Hi,

Thanks a lot for your suggestion.

I have another question. I am using ParseTreeBuilder to get ParseTree,
however, I cannot get the line location of a token in original source code
by parseTree.getLine().

The results of getLine() in the parseTree and its sub-parseTree are always
zero. How can I figure it out? Thanks!

 

ParseTreeBuilder builder = new ParseTreeBuilder("nil");

Parser parser = new Parser(tokens,builder);

parser.compilationUnit();

TokenStream inputStream = parser.input;

ParseTree parseTree = builder.getTree();

 

parseTree.getLine(); ---------------------à always 0

parseTree.getChild(0).getLine();---------à always 0

 

 

I was used to analyze source code using AST, and I can precisely get the
line location of a certain token by the following codes:

Parser parser = new Parser(tokens);  

parser.setTreeAdaptor(adaptor);  

Parser.compilationUnit_return ret = parser.compilationUnit();  

Asttree = (CommonTree) ret.getTree();  

 

Asttree.getChild(0).getLine();---------------àcould give me the correct the
line location of the first token.

 

Best,

Gang

 

From: Indhu Bharathi [mailto:[email protected]] 
Sent: Wednesday, September 16, 2009 7:33 AM
To: 'Gang Shu'; [email protected]
Subject: RE: [antlr-interest] About API in ANTLRWorks

 

A related mail from archive:

 

 

you mean a parse tree, not AST, right?  There is a ParseTreeBuilder i think.

T

On Sep 1, 2009, at 12:50 PM, Stefan Groschupf wrote:

 

> Hi,

> I'm making my first baby with antlr.

> Is there any chance to get a AST exactly as antlr work is generating 

> without rewriting rules.

> Thanks,

> Stefan

 

 

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Gang Shu
Sent: Wednesday, September 16, 2009 1:07 PM
To: [email protected]
Subject: [antlr-interest] About API in ANTLRWorks

 

 

Hey,

Is there any API in ANTLRWorks I can use to directly get the parse tree of a
sample source code?

 

I want to analyze the parse tree generated from Integrated Debugger in
ANTLRWorks. Is there any API in the ANTLRWorks for this goal? Thanks a lot!

 

Best,

Gang 

 


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

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

Reply via email to