-
Hi, I found a further problem using PEGTL master on fde02a1.
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Your input for |
Beta Was this translation helpful? Give feedback.
-
Oh sorry, I made a mistake while reducing the grammar. I give you an update when I have a correct reduction. |
Beta Was this translation helpful? Give feedback.
-
Hi,
And here the output:
Thanks for your help. |
Beta Was this translation helpful? Give feedback.
-
The library works as expected. Let's analyze what is happening in your case: The input is Now the rules are trying to match The first Now the problem is that PEGs (unlike CFGs) are truly greedy. As you have put |
Beta Was this translation helpful? Give feedback.
-
Thanks for your explanation, you are right. Perhaps I can make the grammar next week PEG conform (do you know some papers on this topic?) or I have to choose another library :-(. Again, thanks a lot. |
Beta Was this translation helpful? Give feedback.
-
I'm not aware of any paper to help you with that. But in my experience the process of manually converting a grammar from a CFG into a PEG is well worth it: It can be quite involved, but at the end you learn a lot more about how CFGs and PEGs work in general as well as how your specific grammar is constructed. Often times, I find that with the help of the PEGTL's convenience rules the resulting grammar is much clearer than the original CFG. As a final hint, make sure you check out the Good luck! |
Beta Was this translation helpful? Give feedback.
The library works as expected.
Let's analyze what is happening in your case: The input is
OBJ end OBJ;
(if I replace newline with space, which is equivalent in this case).Now the rules are trying to match
content = star<entry>
withentry = seq< IDENT, composition, "end", IDENT, ";" >
. (I hope the pseudo-syntax is OK for you)The first
OBJ
isIDENT
. Next we try to matchcomposition = seq< entry_list, star< "public" > >
. Looking atentry_list = star< name, component_list, ";" >
. And here, it matches theend OBJ;
-part of the input.name
matchesend
andOBJ
matchescomponent_list = seq< IDENT, star<...> >
.Now the problem is that PEGs (unlike CFGs) are truly greedy.
composition
does eat thee…