bnfc icon indicating copy to clipboard operation
bnfc copied to clipboard

coercions: make pragma more intelligent

Open andreasabel opened this issue 5 years ago • 1 comments
trafficstars

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.

andreasabel avatar Dec 15 '19 01:12 andreasabel

To implement a smarter coercions pragma, we need to restructure GetCF.getCFP to make two passes over the .cf file:

  1. Collect all the non-terminals defined by rules in the .cf file.
  2. 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).

andreasabel avatar Dec 16 '19 09:12 andreasabel