An experiment in type checker generation. Warning: work in progress!
From the user perspective the basic idea is as follows:
- Start with a Rascal grammar of the language of interest, say, MiniML.
- Write functions for specific language constructs
definecaptures all defining occurrences of variables and their scopes;
usecaptures all uses of variables;
requirecaptures all static requirements on the use of certain constructs, such formal/actual parameter correspondence and the like;
calculateto compute a type for a language fragment using earlier calculated types, think of the result type of an operator based on its argument types.
- The above functions will populate a fact/requirement model (or
TModelfor short) of a source program to be type checked.
- Apply the
collectfunction to a parsed program (a parse tree). This will apply
calculateto all relevant places in the tree, will create scopes and use/def information and will also build a collection of constraints. They are all part of the
TModelresulting from the previous step.
solveis happy if all constraints can be solved and generates error messages otherwise.
solvealso enhances the original
TModelwith derived facts that can be used for use/def analysis, interactive display of type information, and the like.