kjosib / booze-tools

Booze Tools will become the complete programming-language development workbench, all written in Python 3.9 (for now).
MIT License
14 stars 1 forks source link

Semantic Desugaring as Pattern-Matching Tree-Transducer #20

Closed kjosib closed 1 year ago

kjosib commented 5 years ago

Because LR parse-actions run bottom-up, computing synthesized attributes is easy but doing anything with what would be called an an inherited attribute requires another run over -- whatever data structure you built, bottom up!

If a simple generic driver could build a simple generic structure, then all manner of nice simple generic algorithms might be available.

kjosib commented 4 years ago

Related: The support.foundation module now includes a Visitor base-class which implements a limited form of multiple dispatch. This means if your syntax tree nodes are instances of different classes, then you can easily write top-down compilation passes. That still carries the notation overhead of defining a bunch of classes, but at least it's easier to organize the code. Despite a few quirks, typing.NamedTuple makes this fairly easy for most cases.

kjosib commented 1 year ago

Experience with the Visitor class shows that it's a reasonable answer.