I have a parser and tree grammar written to add better flow control constructs
to an assembly language-like DSL.
Here's the parser grammar rule of interest:
| KW_while l=string condition=string r=string statement+
KW_endwhile
-> ^(KW_while ^(EXPR $l $condition $r) ^(SLIST statement+))
In ANTLRWorks it shows what I expect for an AST using the following text:
while $99 > 0
let $99 - 1
let $98 + 1
endwhile
The expected AST includes a tree with a root of KW_while and two children (the
EXPR and the SLIST (the list of two statement trees). I hope that makes sense.
I have a tree-walking grammar that uses "output=template" and "rewrite = true"
with the following rule:
| ^(KW_while ^(EXPR l=string condition=string r=string) ^(SLIST
s+=statement+))
-> template(lhs={$l.text}, operator={$condition.text},
rhs={$r.text}, stats={$s})
<<
L:
; while <lhs> <operator> <rhs>
test <lhs> <operator> <rhs> L_END:
<stats>
goto L:
L_END:
>>
I'm doing something wrong as the "<stats>" ends up being null and I get the
following output:
L:
; while $99 > 0
test $99 > 0 L_END:
goto L:
L_END:
What is wrong with my rewrite grammar?
--
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