Robert van der Hulst schrieb: > Guys, > > I have 'inherited' a large project that uses Antlr V2 (CPP target). > > Is there a step by step guide somewhere on how to convert the Antlr V2 > grammar files to Antlr V3. > I would not mind switching from the CPP target to for example C# too. > >
There is a wiki-page: http://www.antlr.org/wiki/display/ANTLR3/Migrating+from+ANTLR+2+to+ANTLR+3#MigratingfromANTLR2toANTLR3-NewinANTLR3 But be warned, that this page is only concerned about the grammar syntax. Among the other changes are also: a new tree model (instead of child-sibling), and a new parsing algorithm (LL*) that may cause problems if you have lots of ambiguities in your grammar. ANTLR2 does not seem to have this problem. So, if your inherited code is large enough and happens to manipulate the AST, using functions like "setNextChild", "getFirstChild", "setHiddenAfter" etc, you will run into trouble. Some weeks ago, I already posted a mail about this topic. Part of it was: For example, an antlr2 AST node can be a singular node,or a node with a sibling, which has another sibling. So, it can be either a node or a list of nodes. If your code depends on this, you end up replacing many type definitions with List<AST>. Or you add the nodes you actually want to return to a dummy parent, return the first child of that parent, and let the caller find out if the returned node has a parent and if so, regard all its childs as the rest of the list. If you did not write your program in such a fashion, maybe the translation to antlr3 gets easier then. But still, there is a function called "setNextSibling" in antlr2. How do you emulate that in antlr3? You have to distinguish lots of special cases to find out if it means: addChild, deleteChild, deleteRangeOfChildren .. whatever. If that applies to you, another solution could be to use ANTLR3 only for parsing, but keep using the ANTLR2 AST nodes for representation and manipulation. You probably could do this using a TreeAdaptor, which is new in ANTLR3 and is used from within the tool-generated code to build/traverse/manipulate the AST. Best, Andreas Meyer List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
