[antlr-interest] mismatched cardinality

Aaron Leiby aleiby.antlr at gmail.com
Wed Jun 4 15:30:15 PDT 2008


I've been working my way through the ANTLR book, and just got to the section
on Rewrite Rule Cardinality.  I'm sure the restriction that "the cardinality
of the elements within suffixed subrules and trees must always be the same
if their cardinality is greater than one" is probably best or maybe even
necessary in this context, but it reminded me of "spreads" in vvvv which are
handled a bit differently.

http://vvvv.org/tiki-index.php?page=Spreads#Connecting_Pins_with_different_slice_counts
http://vvvv.org/tiki-index.php?page=Tutorial+SpreadsII

In that case, if you had something like this:

r : a+ (b c)+ -> ^(a b c)+ ;

Where 'a' matches 0 or 1, 'b' matches only 'B's and 'c' matches only 'C's,
then given the following input:

01 BC BC BC

it would get rewritten as:

0BC 1BC 0BC

since we matched 3 (b c)s and 2 a's, we'd output 3 pairs of BC, and wrap the
a's to match.

While I cannot fathom any situations this would be handy in a language, it
turns out to be very handy in the geometric applications that vvvv was built
for.  I thought I'd bring it up in any case, since it might make a nice
option, or spark some discussion on why that would never be useful in the
problem set that ANTLR is built to solve.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080604/6fb91a3c/attachment.html 


More information about the antlr-interest mailing list