The AST ahs whatever information in it that you give it. You don’t need the 
rule names, they are just an abstraction for parsing.

 

Jim

 

From: Ketan Maheshwari [mailto:[email protected]] 
Sent: Wednesday, March 31, 2010 8:27 AM
To: Jim Idle
Cc: [email protected]
Subject: Re: [antlr-interest] How to get GUI like tree structure

 

Jim

 

About the purpose of having ParseTree : I need to know what tokens are children 
of a given rule in my input so that I can separate tokens based on the rules 
and put them into places in a customized object which in turn is required to 
generate  output in xml format! 

So, essentially I am building a translator from my DSL to its xml 
representation for which an xml writer exists. I just need to give it correct 
java object!

 

I think a ParseTree only can do this since ASTs does not have rule names they 
just have the tokens arranged in a tree.

 

Regards

Ketan

 

 

On Wed, Mar 31, 2010 at 5:11 PM, Ketan Maheshwari <[email protected]> 
wrote:

Jim

 

Thanks for your quick answer. The code shown uses the -debug option to generate 
parser and lexer classes, but I have problems with the debug option that when I 
use it the parser just hangs and does not go ahead.


Any solution as to generate a ParseTree without using the debug option.

 

Ketan

 

On Wed, Mar 31, 2010 at 4:58 PM, Jim Idle <[email protected]> wrote:

I think you are looking for the wrong thing. You are unlikely to need the parse 
tree in order to operate upon the input. You are almost certainly in need of an 
AST that you build yourself using the ANTLR tree building constructs.



Did you search the WIKI:



http://www.antlr.org/wiki/pages/viewpage.action?pageId=1760




Jim





From: Ketan Maheshwari [mailto:[email protected]]

Sent: Wednesday, March 31, 2010 7:47 AM

To: Jim Idle
Cc: [email protected]
Subject: Re: [antlr-interest] How to get GUI like tree structure



Hi Jim, Hi All



I searched but still am struggling to really get the parsertree object for my 
grammar.



My goal is to get the parser tree object just as being shown in the GUI and put 
its elements in another object that I need to construct based upon the tree.



But after a lot of search I still have no clue how do I get the ParserTree 
object with a *hierarchy of rules* and leaf nodes as the actual *tokens* of my 
program!



Many thanks for any help with this.



Regards

Ketan



On Mon, Mar 29, 2010 at 6:30 PM, Jim Idle <[email protected]> wrote:

Ah. You are asking for the parser tree, not a representation of the AST? Search 
the mailing list for this. Such a tree is not generally useful for doing things 
with (so if you are looking for this information because you want to use it to 
generate code or something, then you are probably looking at your problem 
incorrectly), but it is very useful for debugging the tree.



http://antlr.markmail.org/search/?q=parse+tree





If all you want is information in the nodes, then get the payload of the leaf 
node (usually CommonToken) and ask for it, but that’s what the code you looked 
at is doing.



Jim





From: Ketan Maheshwari [mailto:[email protected]]
Sent: Monday, March 29, 2010 9:18 AM
To: Jim Idle
Cc: [email protected]
Subject: Re: [antlr-interest] How to get GUI like tree structure




Jim



Thanks again for your answer.



1. I checked the DOTTreeGenerator.java code but I do not seem to know how it 
finds all the info about a tree. Also I am confused with its use of both the 
stringtemplates and trees (are'nt they mutually exclusive?).



2. Yes, the toStringTree() method prints the tree but it only gives the leaf 
nodes, that is the program itself. I have no info about which rule a given 
token belongs to.



To be more clear, see the attached snapshot. My question is how can I capture 
this parse tree in a some kind of java data structure and walk through it.



Many Thanks again for all your help.

Ketan



On Mon, Mar 29, 2010 at 5:41 PM, Jim Idle <[email protected]> wrote:

Look at the code for DOTTreeGenerator.java or use toStringTree() if that gives 
you a good enough representation.

Jim


> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Ketan Maheshwari
> Sent: Monday, March 29, 2010 7:36 AM
> To: [email protected]
> Subject: [antlr-interest] How to get GUI like tree structure
>
> Hello Friends
>
> I am trying to use the CommonTree generated by the parser of my grammar
> against a test code.
>
> Using the getChild(index).toString method, I get the tokens well.
>
> However, I do not know how can I also get a hierarchy of the rule to
> which
> they belong to. Similar to what we get in the ANTLRworks GUI.
>
> Any clue how can I get a tree such that it shows complete hierarchy of
> the
> grammar and the tokens as leaf nodes only.
>
> Am I using the correct Data Structure (CommonTree) ?
>
> Thanks for any clues.
>
> Regards
> Ketan
>

> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address






List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address






List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

 

 




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.

Reply via email to