Merge pull request #36 from nyalldawson/precedence

Setup operator precedence for parser to avoid ambiguity and fix shift/reduce warnings
This commit is contained in:
Evan Miller
2020-08-22 18:28:23 -04:00
committed by GitHub
2 changed files with 22 additions and 7 deletions

View File

@@ -65,8 +65,11 @@ or { return OR; }
not { return NOT; }
is { return IS; }
null { return NUL; }
"=" { return EQ; }
(<=) { return LTEQ; }
(>=) { return GTEQ; }
"<" { return LT; }
">" { return GT; }
like { return LIKE; }
limit { return LIMIT; }
count { return COUNT; }

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; }