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

http://www.antlr.org:8080/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 <[EMAIL PROTECTED]> 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:8080/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
>
>

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to