[antlr-interest] Weird problem with semantic predicates. Incorrect warning message
Gabriel Petrovay
gabriel.petrovay at 28msec.com
Tue Apr 28 09:13:22 PDT 2009
Hi,
Thanks a lot John for make it it clear. Although I see the problem and
I think that generates everyting, there are at least a couple of
problems with ANTLR:
1. The Warning is incorrect: Decision can match input such as "IF"
using multiple alternatives: 1, 4. As a result, alternative(s) 4 were
disabled for that input.
This is non-sense to me since decision 1 in p_ExprSingle does not
match "IF". Only decision 4 can match it (p_StepExpr)
2. What do those two alternatives (1 and 4) have to do with the
alternative 2 (p_ExitExpr) and a rule that is NOT used anywhere
(p_ReplaceExpr) ???
Regards,
Gabriel
On Tue, Apr 28, 2009 at 5:03 PM, John B. Brodie <jbb at acm.org> wrote:
> 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
>
>
--
MSc Gabriel Petrovay
MCSA, MCDBA, MCAD
Mobile: +41(0)787978034
More information about the antlr-interest
mailing list