[antlr-interest] Re: Yacc to antlr guide?

lgcraymer lgc at mail1.jpl.nasa.gov
Fri Nov 14 16:18:13 PST 2003


Actually, there are a couple of tricks that can be used.

For operator precedence, you can write a pretty simple precedence language processor (in ANTLR, of course) that takes a 
precedence description and outputs an expression grammar.  Including actions, that should take only about two pages of ANTLR 
code.  That may be overkill, if your expression syntax is simple;  you can bypass that by cannibalizing parts of the java or C 
or other available grammar, as mentioned by Ric, provided your expression syntax conforms.

For returning special types, you can include a pointer to any data structure within custom AST classes.  You will have to set those 
fields within rules, but they will be automatically returned (provided buildAST=true).

--Loring


--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> See http://www.javadude.com/articles/lalrtoll.html for general LALR to LL
> hints, but doesn't talk about precedence.
> 
> Precedence you will have to work out the LL way with lots of little rules.
> Ter's tutorials cover this, I'm sure.
> 
> > is there some way to say that all rules 
> > return a T without decorating each of them individually?
> 
> Only by modifying the code generator or by writing an ANTLR to ANTLR source
> to source transformation that adds that to every rule.
> 
> Monty
> 
> -----Original Message-----
> From: Christopher Nebel [mailto:c.nebel at a...] 
> Sent: Friday, November 14, 2003 12:50 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Yacc to antlr guide?
> 
> Is there documentation somewhere on how to translate yacc grammars into 
> antlr?  I've got a non-trivial yacc-based grammar I'd like to port.  
> Most of the basic grammar parts are straightforward, if tedious, but 
> I'm having two specific problems:
> 
> 1. How do I deal with operator precedence?  The yacc grammar uses 
> precedence declarations, and I don't see any equivalent.  Obviously, I 
> could break the big rules apart into smaller ones that reflect the 
> precedence, but I'm hoping for something more direct.
> 
> 2. The actions in the original make heavy use of $[$12...], and it's 
> not clear to me how to deal with that.  Well, it kind of is.  I can see 
> the "rule returns [T v]" bit, but I'm not looking forward to adding 
> that to every single rule -- is there some way to say that all rules 
> return a T without decorating each of them individually?  The custom 
> AST stuff is also sort of applicable, but I've got a bunch of weird 
> constraints (notably the fact that the type is *not* a C++ object) that 
> make using it somewhat impractical.
> 
> Thanks,
> 
> --Chris Nebel
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


 

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




More information about the antlr-interest mailing list