how to express simply : a : b c d | c b d | d c b ...
1 posts in topic
Flat View  Flat View

Posted By:   Michel_Caillat
Posted On:   Friday, December 23, 2005 07:28 AM

I am wondering if there is a simpler and more elegant way to express a rule like :

a : b c d
| b d c
| c b d
| c d b
| d b c
| d c b

More generally how to express the fact that a is satisfied as soon as B C D are present independantly of their order of
occurrence. A typical usecase is a collection of attributes
of an XML element : they have to occur but their order does not matter.

Thank you in advance,
Michel Caillat
Observatoire de Paris.

Re: how to express simply : a : b c d | c b d | d c b ...

Posted By:   Jack_Hyde  
Posted On:   Wednesday, January 4, 2006 09:45 AM

I am relatively new to ANTLR but have used several other parser generators. From a syntactic viewpoint I do not know of a solution but recommend the addition of semantic rules.

a : ((x = b) | (y = c) | (z = d))+


Semantic rules to ensure that x, y and z are *not*

null (assuming that they are object references.)

If it is important that there is exactly one instance

of a, b and c then you will, of course, need to add

additional counting and validation code.


About | Sitemap | Contact