Modelica
Modelica Language is a non-proprietary, object-oriented, equation-based language to conveniently model complex physical systems containing, e.g., mechanical, electrical, electronic, hydraulic, thermal, control, electric power or process-oriented subcomponents. Modelica is a growing language, presenting new language constructions every now and then. A fellow researcher asked me whether the process of adding new features to the language cound be simplified. My answer was obviously yes, but you will have to learn a bit of Haskell. The result was a modular compiler construction. The main idea was to build a specific AST to each compiler stage based on blocks and traversable/foldable functions. Sadly we did not finish this project, and the code was left to die. The main ideas implemented for modular construction and consumption used here were: + Data Types a la Carte : for simple modular data construction. + High-Order Functors and High-Order Free Monad: bigger trees with holes :D!. Classic definitions with a bit more Type/Kind information.
data HFree :: ((u -> *) -> u -> *) -> (u -> *) -> u -> * where
Return :: f a -> HFree h f a
Op :: h (HFree h f) a -> HFree h f a
This lets us consume such a structure with a catamorphism, given a high-order functor.
As presented to me, there were three basic stages, each with a slightly different AST. With my implementation we could state explicitly how to build such an AST and write simple functions from one stage to the next. For example, the flat-expression Modelica AST:
type FlatAstDom =
ClassDefinition + DerivedExtendedClass + EnumShortClass + RegularClass (Ident, Ident)
+ Composition + Component TypePrefix + External (FlatRef := 'TSubscript) + Declaration + ElementMod + Modification
+ Assign (FlatRef := 'TSubscript) + CallOutput CallArguments (FlatRef := 'TSubscript) + Statement + CallEq CallArguments
+ ForEq + IfWhen + EString + CallExpression + NumExp + Reference (FlatRef := 'TSubscript) + ArrayCons CallArguments
+ Expression + Subscript + FunExp