[antlr-interest] TokenStreamRewriteEngine

DM donalmurtagh at yahoo.co.uk
Mon Jan 9 04:49:39 PST 2006


Hi,

I'm using ANTLR to validate and modify a structured text file.
Originally, I intended to enable the file to be modified by:

1. Building a min/max AST
2. Modifying the min/max AST
3. Printing out the tokens in the modified AST in the original order

As per the approach advocated in the article:
http://www.antlr.org/article/preserving.token.order/preserving.token.order.tml

However, this solution is inefficient, as I'll need to reparse the file after each modification
(in order to reconstruct the min/max AST). This is a particular problem for me, as the file is
very large.

As an alternative approach, TP suggested using his TokenStreamRewriteEngine. An example of using
this is presented in the article:
http://www.antlr.org/article/rewrite.engine/index.tml

However, in this example (generating a C header file from a source file), the necessary
modifications are known a priori. But in my case, the modifications will only be known at runtime,
as they depend on user input.

Is TokenStreamRewriteEngine suitable for use only when one type of modifications are possible? For
example, would it be possible to modify the example in the article to alternatively enable:

- all global variables to be deleted OR
- all global function names to be renamed so they begin with "foo"

Thanks in advance,
DM




	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com


More information about the antlr-interest mailing list