[antlr-interest] simple question regarding type propogation
William Halliburton
whalliburton at gmail.com
Wed Jul 25 16:08:46 PDT 2007
given an AST like such and the required transformation
(+ 1 2) -> numericalAdd(1,2)
(+ "a" "b") -> stringConcat("a",b")
this is easy for simple additions but does not work for nested additions
because the type of results are not easily distinguishable from the AST
what is needed is
(+ (+ 1 2) (+ 3 4)) -> numericalAdd(numericalAdd(1,2),numericalAdd(3,4))
is there a way to have the tree parser run down the children and propagate
the types upwards?
thank you very much,
will
simplified grammar is below.
mathOperation
options {backtrack=true;}
: ^('+' expression stringVal) ->
stringConcat(left={$expression.st},right={$stringVal.st})
| ^('+' expression numberVal) ->
numericaAdd(right={$numberVal.st},left={$expression.st)})
;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070725/b17268ce/attachment.html
More information about the antlr-interest
mailing list