[antlr-interest] Re: syntax predicates

Terence Parr parrt at jguru.com
Fri Sep 13 09:55:20 PDT 2002


On Thursday, September 12, 2002, at 04:47  PM, lgcraymer wrote:

> Yeah, there's a synpred bug in 2.7--synpreds only work if they
> reference a single rule or token.  I pointed this out to Ter a few
> months back, so it's probably on the "to be fixed" list.

Syn preds only work on more than one alt (>1 alt implies a decision); 
not sure what you referring to with the single rule/token thing.  But 
in this case, this makes sense, but with only one alt the code 
generator probably screws up since the 2nd alt (the empt alt) is 
implied.  try (...| ) instead of (...)?

Ter

>
> --Loring
>
>
> --- In antlr-interest at y..., "richardhensley99" <richard.hensley at m...>
> wrote:
>> I have a question about syntax predicates because I think I found a
>> bug.
>>
>> I have the following grammar snippet
>>
>> startRule
>> :   (   "create" (("or" "replace" "force" "view") => createView)?
>>     |   skipTokens
>>     )* EOF
>> ;
>>
>> createView
>>     :   (ID)* "view"
>>     ;
>>
>> skipTokens
>>     :   ~("create")
>>     ;
>>
>> And it generates the following code in the startRule method
>>
>> case LITERAL_create :
>>     {
>>         AST tmp1_AST = null;
>>         tmp1_AST = (AST) astFactory.create(LT(1));
>>         astFactory.addASTChild(
>>             currentAST,
>>             tmp1_AST);
>>         match(LITERAL_create);
>>         {
>>             boolean synPredMatched2949 = false;
>>             if (((LA(1) == LITERAL_view
>>                 || LA(1) == ID)
>>                 && (_tokenSet_0.member(LA(2)))
>>                 && (_tokenSet_0.member(LA(3)))
>>                 && (_tokenSet_0.member(LA(4))))) {
>>                 int _m2949 = mark();
>>                 synPredMatched2949 = true;
>>                 inputState.guessing++;
>>                 try {
>>                     {
>>                         match(LITERAL_or);
>>                         match(LITERAL_replace);
>>                         match(LITERAL_force);
>>                         match(LITERAL_view);
>>                     }
>>                 }
>>                 catch (RecognitionException pe) {
>>                     synPredMatched2949 = false;
>>                 }
>>                 rewind(_m2949);
>>                 inputState.guessing--;
>>             }
>>
>> The problem seems to be the following line of code:
>>
>> if (((LA(1) == LITERAL_view
>>     || LA(1) == ID)
>>
>> Which is generated because of the syntax predicate, however the
>> syntax predicate is for the literal "or", not an ID or the
>> literal "view". I'm not sure what gives, but this causes problems
>> when the testLiterals options is true for an ID token because the
>> token is kicked out of the lexicial analyzer as a LITERAL_or instead
>> of an ID.
>>
>> Has anybody else encountered this problem?
>>
>> I've worked around it by just using my createView rule as a
> predicate
>> to createView, but I thought I would ask.
>>
>> Richard
>
>
>
>
> Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/
>
>
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list