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

Terence Parr parrt at cs.usfca.edu
Mon Dec 4 10:01:48 PST 2006


On Dec 4, 2006, at 9:49 AM, Christopher D. Rickett wrote:

>
>
> ---------- 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.

Perhaps you can make a CommonTokenStream implementation that looks  
for this kind of keyword issue and replace the 3 tokens with a new  
meta token before it hits the parser.  Then now parser->lexer comm.  
needed.

Ter


More information about the antlr-interest mailing list