[antlr-interest] parser tree structure
whaefelinger
ora.et.labora at web.de
Tue Oct 12 02:09:32 PDT 2004
Hello,
I'm wondering about the structure of my generated parse tree. Here is
what I have (quite similar to my recent posting - but much improved
now thanks to "kozchris"):
================== parser ======================================
/** stmts shall be a "list" of expressions terminated by ";" */
stmts
: ( expr {
## = #(#[STMT,"stmt"],##) ;
}
";"!
)+
;
/** an exression shall be just a number (for simplicity) */
expr: INT ;
================================================================
Here's the tree generated on input of "1;"
stmt
|
+--1
Here's the tree generated on input of "1; 2;"
stmt
|
+--stmt
|
+---1
|
+---2
I wonder here about the top most 'stmt'?
Here's the tree generated on input "1; 2 ; 3;"
stmt
|
+--stmt
|
+--stmt
| |
+--3 +--1
|
+--2
Again there's this top node having just one child.
I dot not fully understand how this tree layout is
reflected by the node construction rule
#(#[STMT,"stmt"],##)
Instead I expected to end up in something like:
stmt stmt stmt
| | |
+--stmt +--stmt +--1
| | | |
+--3 +--stmt +--2 +--1
| |
+--2 +--1
"1;2;3;" "1;2;" "1;"
which appears bit more regular in my eyes. Is there
a way to archieve this?
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list