[antlr-interest] Generated declaration?

Rick Morgan r.morgan at verizonbusiness.com
Mon Oct 30 08:27:22 PST 2006


That sorta works because if I put a "returns [int cs]" on the rule, then
I get a declaration "int cs;" in the output.  But reading wiki examples, I
came away with the impression that when I put a label, say cs, on something,
then the method getText() becomes available for the variable cs.  For the
generated code to actually compile however, and using your suggestion, I
would have to know the internals of antlr so I can put a proper "returns
[xxx cs]" on whatever rule needs it.  Am I really expected to delve into the
internals of antlr to figure out what the node types are?

Maybe there's a disconnect between what I'm trying to do and a proper usage
of antlr.  I'm not trying to build an AST that I can later walk... I'm
working on a testing framework that needs to recognize a certain language
and fire off actions as the input is  recognized.  Seems like ANTLR could do
that, no?

By the way, I didn't say this earlier, but my target language is c++, and
the action I put in wasn't valid c++ code but that's easily fixed once I see
a valid "cs" declaration somewhere.

thanks,
Rick

>The type of cs depends on the return type of your classSpec rule.  If it
>currently doesn't return anything then it's expected that ANTLR won't put a
>declaration of your variable in there as there is nothing to store

>>Hi, just discovered antlr 2 days ago, so pretty new at this... I'm
>>trying to discover how actions I specify are placed in the generated
>>code so I wrote the following inside a rule:
>>( cs:classSpec { initEntity( cs.getText() ); } )*

>>As expected, the generated code contained initEntity( cs.getText() );

>>Problem is there is no declaration of cs.  I could declare it myself
>>somewhere if I new what type it was but I doubt that is the correct
>>solution.  I ran this test using both the command line tool (java
>>antlr.Tool verbTest.g) and using an Eclipse plugin, both do not generate
>>a declaration for cs.

>>I reread the wiki entries for labels several times, but it doesn't go
>>into these details.  I'm using antlr version 2.7.7rc1.





More information about the antlr-interest mailing list