[antlr-interest] Weird problem with semantic predicates. Incorrect warning message

Gabriel Petrovay gabriel.petrovay at 28msec.com
Tue Apr 28 05:10:43 PDT 2009


Hi all,

I have the parser grammar posted at the bottom of this e-mail. (there
is a corresponding lexer grammar that provides all the necessary
tokens).

If I try to build the parser for this grammar, I get the following warning:
-------
   warning(200): exit_test.g:13:3: Decision can match input such as
"IF" using multiple alternatives: 1, 3
   As a result, alternative(s) 3 were disabled for that input
-------

If I comment the following line in the p_ExprSingle rule:

//		| {flag}?=> p_ExitExpr

everything is OK. Why is this? Why does it work with the next
alternative (p_WhileExpr) but not with the p_ExitExpr alternative? The
message of the waring is wrong: the same message should appear even
also when the line is commented.

Assume I want to parse the text "if" (the token IF). In the rule
p_ExprSingle, the p_IfExpr alternative should fail, the second would
fail anyway an the third one will be successful. So, why the warning?
In a similar manner the parsing of the text "exit" should reach the
3rd alternative.


IMPORTANT: The p_ReplaceExpr rule is not used in any other rule. But
if deleted, I have no more warning and everything is OK. My research
on this problem tells me that there is something fishy regarding the
"WITH p_ExprSingle" at the end of both rules: p_ReplaceExpr and
p_ExitExpr.

Regards,
Gabriel


PARSER GRAMMAR:
--------------------------------------------------
parser grammar exit_test;

options {
tokenVocab=XQueryLexer;
}


pm_Expr
		: p_ExprSingle EOF
		;

p_ExprSingle
		: p_IfExpr
		| {flag}?=> p_ExitExpr
		| {flag}?=> p_WhileExpr
		| p_StepExpr
		;

p_IfExpr
		: IF LPAREN pm_Expr RPAREN
		;

p_StepExpr
		: p_NCName
		| p_EnclosedExpr
		;

p_EnclosedExpr
		: LBRACKET pm_Expr RBRACKET
		;

p_NCName
		: L_NCName | IF | EXIT
		;

p_ReplaceExpr
		: REPLACE p_ExprSingle WITH p_ExprSingle
		;

p_ExitExpr
		: EXIT WITH p_ExprSingle
		;

p_WhileExpr
		: WHILE LPAREN p_ExprSingle RPAREN
		;

--------------------------------------------------

-- 
MSc Gabriel Petrovay
MCSA, MCDBA, MCAD
Mobile: +41(0)787978034


More information about the antlr-interest mailing list