[antlr-interest] A few ANTLR 3.0b4 questions
Micheal J
open.zone at virgin.net
Wed Nov 15 19:04:41 PST 2006
Hi,
[...]
> 2) I am using an AST but for some reason, neither @header{}
> @members{} seem
> to have the deisred behavior as appears to be
> indicated in the wiki nor does header{} appear to work.
> I want to set
> the java package
> name and perhaps use some imported libraries.
>
> The relevant syntax looks like:
> grammar MyGrammar;
>
> options{
> output=AST;
> }
>
> /* This won't compile
> @header{
> package mypackage;
> }
[...]
> tokens{
> // This all works.
> }
@header{...}, @members{...} etc blocks cannot appear before tokens{...}
block.
> 3) I would like to add some Java source to invoke some actions in my
> grammar.
> Do I need code to walk the AST, or can I try to
> accomplish them during
> the AST
> construction phase, I expect I'll be using both inherited
> and synthetic
> attributes in my rules.
Depends on your language. Some language do not lend themselves to
"single-phase" processing tools. Using an independent TreeParser is
"cleaner" but less performant.
> If I have a rule like
>
> command:
> (
> c1=commandType1->(COMMAND $c1) // Here I would like
> java code for
> command processing
> |
> c2=commandType2->(COMMAND $c2) // Here too
> );
>
> I took a quick look at the wiki and it appears there is some
> @actions stuff
> but I don't grok it yet.
Have a look at the source code in the samples. And at the mantra project
sources too.
Micheal
-----------------------
The best way to contact me is via the list/forum. My time is very limited.
More information about the antlr-interest
mailing list