[antlr-interest] Tree parser
Johannes Luber
jaluber at gmx.de
Thu Jul 31 13:39:46 PDT 2008
rkevinburton at charter.net schrieb:
> Thank you. This syntax came from
>
> http://antlr.org/share/list
> kcsparse - an ECMA-334 C# Grammar Sample for ANTLR v2.7.6 (C#)
>
> Kevin
Anything with a version before 3.x should be considered as outdated and
incorrect, as without knowledge of both versions one doesn't know what
is usable in 3.x and what has to be changed.
Johannes
>
> ---- Johannes Luber <jaluber at gmx.de> wrote:
>> rkevinburton at charter.net schrieb:
>>> I would like to generate a tree parser. Unfortunateliy the ANTLR book has very little to say of the issue (or I just don't know where to look) and the sample grammars that I see seem to implement the 'walker' different from the way ANTLR does it now. For example in the CSharp grammar there is syntax like (the 'walker grammar names are different):
>>>
>>> CSharpwalker = new CSharpWalker();
>>> walker.setASTFactory(new ASTNodeFactory());
>>> CSharpParser.initializeASTFactory(walker.getASTFactory());
>>>
>>> where the constructor for the waler no longer takes '0' arguments. There isn't a method 'setASTFactory' and there also isn't a method 'initializedASTFactory'. If I have a TreeParser grammar how do I integrate it with the parser?
>>>
>>> Thank you.
>>>
>>> Kevin
>>>
>> I don't know where the syntax above comes actually from, but my own tree
>> grammar used a driver like this:
>>
>> CSharpParser.grammarDef_return r = parser.startRule();
>> CommonTree r0 = ((CommonTree) r.tree);
>> CommonTreeNodeStream nodes = new CommonTreeNodeStream(r0);
>> nodes.TokenStream = tokens;
>> CSharpGenerator walker = new CSharpGenerator(nodes);
>> RuleReturnScope r1 = walker.startRule();
>> Console.Out.WriteLine(r1.Template.ToString());
>>
>> Hope this helps
>
More information about the antlr-interest
mailing list