[antlr-interest] need help with predicates
    Andy Tripp 
    antlr at jazillian.com
       
    Thu Aug  9 14:25:28 PDT 2007
    
    
  
Richard Clark wrote:
> The usual answer to dealing with context-dependant elements is to move
> the decision from the lexer into the parser.
>
> You might do this:
>
> identifier: (ID_FRAGMENT '!' ID_FRAGMENT) => ID_FRAGMENT '!' ID_FRAGMENT
>              | ID_FRAGMENT
>              /* You still have to deal with the other suffixes */
>              ;
>
> ID_FRAGMENT: LETTER (LETTER| DECIMAL_LITERAL)* ;
>
>  ...Richard
>
>   
Hmmm. I tried this, and thought it didn't work, because when I have 
something like:
Dim a!
Dim b
...since keywords such as 'Dim' are also identifiers, "a ! Dim" would be 
considered an identifier.
But thinking about it now, that shouldn't be a problem. "Dim" should not 
match ID_FRAGMENT, as
it can only match its specific token:
DIM='Dim';
I'll look into it more, thanks for the suggestion.
    
    
More information about the antlr-interest
mailing list