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: [email protected]
[mailto:[email protected]] 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: [email protected] [mailto:[email protected]] On
Behalf Of Tran Thi Que Nguyet
Sent: Tuesday, November 03, 2009 2:50 PM
To: '[email protected]'
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

 

 

 


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