Hi Marco, (a Cc: goes to the list) Marco Baringer writes: > > Karl Gaissmaier <[EMAIL PROTECTED]> writes: > > > statement : email! | name! | phone | fax > > > > with the semantik, that email and name is required and phone or fax > > is optional. Don't know how difficult it would be for Damian to > > have an additional layer of state to handle inside the parser or wether > > this is by principle not possible, but if it is possible it would > > help for clarity, because the grammar stay's in the grammar part and > > not in the action part. > > but what you have there is an alternation between four things, but two > of them are required, i'm not really sure what you mean. > > do you mean that a statement consists of two to four productions one > of which must be 'email' one of which must be 'name' and there can be > at most one 'phone' and at most one 'fax', and in any order? As far as > "normal" grammars go what you want is a production alternating all the > possible sequences:
yes that's what I want. I know that the solution could be the permutation of the pieces but this blows up the grammar with n!. I also know that the problem arises from, that the pieces are allowed to be unordered, but this is normal way for config files, you will not force the user to be constricted to a special order. It makes no sense to the user that: person { email = "[EMAIL PROTECTED]" name = "foo" phone = "12345" fax = "98765" } is allowed only in one specific order. > > statement : statement_piece { statement_action(); } > > statement_pice : email name | > name email | > email name phone | > .... > name email fax | > .... > fax phone name email > > it should not be difficult to auto generate this (obviously requiring > an order would greatly reduce the number of permutations). i coudl > imagine something as simpel as: > > $grammar = "statement : " . gen_prod(req => [ qw( email name ) ], > opt => [ qw( phone fax ) ]) . > " { statement_action(); }\n" . > ... > ; > sure it would be possible but makes the grammar difficult to read and the productions go with n!. > however, what you're talking about is a semantic validation of input, > something which usally happens after parsing and hence isn't dealt > with by grammars. hmm, I'm not sure that this is semantik. The semantik is, that the value of email could be used in a To: field, but the required pieces are still syntax, as we can see that this could be done with permuting the pieces. > > > > > And the following would also be sometimes useful: > > > > exor : Mr ^ Mrs ^ hybrid > > isn't this just: > > exor : Mr | Mrs | hybrid > > this requires that the exor production be one and only one of Mr, Mrs > and hybrid. what am i missing? perhaps not fully described (or understood?) by me: chooselist: salutation(s) salutation: Mr ^ Mrs that means Mr and Mrs could be only found one time, every doublette gets automatically rejected. regards Charly -- Karl Gaissmaier Computing Center,University of Ulm,Germany Email:[EMAIL PROTECTED] Network Administration Tel.: ++49 731 50-22499