[antlr-interest] Yacc to antlr guide?

Ric Klaren klaren at cs.utwente.nl
Fri Nov 14 02:13:38 PST 2003


Hoi,

On Fri, Nov 14, 2003 at 12:50:24AM -0800, Christopher Nebel wrote:
> 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.  

No guides available I think...

> 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.

Have to disappoint you there :( You could probably borrow the basic layout
from the java grammars.

> 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? 

No easy way other than using sed/perl/tcl/ and editor with regexp replace
to fix things up easily. All the $1 stuff you'd have to change to labels
though :/ then again labels are way less error prone than the yacc stuff ;)

> 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.

If you have a yacc grammar with custom tree building in it then you migth
be quicker of using the treebuilding from the yacc grammar. Unless you want
to rewrite the backend stuff as well. The last bit is not clear to me....

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  There are 10 kinds of people - those that understand binary and
  those that don't. --- Unknown


 

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




More information about the antlr-interest mailing list