-
I've noticed when writing DCG parsers, especially when things like whitespace are involved, it becomes really difficult to write a parser that also generates with fair enumeration. I've asked about this before with fair tree enumeration, but I haven't been able to generalize this to a full parser. I noticed an interesting technique in the json library. There is a Is this a good approach to copy for general generative monotonic DCG parsers? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
I also find handling white spaces troublesome when I work with DCGs. You might consider 2 passes: first "lexer" that normalizes spaces and new lines, and then second pass with an actual grammar. Also consider to relax your grammar a little to be able to handle errors more gracefully. |
Beta Was this translation helpful? Give feedback.
-
Regarding |
Beta Was this translation helpful? Give feedback.
-
See this too. |
Beta Was this translation helpful? Give feedback.
-
I found a somewhat relevant paper where they describe some DCG rules that can deal with spaces and allows "greedy rules" which isn't necessarily the most trivial thing to do in DCG. Also they have full implementation for SWI and it can probably be easily ported to Scryer. |
Beta Was this translation helpful? Give feedback.
I also find handling white spaces troublesome when I work with DCGs. You might consider 2 passes: first "lexer" that normalizes spaces and new lines, and then second pass with an actual grammar. Also consider to relax your grammar a little to be able to handle errors more gracefully.