[antlr-interest] Predicate Syntax Problem

Bill Venners bv-svp at artima.com
Fri Jan 12 11:37:12 PST 2007


Hi Terence,

On Jan 12, 2007, at 10:17 AM, Terence Parr wrote:

>
> On Jan 11, 2007, at 11:34 PM, Bill Venners wrote:
>
>> Hello,
>>
>> I am not sure how to add a predicate to one element of an OR  
>> expression in ANLTR 3.
>>
>> passedDecl
>>     :    'not-null'? ('byte' | 'short' | 'int' | 'long' |  
>> 'boolean' | 'float' | 'double'
>>          | 'char' | ID_UP )^ { isTypeName($ID_UP.getText()) }?
>>          ID_DOWN { isVarName($ID_DOWN.getText()) }?
>>     ;
>>
>> This is apparently valid grammar syntax, but the $ID_UP doesn't  
>> work. I get:
>>
>> com/artima/view/ViewParser.java:497: cannot find symbol
>> symbol  : variable $ID_UP
>> location: class com.artima.view.ViewParser
>>             if ( !( isTypeName($ID_UP.getText()) ) ) {
>>
>> I am unable to find any help in the documentation I can find. Can  
>> someone help me understand what I should do here? What I'd like to  
>> accomplish is to kill the parse if the ID_UP variable returns  
>> false when passed to isTypeName().
>
> Hi Bill,
>
> Have you tried the latest jar in file sharing area?  It should fix  
> lots of these.  Do you want the {...}? to validate input or  
> disambiguate?  If the latter, they should go on the left edge. :)
>
I'll try the latest jar. I want to validate, but having slept on it  
I'm not sure what the advantage of putting this in the parser itself  
is. What I do is build an AST that I pass to a code generator (just  
some Java code that uses StringTemplate directly, and that code  
generator could do the same validation, print out nice error  
messages, kill the build, etc. I get the feeling there's some cool  
way to use StringTemplate with ANTLR 3 that I don't know about. If  
there is and there's some documentation somewhere, please point me to  
it.

I thought in the ANTLR 2 docs that validation predicates went *not*  
on the left. I've been trying to guess how ANTLR 3 works from ANTLR2  
docs.

Thanks. Really great stuff. I'm just quite the newbie.

Bill


More information about the antlr-interest mailing list