[antlr-interest] Re: antlr bug or grammar problem?
Monty Zukowski
monty at codetransform.com
Thu Sep 23 12:08:58 PDT 2004
Hey, I used to work on that grammar! Anyhow, this may be a bug in
ANTLR. Syntactic predicates are used to disambiguate. Here, ANTLR
sees no ambiguities between the alternatives, so it doesn't use the
syntactic predicate. If it were generating a syn pred you would see
guessing mode incremented and the decremented at the end of the
predicate.
Try a semantic predicate instead
{LA(1)==BECAME_TRUE||LA(1)==BECAME_FALSE||LA(1)==CHANGED}?
Monty
ANTLR & Java Consultant -- http://www.codetransform.com
ANSI C/GCC transformation toolkit --
http://www.codetransform.com/gcc.html
Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html
On Sep 23, 2004, at 11:55 AM, kozchris wrote:
> shouldn't a line like this
>
>>> ( BECAME_TRUE | BECAME_FALSE | CHANGED ) => expr
>
> produce code like this
>
>>> switch ( LA(1)) {
>>> case BECAME_TRUE:
>>> case BECAME_FALSE:
>>> case CHANGED:
>>> {
>>> expr();
>
>
>
> --- In antlr-interest at yahoogroups.com, Monty Zukowski <monty at c...>
> wrote:
>> A syntactic predicate doesn't work by modifying the lookahead, it
>> actually tests the grammar fragment in 'guessing' mode and then if
>> that
>> is ok it will proceed. I don't think you've found a bug in ANTLR.
>> However, you were looking at the code for a reason. What's the
>> original bug?
>>
>> Monty
>>
>> ANTLR & Java Consultant -- http://www.codetransform.com
>> ANSI C/GCC transformation toolkit --
>> http://www.codetransform.com/gcc.html
>> Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html
>>
>> On Sep 23, 2004, at 11:10 AM, kozchris wrote:
>>
>>> I'm using antlr 2.7.4.
>>> I've run the grammar building both a cpp and java version with same
>>> results.
>>>
>>> You can see the grammar file here
>>> http://www.synergyss.com/SCRExpression.g.
>>> and the java output here
>>> http://www.synergyss.com/SCRExpressionParser.java
>>>
>>> The issue is showing up in the parser code generated for rule
>>> eventExpr on line 279.
>>> The line:
>>> ( BECAME_TRUE | BECAME_FALSE | CHANGED ) => expr
>>> {printf("processing
>>> simple event expr\n");}
>>>
>>> is showing up as this in the generated parser.
>>>
>>> <<<< begin code snip
>>> switch ( LA(1)) {
>>> case BOOLEAN:
>>> case DoubleDoubleConst:
>>> case FloatDoubleConst:
>>> case LongDoubleConst:
>>> case IntBinaryConst:
>>> case IntHexConst:
>>> case LongHexConst:
>>> case UnsignedHexConst:
>>> case IntOctalConst:
>>> case LongOctalConst:
>>> case UnsignedOctalConst:
>>> case IntIntConst:
>>> case LongIntConst:
>>> case UnsignedIntConst:
>>> case LPAREN:
>>> case PLUS:
>>> case MINUS:
>>> case LNOT:
>>> case BNOT:
>>> case BECAME_TRUE:
>>> case BECAME_FALSE:
>>> case CHANGED:
>>> case ID:
>>> {
>>> expr();
>>> astFactory.addASTChild(currentAST, returnAST);
>>> if ( inputState.guessing==0 ) {
>>> printf("processing simple event expr\n");
>>> }
>>> eventExpr_AST = (AST)currentAST.root;
>>> break;
>>> }
>>> <<<< end code snip
>>>
>>> What is strange is that if I change line 281 from:
>>> ( BECAME_TRUE | BECAME_FALSE | CHANGED ) => expr
>>> {printf("processing
>>> simple event expr\n");}
>>>
>>> to:
>>>
>>> ( BECAME_TRUE | BECAME_FALSE | CHANGED ) => simpleEventExpr
>>> {printf("processing simple event expr\n");}
>>>
>>> the code generated is correct.
>>>
>>> <<<< begin code snip
>>> switch ( LA(1)) {
>>> case BECAME_TRUE:
>>> case BECAME_FALSE:
>>> case CHANGED:
>>> {
>>> simpleEventExpr();
>>> astFactory.addASTChild(currentAST, returnAST);
>>> if ( inputState.guessing==0 ) {
>>> printf("processing simple event expr\n");
>>> }
>>> eventExpr_AST = (AST)currentAST.root;
>>> break;
>>> }
>>> <<<< end code snip
>>>
>>> Any ideas on how to solve this problem?
>>>
>>> Thanks for the help.
>>> Chris
>>>
>>>
>>>
>>>
>>>
>>>
>>> Yahoo! Groups Links
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list