[antlr-interest] A few questions about AST
Jim Idle
jimi at temporal-wave.com
Mon Jun 25 09:24:57 PDT 2007
The rules:
projection
: PROJ LBRACK listAttribut RBRACK relation
-> ^(PROJ listAttribut relation);
listAttribut
: (attribut) (','! attribut)*;
Can be:
tokens
{
ATTRIB;
}
listAttribut
: a1=attribute (',' a2+=attribute) -> ^(ATTRIB $a1 $a2*)
;
Though there are other ways to formulate this of course.
The rules:
predicat: elementaryPredicat (logicalOperator elementaryPredicat)*;
// -> ^(logicalOperator elementaryPredicat elementaryPredicat);
logicalOperator
: AND
| OR;
can be:
predicat: elementaryPredicat (^logicalOperator elementaryPredicat)*;
logicalOperator: AND | OR;
Parsing the resulting tree is done via a tree parser produced by tree
grammar or by manually traversing the tree. You need to read the book
and/or examples for more details.
Jim.
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of G R
Sent: Monday, June 25, 2007 6:54 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] A few questions about AST
Hi,
I'm actually testing ANTLR to translate a relational algebra query into
SQL query for my "end of school project". Anyway, reading the wiki and
FAQ on the web site there are still a few things that i don't know how
to do.
So here is my first question :
I got this Parser rules
projection
: PROJ LBRACK listAttribut RBRACK relation
-> ^(PROJ listAttribut relation);
listAttribut
: (attribut) (','! attribut)*;
When i look at my AST, i got every attributes as child of my node PROJ.
I'd like to know how can I create an imaginary children "Attributes" to
PROJ and list every attributes in the subtree Attributes.
Instead of having :
PROJ
|______attribut1
|______attribut2
|...
|______relation
I'd like to have
PROJ
|_____Attributs
| |______attribut1
| |______attribut2
|_____relation
The second question is... How can i make a node using a parser rule ?
here is an example : I got the following rule
predicat: elementaryPredicat (logicalOperator elementaryPredicat)*;
// -> ^(logicalOperator elementaryPredicat elementaryPredicat);
logicalOperator
: AND
| OR;
As you can see I've try to make my node using the logical operator but
this don't work.
Is there anyway of doing such things?
Finally, a simple question...How do i parse the AST from my main program
in java ?
Thanks.
G. R.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070625/baa12b3f/attachment.html
More information about the antlr-interest
mailing list