|
Roberto Ierusalimschy wrote:
Basically, my reasoning is that the simple type check solution would cover 90% of the demands at a very low cost. In other words, the gain/cost ratio is excellent for the simple type checker.The best way to support that claim is with a working prototype. Why don't you try to implement your idea?
That is true, and a fair request to back up my claims. If I can find the time, my plan would be this:
1) Extend the parser to support type annotations a few places in the grammar: In particular, variable and function declarations.
2) Add a simple typing pass when the syntax tree is built, which has two phased: a) Bubble types up from leaves in the syntax tree in a post-order depth first traversal - i.e. type deduction. b) A second traversal, which checks that the deduced types matches any declared types.
Can you give me a few pointers to where to start? I have never looked at the source code for the compiler. Where can I extend the parser, where can I extend the syntax tree with a type field, and where can I hook up such a new typing pass? Is there an example of a tree traversal somewhere?
Thanks, Asger Ottar Alstrup