Oct 8, 2015 at 4:42 PM
Edited Oct 8, 2015 at 5:13 PM
I have a sql-like grammar which was previously working fine. It would successfully parse
SELECT COUNT(DISTINCT(item)) ...
but I've recently needed to introduce
SELECT DISTINCT option and it has thrown up this error.
State S4 (Inadequate)
Shift-reduce conflicts on inputs: DISTINCT
selectClause -> SELECT ·distinctExpression expressionList
distinctExpression -> ·DISTINCT
distinctExpression -> · [[ ... COUNT DISTINCT ... ]
Transitions: distinctExpression->S94, DISTINCT->S95
The salient parts of the grammar (as far as I can tell are)
Dim [DISTINCT] = ToTerm("DISTINCT")
selectClause.Rule = [SELECT] + distinctExpression + listExpression
distinctExpression.Rule = [DISTINCT] Or Empty
listExpression.Rule = MakePlusRule(listExpression, [COMMA], columnExpression)
columnExpression.Rule = expression Or ...
expression.Rule = term Or ...
term.Rule = functionExpression Or ...
functionExpression.Rule = functionNameExpression + parenExpression Or
functionNameExpression + [EMPTYPAREN]
functionNameExpression.Rule = [COUNT] Or [DISTINCT] ...
parenExpression.Rule = LPAREN + listExpression + RPAREN
DISTINCT as a function I don't think would ever appear without COUNT so perhaps I haven't defined it correctly with respect to function names. It previously returned a COUNT node containing a DISTINCT node nested within it.
OTOH, I wasn't sure if I should be explicitly given hints as to how to process the DISTINCT.
I've looked at the sql grammar example and it looks like the DISTINCT is just being treated as identifier in the context of COUNT(DISTINCT ...
Is there a (quick!) fix for the way that I am doing it or should I rework it to match the example.
Again, I'd be grateful of any pointers
Thx in advance