[antlr-interest] grammar guessing.
Bharath Sundararaman
Bharath.Sundararaman at starthis.com
Tue Apr 5 13:19:52 PDT 2005
Hi Ric,
I retraced the rules all the way back to the top-most rule which had a
(foo)=>bar rule. I changed the rule to avoid the guessing and it works
now.
About your init action comment, it unfortunately doesn't help me because
var{...}: v:IDENT (subscripts[#v]); requires work to be performed on
'v', which is visible only after the initialization ends.
Thanks for your help
Bharath.
-----Original Message-----
From: Ric Klaren [mailto:ric.klaren at gmail.com]
Sent: Tuesday, April 05, 2005 11:40 AM
To: Bharath Sundararaman
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] grammar guessing.
Bharath Sundararaman wrote:
> I have a rule of the form:
>
> var: v:IDENT{Get type of "v" and store it in AST #v}(subscripts[#v])?;
>
> Before the 'subscripts' rule is called, I have to store the type of
'v'.
> However, the compiler is in GUESSING MODE because of
(subscripts[#v])?.
> This causes the execution of 'subscripts' rule without performing the
> actions related to the IDENT.
A rule like this cannot result in guessing mode. It must come from an
encapsulating rule. Only a syntactic predicate ( foo ) => bar switches
the parser to guessing mode.
If you *really* *really* want to do things during guessing mode you can
do things in init actions.
var {
Token v = LT(1);
// do stuff for v regardless off guessing mode.
// ...
}:
IDENT (subscripts[v])?;
Check the antlr grammar/docs on where init actions are possible.
Most probable an extra pass over the AST would be nicer in the long run
YMMV.
Cheers,
Ric
More information about the antlr-interest
mailing list