[antlr-interest] Tree parser
Johannes Luber
jaluber at gmx.de
Thu Jul 31 13:42:38 PDT 2008
rkevinburton at charter.net schrieb:
> I tried this:
>
> program_return ret = parser.program();
> CommonTree ct = ((CommonTree) ret.tree);
>
> But the C# compiler gives me an error:
>
> 'BsiServices.Parse.ECMAScriptParser.program_return.tree' is inaccessible due to its protection level
>
> What am I doing wrong?
>
> Thanks again.
>
> Kevin
It could be that you have to change .tree to .Tree. I didn't check if
the driver code is still uptodate. BTW, please look if changing the
capitilization works before you write an email. :)
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