-
Greetings,
and i want to implement it with PEGTL
it is working for inputs consisting of even number of uppers but not working with inputs consisting of odd number of uppers
it seems that when the parser is having an even number of 'upper' .it consumes one on the first 'sor' which is correct .but in the "opt" part ,instead of consuming it on the 'upper' part outside the 'star' and accepting the grammer.it consume it inside the 'star' part and then gives an parsing error. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
I reformatted your grammar, and the problem became apparent: You pass the last
you need:
So the |
Beta Was this translation helpful? Give feedback.
-
...and I also just realize that this won't work either. OK, digging deeper: You probably try to write a PEGTL-equivalent of the following rule:
Besides the difference between A semantically correct version of the above CFG as a PEG might look like this:
I'll leave it to you to adapt your PEGTL grammar, feel free to ask if you need more help 🙂 |
Beta Was this translation helpful? Give feedback.
-
Thanks very much for the help. |
Beta Was this translation helpful? Give feedback.
-
Very interesting indeed. Thank you @d-frey for your great explanations.
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
And one more tip for improving the efficiency: It might be more efficient (and semantically identical) to use
instead of
|
Beta Was this translation helpful? Give feedback.
...and I also just realize that this won't work either. OK, digging deeper: You probably try to write a PEGTL-equivalent of the following rule:
Besides the difference between
PN_CHARS_U
andPN_CHARS
(the latter not being just uppercase characters) you have one major problem in your understanding of grammars: The above is a rule from a CFG (a Context-Free Grammar) and not from a PEG (a Parsing Expression Grammar). They look extremly similar, but they have a different semantic. Hence you need to adapt those rules from CFG to PEG as otherwise the naive translation will never match the optional part as the star is…