Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.48 KB

README.md

File metadata and controls

58 lines (40 loc) · 1.48 KB

MicroC

Intepreter, Static Analyzer, and hopefully soon a compiler of MicroC.

Project features

  • 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

Language overview

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;
}

Tests

Test uses combination of standard unit tests, and Golden.

stack exec hgold -- -u test/golden