In this case, it seems that changing the order of the
different options
( (zeroToThree , octalDigit , octalDigit) / (octalDigit , octalDigit)
/ octalDigit )
matters. In fact, with the longest option, it is able to recognize all
the possibility.
#/ is an ordered choice, see the method comment of #/ and the class
comment of PPChoiceParser.
To summarize: #/ tries the first choice (the receiver): if that works
it returns the result without trying any other choice; if that doesn't
work, it backtracks and tries the next choice, and so on ...
So, is it correct that I have to put always the
longest option in this cases?
Are there other approaches?
Not necessarily, you put first what has the highest priority. Note
that the ordered choice #/ is similar, but not exactly the same as the
unordered choice #| in traditional LR/LALR grammars.
Since I am not proficient enough with PetitParser, I
discarded the
idea of creating a translator from grammars specified in other
syntaxes (e.g., antlr) to PetitParser. I hope to be able to do it in the
future :)
Yes, that would be something awesome to have!
Lukas
--
Lukas Renggli
www.lukas-renggli.ch