[antlr-interest] adding actions to rules breaks stuff
Mark Wright
markwright at internode.on.net
Mon Feb 11 15:15:13 PST 2008
Hello Benjamin,
The ANTLR syntax:
import [Object s]
declares rule import as taking a parameter s. So ANTLR is
pointing out that when you call it in document, it needs
to pass it the parameter, something like:
document [Object o]
: (i+=import[o])* c+=thing* EOF {o=new Doc($i,o);}
;
If you wanted just a local variable instead, then these can
be declared like:
document
@init { Object o; }
: i+=import* c+=thing* EOF {o=new Doc($i,o);}
;
import
@init { Object s; }
: 'import' s_=Text eol_ {s=$s_;}
;
I strongly recommend buying and reading the ANTLR book.
Regards, Mark
On Mon, 11 Feb 2008 14:12:57 -0800
Benjamin Shropshire <shro8822 at vandals.uidaho.edu> wrote:
> I have a grammar that Antlr will process. However when I try to add
> actions
>
> example:
> ///////
> document [Object o]
> : i+=import* c+=thing* EOF {o=new Doc(i,o);}
> ;
>
> import [Object s]
> : 'import' s_=Text eol_ {s=s_;}
> ;
> //////
> it says this:
>
> missing parameter(s) on rule reference: import
>
> When I add an action to the top most rule it works, but when I add an
> action to any rule that is used by anyone else, I get that error
> message. I'm assuming I'm doing something wrong but I can't find
> anything in the docs that is useful. A (well documented) example or a
> pointer into the documentation would be appreciated. Also, how could
> I have found the info my self would be of even more help.
>
> Benjamin Shropshire
--
More information about the antlr-interest
mailing list