Intepreter, Static Analyzer, and hopefully soon a compiler of MicroC.
- Interpreter
- Semantic analysis: undefined/dup names, creating pointer to fun is forbidden, recursive records, accessing undefined fields of a record, assignments save to l-value.
- Dataflow analysis: const & sign analysis, very busy and reaching definitions analysis
- Compiler to ostorc vm
The language is sourced from the NI-APR course.
A program is a collection of functions. (No global variables or so.)
Regarding types, we have integers, records and pointers.
A function has N parameters. It begins with definition of variables used in the body of the function, and has only a single return at the end.
Grammar:
Fun ⟶ Id ([Id, ..., Id]) {
[ var Id, ..., Id; ]
[ Stmt ]
return Expr;
}Regarding statements, we support assignment, if condition, while loop and output statement (that prints out its argument).
Assignments
Regarding expressions, we have basic arithmetics, alloc (something like malloc), reference, dereference, user input, and basic literals.
Example program:
main() {
var rec, ptr;
rec = { foo: 3, bar: main };
ptr = &(rec.bar);
*ptr = 5;
output rec.bar;
return 0;
}
Test uses combination of standard unit tests, and Golden.
stack exec hgold -- -u test/golden