BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
586 stars 165 forks source link

Make Ulf Norell's `define` example work in all backends #363

Closed andreasabel closed 3 years ago

andreasabel commented 3 years ago

The original example for define by Ulf Norell is currently only accepted by the Haskell backends. https://github.com/BNFC/bnfc/blob/3da1b0e732bd67b264d1783f6804c6b101147401/examples/DefinedRules.cf#L22-L23

Missing sanitization is a regression wrt. 2.9.1, introduced by #287. The list constructors probably never worked.

shlevy commented 3 years ago

@andreasabel We just hit:

C: list constructors rendered wrongly as make(:) and make[]

Any pointers to fix?

andreasabel commented 3 years ago

I am now working to extend the expression type by typing information, so that the printers can pick the right list constructors.

andreasabel commented 3 years ago

Remaining problem (C): non-linear definitions, like: https://github.com/BNFC/bnfc/blob/228e2eff0f4f4269b8d375814fc544c506ea6e2c/examples/define/test.cf#L25 This creates syntax trees that not trees but DAGs.

  make_Assign (x, make_EOp (make_EVar(x), make_Plus(), make_EInt(1)))

E.g. here, x is shared. This causes problems for the C deallocator which assumes that it is dealing with a tree.

shlevy commented 3 years ago

the C deallocator

A bit off topic, but is there a deallocation function provided with the generated files? I haven't seen one, I've just been manually freeing recursively down the generated structs.

andreasabel commented 3 years ago

@shlevy : The deallocation is a new, yet unreleased functionality added in a9d360d9cc0a33624e3d7f3e9c8cda01ab25cb9c (#348).

andreasabel commented 3 years ago

Remaining problem (C): non-linear definitions, like:

This has been fixed by introduction of clone_* and the cloning of duplicate components to prevent pointer aliasing and to preserve the tree-property.