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

John B. Brodie jbb at acm.org
Tue Apr 28 08:03:19 PDT 2009


Greetings!

On Tuesday 28 April 2009 08:10:43 am Gabriel Petrovay wrote:
> 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
> -------
>
>........ remainder of original posting snipped...

This is very similar, to me, to the classical if-then-else ambiguity.

Consider this, apparently valid, sentence in your language:

REPLACE EXIT WITH EXIT WITH EXIT

now there are 2 ways to parse this sentence.
is it REPLACE EXIT WITH (EXIT WITH EXIT)
or REPLACE (EXIT WITH EXIT) WITH EXIT
where the parens group together the p_ExitExpr within
each version of the parse. the other instance of the word 
EXIT in each parse is a p_NCName.

and here are the parse trees for each hopefully making
the ambiguity clearer:

1) REPLACE p_ExprSingle WITH p_ExprSingle
                                     |                              |
                           p_StepExpr                p_ExitExpr
                                     |                              |
                          p_NCName                EXIT WITH p_ExprSingle
                                     |                                                     |
                               EXIT                                             p_StepExpr
                                                                                           |
                                                                                     p_NCName
                                                                                           |
                                                                                      EXIT

2) REPLACE p_ExprSingle WITH p_ExprSingle
                                    |                              |
                         p_ExitExpr                 p_StepExpr
                                    |                              |
      EXIT WITH p_ExprSingle           p_NCName
                                    |                              |
                           p_StepExpr               EXIT
                                    |
                           p_NCName
                                    |
                               EXIT

and so your grammar is ambiguous, the warning is correct, predicates have
nothing to do with your problem.

Hope this helps...
   --jbb



More information about the antlr-interest mailing list