[antlr-interest] 'any order' operator in ANTLR?

Raphael Reitzig r_reitzi at cs.uni-kl.de
Wed Aug 6 06:26:52 PDT 2008


Hi!

I don't know of such a thing yet. I think that would be a nice  
extension. Maybe, it could be implemented as syntactic sugar, thus being
(A B C)# (# an operator; ~ is already taken, I think)
a shortcut for
(A B C)|(A C B)|(B A C)|(B C A)|(C A B)|(C B A)

One could argue that this naive solution would introduce one operator  
which would create exponential loads of code with just one character.  
Furthermore, it hides a lot detail and may lead to further  
understandability issues and confusions.

I do not know wether such an idea can be introduced to the algorithm  
itself, which would be a cleaner way. "If you find A, B and C in the  
following without any disturbances, normalize the permutation found to  
ABC and proceed (means: match)." I wonder what (joggled) recursion  
would do to this...

Regards

Raphaelo


"Marc Bischof" <atlan at gmx.li> wrote (Wed Aug  6 14:49:26 2008):

> Hello List,
>
> I question if an 'any order' operator makes sense in grammar development.
> Do you already considered this?
>
> I will explain what I mean in a short example:
>
> You want to model a rule S with 3 optional nonterminals (call them A B and C)
> where the order of occurrence is not relevant.
>
> So far without too much overhead you will model that like this (forcing a
> fixed order):
>
> S : A? B? C?
>
> To omit overhead, I think that for such cases it might be more clear to have
> an 'any order' operator (called  '~' here).
> With that operator one can say:
>
> S : (A? B? C?)~
>
> What do you think? Did I miss s.th.? Is it already possible with ANTLR?
>
> Cheers Marc
>



----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: PGP Digital Signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080806/a8cb0c2b/attachment-0001.bin 


More information about the antlr-interest mailing list