[antlr-interest] Tree transformation
mzukowski at yci.com
mzukowski at yci.com
Wed Oct 8 15:18:35 PDT 2003
Ack, the formatting got blarked. Should be this:
list_expr! : #(l:LIST s:stmt_list) {##=#(#[LPAREN,")"], #[NAME,"func"], s);}
stmt_list : #(STATEMENT_LIST (stmt)*)
-----Original Message-----
From: mzukowski at yci.com [mailto:mzukowski at yci.com]
Sent: Wednesday, October 08, 2003 3:11 PM
To: antlr-interest at yahoogroups.com
Subject: RE: [antlr-interest] Tree transformation
Your description is a bit unclear, but to get this:
LPAREN
|
NAME("func") - STATEMENT_LIST
|
ID(a) - ID(b) - ID(c)
Do this:
list_expr! : #(l:LIST s:stmt_list) {##=#(#[LPAREN,")"], #[NAME,"func"], s);}
stmt_list : #(STATEMENT_LIST (stmt)*)
Monty
-----Original Message-----
From: Arnar Birgisson [mailto:arnarb at oddi.is]
Sent: Wednesday, October 08, 2003 12:03 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Tree transformation
Hello..
I have a programming construct "[a,b,c]" which defines a list (in the
lisp sense) of the results of expressions a, b and c. The parser returns
this tree: #([LIST,"["], #(STATEMENT_LIST, #a, #b, #c)). I.e.
LIST
|
STATEMENT_LIST
|
ID - ID - ID
My languages sematnics define "[a,b,c]" to be eqivalent
"func(;a,func(;b,c))", and moreover, the user program might define
"func" to be whatever function the user wants it to be.
(As a side note: the function call syntax in the language is
func(x1,..,xN;y1,..,yM) where x1,..,xN are copy-in copy-out parameters,
and y1,...,yM are pass-by-value. Also, there is no distinction between
statements and expressions.)
I have one tree parser that takes the parser output and simplifies the
tree, before that is passed to another tree-parser, the code generator.
The simplifying treeparser (the transformer) does things like convert
"expr1 + expr1" to "+(;expr1,expr2)", and I furthermore want it to
convert the tree for "[a,b,c]" to the tree "func(;a,func(;b,c))" would
have generated.
In a nutshell, I need to convert trees of the form depicted above, to
this:
LPAREN
|
NAME("func") - STATEMENT_LIST - STATEMENT_list
|
ID(a) - ID(b) - ID(c)
How would you do in a tree-parser rule? The rules I have to match the
input tree are:
list_expr : #(LIST stmt_list)
stmt_list : #(STATEMENT_LIST (stmt)*)
Arnar
ps. for the sake of completeness, the actual language doesn't use "func"
as the function name, but rather ":". Operatrs in the language are
simply functions as the equivalence "a+b"="+(;a,b)" implied.
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list