[antlr-interest] Re: Newbie Question about Syntactic Predicates

lgcraymer lgc at mail1.jpl.nasa.gov
Sat Nov 8 00:32:03 PST 2003


Mike--

Ah--perl is a useful tool, but it can warp the mind.  Good ANTLR 
development practice is that

Lexers are for separating input into tokens; while parsing can be 
done in the lexer, it is usually not good practice.

Parsers are for recognizing token sequences and tree construction.

Tree rewrites are for reorganizing token sequences into a regular 
form suitable for output.  The final treewalk passes are for output.

For a "simple" translation of the sort you describe (no complex 
optimization passes), you should be able to avoid complex action 
code.  It's all a matter of restructuring ...

--Loring


--- In antlr-interest at yahoogroups.com, "hawkwall" <hawkwall at y...> 
wrote:
> Jim,
> 
> You are right about the oversight, I missed that when I copied in 
the
> post.  I will look at the testLiterals option and play with it. 
> Thanks for taking the time to make the example, it seems much 
easier.
> I don't want to do more work than I have to.  
> 
> 
> Loring,
> 
> Thanks for the hint about left factoring the NUMBER.OF.  There are
> lots of places I can do that, and it will help.  You also mentioned
> testLiterals, so I will dig more.  From you comment about doing 
more 
> work in the parser, I appreciate your advice.
> 
> 
> Thank you both for your answers.  At some point, I plan to add 
actions
> and use Hibernate to populate a database from the parse. I was
> thinking it would be cleaner if more of the parsing work was done 
in
> the lexer, because I assume the actions will be fairly complex.  I
> have used the perl module Parse::RecDescent in the past to parse 
files
> and build comma seperated text files that were then loaded into the
> database.  I spent way to much time debugging the column names and
> making sure things were in the right order.  I wish I could say I
> understood the internals of P:RD, but in actuality, I just tinkered
> until I got an acceptable result.  Already, I have better
> understanding of what antlr is doing, the generated code is much
> easier to read.  I hope this approach with antlr and hibernate will
> work better.  I was kinda shocked to not see regular expressions in
> antlr, but I don't think I will miss them. Would an AST serve me
> better to populate the database?  I will need to get a better
> understanding of AST's if so.  Again, I am grateful for the help.
> 
> Mike


 

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




More information about the antlr-interest mailing list