[antlr-interest] Mulit-pass language processing.

Tom Smith yotommy at gmail.com
Mon Sep 22 11:01:09 PDT 2008


I have a similar situation, and chose an approach like one I saw mentioned
on the mailing list years ago:

http://www.antlr.org/pipermail/antlr-interest/2005-June/012788.html

I have implemented one Behavior per pass, and change the Behavior from
the main program before calling the parser on each pass.

Hope this helps,
Tom.

On Mon, Sep 22, 2008 at 12:25 PM, Peter C. Chapin <pcc482719 at gmail.com> wrote:
> I have an application where I need to process and rewrite a collection
> of source files. I have come to the conclusion that I'll need to use two
> passes over the source files. During the first pass I will parse the
> files and gather certain bits of information about them. During the
> second pass I will parse and rewrite these files taking into account the
> information gathered during the first pass. I believe that, in general,
> I need to look over all the files before I can reliably rewrite any of them.
>
> I know how to set up ANTLR's rewriting mode. In fact I have a program
> that parses my input files using an ANTLR grammar and rewrites them all
> using an identity rewriting. Fine so far. Now I'm thinking about how to
> gather the necessary preliminary information I need to do the rewriting
> I actually want. The problem is that the grammar actions I need are
> different in the two cases (gather information vs rewriting). So that
> seems to suggest that I'll need two grammars with largely the same
> rules, but different actions. I would instantiate parsers from the first
> grammar to do the information gathering (one parser for each source
> file), and parsers from the second grammar to do the rewriting.
>
> Before embarking on this path, I wanted to ask if there is perhaps a
> more "elegant" way.  It seems like my plan would introduce a maintenance
> headache given that I'd have two different grammars that are supposed to
> accept the same language.
>
> Thanks!
>
> Peter
>
>
> 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