[antlr-interest] Token Memory / Insertion
Matthew Bowman
matthew.bowman at sogotech.com
Thu Sep 27 00:03:53 PDT 2007
I have a simple problem that I thought would be easy enough ... but as
usual I was wrong :(
I have rules in my grammar like so ... (this is simplified of course)
foo : FOO '(' a=NUM ',' b=NUM ')' -> ^(FUNC FOO $a $b)
{ memory.put("a", $a); memory.put("b", $b); };
FOO : 'foo' {barEnabled=true;};
bar : BAR -> ^(FUNC BAR)
BAR : {barEnabled}?=> 'bar';
Now in this example bar is a valid function iff foo appears before it
(and I have this working with gates). However, the 2 NUM arguments to
the foo function need to be passed to the bar function (with having to
retype them). I've tried keeping the Tokens that are parsed at foo and
can't figure a way to create a rewrite rule in bar that manages to do
something like this ...
bar : BAR -> ^(FUNC BAR {memory.get("a");} {memory.get("b");} );
Is this even close and/or possible?
Thanks in advance!
--
Matthew Bowman
More information about the antlr-interest
mailing list