[antlr-interest] Weird problem with semantic predicates. Incorrect warning message
Jim Idle
jimi at temporal-wave.com
Tue Apr 28 09:42:16 PDT 2009
Gabriel Petrovay wrote:
Why don't you run the grammar check in ANTLRWorks, which then points out
the ambiguity pretty instantly. Also, if posting a grammar, make sure it
is one that can be pasted into ANTLRWorks and just used - yours is a
parser grammar without the lexer tokens, which means it will give errors.
>>
>> PARSER GRAMMAR:
>> --------------------------------------------------
>> parser grammar exit_test;
>>
>> options {
>> tokenVocab=XQueryLexer;
>> }
>>
>>
>> pm_Expr
>> : p_ExprSingle EOF
>> ;
>>
>> p_ExprSingle
>> : p_IfExpr
>> | {flag}?=> p_ExitExpr
>> | {flag}?=> p_WhileExpr
>>
Are sure that you want this? what about {flag}?=> (p_ExitExpr | p_WhileExpr)
>> | p_StepExpr
>> ;
>>
>> p_IfExpr
>> : IF
This is the first place that IF can be matched in pExprSingle
>> p_NCName
>> : L_NCName | IF | EXIT
>> ;
>>
And this is the second (as pStepExpr can be p_NCName, which can be IF.
IF can only be a token for your IF statement or a p_NCName, not both at
once.
Jim
More information about the antlr-interest
mailing list