[antlr-interest] About API in ANTLRWorks
Gang Shu
gxs213 at case.edu
Thu Sep 17 10:06:17 PDT 2009
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:indhu.b at s7software.com]
Sent: Wednesday, September 16, 2009 7:33 AM
To: 'Gang Shu'; antlr-interest at antlr.org
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: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Gang Shu
Sent: Wednesday, September 16, 2009 1:07 PM
To: antlr-interest at antlr.org
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090917/d8620176/attachment.html
More information about the antlr-interest
mailing list