Setup operator precedence for parser to avoid ambiguity and fix shift/reduce warnings

This commit is contained in:
Nyall Dawson
2020-08-23 07:55:41 +10:00
parent 7ed9df0526
commit 83104b7b69
2 changed files with 22 additions and 7 deletions

View File

@@ -71,6 +71,18 @@ typedef struct sql_context
%type <ival> nulloperator
%type <name> identifier
//
// operator precedence
//
// left associativity means that 1+2+3 translates to (1+2)+3
// the order of operators here determines their precedence
%left OR
%left AND
%right NOT
%left EQ LTEQ GTEQ LT GT LIKE IS
%%
stmt:
@@ -142,9 +154,9 @@ identifier:
;
operator:
'=' { $$ = MDB_EQUAL; }
| '>' { $$ = MDB_GT; }
| '<' { $$ = MDB_LT; }
EQ { $$ = MDB_EQUAL; }
| GT { $$ = MDB_GT; }
| LT { $$ = MDB_LT; }
| LTEQ { $$ = MDB_LTEQ; }
| GTEQ { $$ = MDB_GTEQ; }
| LIKE { $$ = MDB_LIKE; }