How to get ParseTree in AnTLR4 with C#?

721 views
Skip to first unread message

Christian LeMoussel

unread,
Dec 5, 2013, 9:00:00 AM12/5/13
to antlr-di...@googlegroups.com

I am currently using AnTLR4 in C# but I am facing a problem, I don't know how to get the the object/class ParseTree.

I find in C# the fully qualified name here is Antlr4.Runtime.Tree.IParseTree but how to get the object?

AntlrInputStream inputStream = new AntlrInputStream(sSpinTexte);
SpinParserLexer SpinLexer = new SpinParserLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(SpinLexer);
SpinParserParser SpinParser = new SpinParserParser(commonTokenStream);
IParseTree tree = ?????

Can you please help?

Terence Parr

unread,
Dec 5, 2013, 11:28:57 AM12/5/13
to antlr-di...@googlegroups.com
tree = parser.rule();

sounds like it's time to buy the book :)

Ter
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Christian LeMoussel

unread,
Dec 5, 2013, 3:02:40 PM12/5/13
to antlr-di...@googlegroups.com
Rule() method doesn't exist in C#. 
I was told another answer with parser.StartRuleName(); StartRuleName is the name of the rule you would like to parse. 

With my example , the answer is 
IParseTree tree = SpinParser.expr();

Sam Harwell

unread,
Dec 5, 2013, 4:28:29 PM12/5/13
to antlr-di...@googlegroups.com
Hi Christian,

That's what Terence meant by the Rule method. All of the methods generated for rules defined in your parser grammar return an object that implements the IParseTree interface. 

Sam

Christian LeMoussel

unread,
Dec 6, 2013, 2:50:51 AM12/6/13
to antlr-di...@googlegroups.com
OK.
Terence , Sorry for my misunderstanding


BR


Christian.
Reply all
Reply to author
Forward
0 new messages