|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
[JJTree] Set of mandatory and optional tokens (each once)Hi
Is there a smart solution or a JJTree mechanism to deal with the following: A set of Parameter Value pairs should be parsed. Some of these pairs are mandatory and the rest is optional. The set of pairs is also unordered. With JJTree, is it possible to mask certain pairs as mandatory? Or is it needed to add some JAVA functionality (e.g. checkExistenceOfRequiredParamaters(...))? -- Sincerely, Helko Glathe --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
RE: [JJTree] Set of mandatory and optional tokens (each once)Hello
If your set is known at design time, and the mandatory / optional pairs also, I believe you should be able to write your grammar more or less like this : PARSER_BEGIN(xxx) // counters for mandatory pairs int mp1 = 0; ... int mpn = 0; // counters for optional pairs int op1 = 0; ... int opm = 0; PARSER_END(xxx) // delimiters TOKEN : { < SET_LEFT_DEL : something > | < SET_RIGHT_DEL : something > } TOKEN : { < PAIR_LEFT_DEL : something > | < PAIR_RIGHT_DEL : something > | < PAIR_MID_DEL : something > } // mandatory parameters and values TOKEN : { < M_P1 : something > | < M_V_1 : something > | ... | < M_Pn : something > | < M_V_n : something > } // optional parameters and values TOKEN : { < O_P1 : something > | < O_V_1 : something > | ... | < O_Pm : something > | < O_V_m : something > } // mandatory pairs TOKEN : { < M_1 : <PAIR_LEFT_DEL> <M_P1> <PAIR_MID_DEL> <M_V1> <PAIR_RIGHT_DEL> > { mp1++; } | ... | .n. } // optional pairs TOKEN : { < O_1 : <PAIR_LEFT_DEL> <O_P1> <PAIR_MID_DEL> <O_V1> <PAIR_RIGHT_DEL> > { op1++; } | ... | .m. } // set TOKEN : { < SET_LEFT_DEL > ( <M_1> | ... | <M_n> )+ ( <O_1> | ... | <O_m> )* < SET_RIGHT_DEL > < EOF > { if (mp1 == 0} throw new ParseException("missing mandatory pair xxx"); ...; .n.; if (mp1 > 1} throw new ParseException("duplicated pair xxx"); } ...; .n.; if (op1 > 1} throw new ParseException("duplicated pair xxx"); } ...; .m.;} Marc MAZAS -----Message d'origine----- De : Helko Glathe [mailto:glathe.helko@...] Envoyé : jeudi 25 juin 2009 23:32 À : users@... Objet : [JavaCC] [JJTree] Set of mandatory and optional tokens (each once) Hi Is there a smart solution or a JJTree mechanism to deal with the following: A set of Parameter Value pairs should be parsed. Some of these pairs are mandatory and the rest is optional. The set of pairs is also unordered. With JJTree, is it possible to mask certain pairs as mandatory? Or is it needed to add some JAVA functionality (e.g. checkExistenceOfRequiredParamaters(...))? -- Sincerely, Helko Glathe --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free embeddable forum powered by Nabble | Forum Help |