[antlr-interest] ANTLR3.4: help on @init and @after
Sam Harwell
sam at tunnelvisionlabs.com
Tue Aug 21 05:46:27 PDT 2012
The @init section is frequently used to declare and initialize variables
which are used in predicates and/or actions later in the rule. If these were
placed inside a generated (state.backtracking==0) block, the scoping rules
of the language would leave you with no way to declare variables and would
not initialize variables if they are used in semantic predicates and/or
forced actions.
--
Sam Harwell
Owner, Lead Developer
http://tunnelvisionlabs.com
-----Original Message-----
From: Francis ANDRE [mailto:francis.andre.kampbell at orange.fr]
Sent: Tuesday, August 21, 2012 2:33 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] ANTLR3.4: help on @init and @after
Hi
This parser rule
foo
returns[Token = null]
@init
{ allowFOO(true); }
@after
{ allowFOO(false); }
: FOO { l = $FOO; }
;
is translated into this snippet
allowFOO(true);
try {
{
FOO1=(Lexem)match(input,FOO,FOLLOW_FOO_in_FOO1247); if
(state.failed) return l;
if ( state.backtracking==0 ) { l = FOO1; }
}
if ( state.backtracking==0 ) { allowFOO(false); }
Why the @after action is conditioned by a backtracking equal to 0, while
the @init one is not??
FA
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list