[antlr-interest] How to implement implicit concatenation operator (for Regular Expressions)
Bryan Ewbank
ewbank at gmail.com
Mon Oct 2 09:04:00 PDT 2006
I think there's an issue if there are more than two adjacent regex's
because of the way the rule is written to use "#a" -- which is not
modified. I think it chops off part of the result. Try this instead:
basicRE:!
a:simpleRE ( b:simpleRE { #a = #([CONC,"conc"], #a,#b); } )*
{ ## = #a; }
;
You might also consider allowing CONC to be an n-ary operator, rather
than a binary operator; , and allow an optional user-specified CONCAT
operator:
basicRE:
a:simpleRE ( CONCAT! b:simpleRE )*
{ ## = #([CONC,"conc"], ##); }
;
On 10/2/06, Manuel Kirschner <kirschner at inf.unibz.it> wrote:
> OK, found the solution by turning off standard tree construction.
>
> > basicRE : simpleRE ((CONCAT^) simpleRE)*;
>
> Now, instead of expecting a CONCAT operator, a CONC node is inserted
> into the AST:
>
> basicRE : a:simpleRE (! b:simpleRE {#basicRE = #([CONC,"conc"], #a, #b); } )* ;
>
More information about the antlr-interest
mailing list