[antlr-interest] ANTLR / Generic parser / AST

xavier.huet at infineon.com xavier.huet at infineon.com
Thu Oct 17 10:31:07 PDT 2002



Hi there,


We try to have kind of generic parser ie for example a verilog (or 
vhdl or anything you can imagine) parser Engine that every client can
configure for their own needs.

We arrived to the fact that we should right our own AST structure and to
have a factory in our parser to create it. (factory then can be defined by
our clients to built their own kind of objects , thought deriving from Our
base AST classes). So it looks like yours.

Calc.g

assignment returns [pNode asgn]
{
 pNode e1 = NULL;
 pNode e2 = NULL;
 pNode id = NULL;
}
 : e1 = expr { asgn = e1; }
 | id = identifier ASSIGN e2 = expr
 { asgn = factory.build_binary( n_assign, id, e2 ); }
 ; 
  
This method is fine for a client that need to some "compile" stuff. But what
if one client wants to filter the input file only by prefixing the module
name. The output should be exactly the same (including whitespaces,
comments, parenthesis, brackets, semi colon) except the module name though.
With the custom tree, we loose a lot of information. Do you have any
solutions ? Or ideas ?

Also we may have some clients that would like a mix of 2 ie building a AST.
Evaluate some of the node and replace, in the original file, the nodes by
the evaluation's result.

For example , if the input looks like this :

## This is a comment ##
a = 1 + 2 ;
## This is another comment ##
b = 2*a + 3 ;

the client would like , to evaluate the expression and replace in the input
by the results but all others
stuff should not be skip.:
## This is a comment ##
a = 3;
## This is another comment ##
b = 9;


Thank you in advance for your help,

~XAvier

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list