I am trying to parse this expression (based on SQLite): 0 BETWEEN 0 AND 2 AND 1 < 9
.
Here is the relevant portion:
expression
: term #termExpression
| left=expression '<' right=expression #lessThanExpression
| value=expression NOT? BETWEEN lower=expression AND upper=expression #betweenExpression
| left=expression AND right=expression #andExpression
| left=expression OR right=expression #orExpression
;
Assume a term is a number (e.g., 0
, 1
, 2
, and 9
).
The actual SQLite parser seems to correctly parse it as so: (0 BETWEEN 1 AND 2) AND 1 < 9
. However, my parser is treating it like 0 BETWEEN (1 AND 2) AND 1 < 9
.
What's the best way to break this ambiguity?
In SQLite, a lot is considered an "expression", including comparisons, arithmetic expressions, AND/OR/NOT, BETWEEN, etc. A boolean can validly appear in the BETWEEN range because it gets evaluated as a number (0 or 1).
There's actually many other alternatives (49 total) mapping to expression
in the real grammar.