[antlr-interest] [antlr-dev] Antlr & Tree programming

Indhu Bharathi indhu.b at s7software.com
Tue Nov 3 01:38:18 PST 2009


I guess this article might help you:

 

http://www.antlr.org/wiki/display/ANTLR3/Tree+construction

 

It has a good test rig.

 

Cheers, Indhu

 

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Indhu Bharathi
Sent: Tuesday, November 03, 2009 3:02 PM
To: 'Tran Thi Que Nguyet'
Cc: 'ANTLR Interest Mailing List'
Subject: Re: [antlr-interest] [antlr-dev] Antlr & Tree programming

 

Moving this to antlr-interest.

 

What you do after that depends on what you want. Have you constructed an AST
in the grammar? Then to get the AST, you have to do this:

 

CommonTree t = (CommonTree)r.getTree();

 

And if you want to give this tree to a tree walker, you can do this:

 

// create a stream of tree nodes from AST built by parser

CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);

// tell it where it can find the token objects

nodes.setTokenStream(tokens);

// create the tree Walker

MyWalker walker = new MyWalker (nodes); 

// walk the tree

walker.startRule();

 

 

Though these are JAVA api, I guess those for C# has to be almost same. You
are not programming on a drastically different language like C.

 

Section 9.6 of ANTLR Definitive ref talks about this in detail.

 

Cheers, Indhu

 

 

 

From: antlr-dev-bounces at antlr.org [mailto:antlr-dev-bounces at antlr.org] On
Behalf Of Tran Thi Que Nguyet
Sent: Tuesday, November 03, 2009 2:50 PM
To: 'antlr-dev at antlr.org'
Subject: [antlr-dev] Antlr & Tree programming

 

Dear all,

 

My name is Tran. I'm doing research on my master thesis. But I have troubles
about how to analysis a sql script file *.sql which contains SQL and PL
commands. 

After that, I knew ANTLR can be used to parse languages. And I also know
there is the PL/SQL grammar in the website.

 

But now, I want to know (after searching a lot but I didn't find out) how I
can use the result after using the method parse for the start rule? 

I'm programming with C# (I cannot change into Java which has more
documentations).

 

I want to retrieve which commands in the script, which objects are accessed,
which . How can I do?  Can you show me some tutorials (step by step)? 

I don't know what I can do after this?

ANTLRFileStream input = new ANTLRFileStream("test.sql");

            PLSQL3Lexer lexer = new PLSQL3Lexer(input);

            CommonTokenStream tokens = new CommonTokenStream(lexer);

            PLSQL3Parser parser = new PLSQL3Parser(tokens);

            PLSQL3Parser.start_rule_return r = parser.start_rule();

 

Thank you for all your help. I need you very much.

 

Tran

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091103/a4aa6cd0/attachment.html 


More information about the antlr-interest mailing list