[antlr-interest] stuck on templates

Johannes Luber jaluber at gmx.de
Mon Aug 27 11:17:24 PDT 2007


Warner Onstine wrote:
> On 8/27/07, Johannes Luber <jaluber at gmx.de> wrote:
>> Warner Onstine wrote:
>>> I also tried to do something similar to the CMinus example here:
>>>
>>> program
>>> scope {
>>>   List globals;
>>>   List functions;
>>> }
>>> @init {
>>>   $program::globals = new ArrayList();
>>>   $program::functions = new ArrayList();
>>> }
>>>
>>> But when I did that ANTLRWorks first complains about "program" being
>>> defined already (in the @init section) and it then complains about not
>>> finding ArrayList (even though I added it in the @header section.
>>>
>>> Thanks for any help, just trying to wrap my head around this stuff.
>>>
>>> -warner
>> Is program supposed to be a rule or a scope? The syntax is a mixture of
>> both. Can you post your grammar here? It would be helpful in finding the
>> cause and the correct fix.
> 
> That grammar comes straight from the CMinus.g file in the v3
> downloads. If you want I can attach it, but it seems that those demo
> grammars *should* be right. If they aren't they need to be fixed.
> 
> -warner
> 

Upps, I just got confused local rule scopes with the global scopes,
which I've been using. The grammar *is* actually correct and ANDLRworks
doesn't complain about any error when generating the file. Does
generating of your copy cause an error? Or does your changed version
cause the error? If the latter, please post the changed rule/grammar.

Best regards,
Johannes Luber


More information about the antlr-interest mailing list