jzimmerman / langcc

langcc: A Next-Generation Compiler Compiler
https://langcc.io
Apache License 2.0
1.73k stars 58 forks source link

An alternative flattening procedure reminiscent of CPS. #44

Closed modulovalue closed 1 year ago

modulovalue commented 1 year ago

ON EXTENDED CONTEXT FREE GRAMMARS AND LR-PARSING by Ole Lehrmann Madsen Bent Bruun Kristensen (1975) discusses a very similar technique to the CPS transformation that langcc uses. They propose an alternative flattening scheme that can provide some of the benefits of the CPS transformation proposed here, all without needing a separate post-processing step.

At the bottom of page 55, a discussion on how to eliminate the +-operator can be found and page 33 discusses how to eliminate the -operator and inline-alternation operators. Unless I've missed it, the ?-operator is not being discussed in the paper, but the -operator essentially shows what flattening the ?-operator could look like, which feels pretty much like what the CPS transformation would propose.

I think, it would be interesting to know whether the CPS technique subsumes these "Kristensen"-transformations, or whether to maximize the expressivity of a parser generator, a parser generator would benefit from supporting both of them. This isn't entirely obvious to me, especially if one were to extend the kristensen-style flattening approach to operators that support explicit interspersion.

@jzimmerman @mathpirate @leoadberg I'd love to hear your thoughts on this issue, if you have any. (and on the other issues that I've opened here.)

modulovalue commented 1 year ago

It looks like CPS does indeed subsume the approach that Madsen and Kristensen presented in their paper.