[antlr-interest] Re: syntax predicates

lgcraymer lgc at mail1.jpl.nasa.gov
Sat Sep 14 21:57:26 PDT 2002


Richard--

Ter managed to convince me that this wasn't an example of the bug I 
encountered--the problem in your code is that "or", "replace", and 
"force" are literals, not IDs, so the synpred is what is incorrect.

For penance, I now have to resurrect the bug that I encountered so 
that Ter can fix it ...

--Loring


--- In antlr-interest at y..., Terence Parr <parrt at j...> wrote:
> 
> 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