bnfc
bnfc copied to clipboard
coercions: make pragma more intelligent
The number of levels in e.g.
coercions Exp 15;
could be figured out automatically such that we only need to write
coercions Exp;
Also, the levels need not be consecutive numbers; not all missing levels should be automatically defined. Currently,
EInt. Exp100 ::= Integer;
EPlus. Exp ::= Exp "+" Exp100;
coercions Exp 100;
produces 99 trivial and superfluous categories.
To implement a smarter coercions pragma, we need to restructure GetCF.getCFP to make two passes over the .cf file:
- Collect all the non-terminals defined by rules in the
.cffile. - Expand macros like
coercions.
Currently, there is a stateless walk over the input (transDef) which calls coercionRules that has to act autonomously without knowing anything about the rest of the file.
Btw, current coercions provides an easy way to generate a grammar that generates a parser of quadratic size.
EInt. Exp ::= Integer;
coercions Exp 300;
300 coercions make happy generate a Haskell parser of already 1.2M. The grammar has around 600 rules (300 coercions, 300 entrypoint rules), the parser has around 900 states of which 600 are trivial but 300 are of linear size, having a different goto action for each of the 300 non-terminals. The size of the parse table is thus in the order of 300*300 (roughly 1M).