[antlr-interest] [antlr-dev] actions in rules with backtracking (fwd)

Christopher D. Rickett crickett at lanl.gov
Mon Dec 4 09:49:14 PST 2006



---------- Forwarded message ----------
Date: Fri, 1 Dec 2006 17:09:53 -0700
From: Craig Rasmussen <crasmussen at lanl.gov>
To: Kay Roepke <kroepke at classdump.org>
Cc: Christopher D. Rickett <crickett at lanl.gov>, antlr-interest at antlr.org
Subject: Re: [antlr-dev] actions in rules with backtracking

Kay,

In your kind response you asked what we wanted to achieve.  In general we are
developing a parser for Fortran 2003 (with some later extensions).
Specifically, we are trying to add communication between the parser and lexer.
Fortran has some nasty ambiguities between identifiers and keywords.  For
example, you can declare an integer with the name integer, as in,

    integer :: integer = 3

This may seem like poor form, but Fortran has so many stupid keywords that it
is almost necessary.

It is common to perform a preliminary pass over the token list to do a
rudimentary analysis in order to fix up the tokens.  However, we thought it
might be better to have parser change a keyword to an identifier, just before
it was expecting to see an identifier.  However, with backtracking, actions to
do this are not called.

Perhaps you have some other ideas.

Cheers,
Craig


On Nov 30, 2006, at 2:08 PM, Kay Roepke wrote:

> Hi!
> 
> On 30. Nov 2006, at 21:54 , Christopher D. Rickett wrote:
> 
> > Is there a way to force actions that begin rules to always be executed,
> > even if backtracking is enabled?  For example:
> > 
> > A : {/* my action */;} B ;
> > 
> > Is there a way to ensure that this action will be executed?
> 
> Do you mean to execute the action 'while backtracking'?
> That's tricky. For synpreds you might be able to get away with the global
> @synpredgate { expression that replaces the 'backtracking == 0' check}, but
> that only works for syntactic predicates and affects all synpreds.
> 
> OTOH:
> If you simply want to execute code at the beginning of a rule, use an @init
> action.
> Those are not protected with 'if (backtracking==0)':
> 
> rule
> @init {
>      // this is always executed, try the -trace option to see it in action
> }
> :    'foo' ;
> 
> BTW, what do you want to achieve?
> 
> HTH,
> -k
> 
> P.S.: antlr-interest is a better list for those questions ;)
> -- 
> Kay Röpke
> http://classdump.org/
> 
> 
> 
> 



More information about the antlr-interest mailing list