No description
  • OCaml 87.8%
  • C 10.4%
  • Shell 1.6%
  • Standard ML 0.1%
Find a file
2018-10-01 21:40:31 +08:00
.vscode Write lexer for tiny subset of C 2018-08-09 18:08:36 +08:00
app Fix bugs and missing code in assignment 2018-09-09 20:00:35 +08:00
debug Write lexer for tiny subset of C 2018-08-09 18:08:36 +08:00
licenses Include license file for c compiler tests 2018-08-12 20:17:45 +08:00
src WIP with menhir 2018-10-01 21:40:31 +08:00
stage_7 Add stage 7 test files 2018-09-22 12:43:52 +08:00
test-kit Ternary expressions 2018-09-22 12:42:51 +08:00
tests Switch to ocamllex 2018-09-26 21:10:39 +08:00
.gitignore Read actual integer literals. 2018-08-11 12:56:32 +08:00
build.sh Compiler executable 2018-08-10 21:21:38 +08:00
compile.sh Compiler executable 2018-08-10 21:21:38 +08:00
dune Get OUnit tests running 2018-08-09 18:07:12 +08:00
dune-project WIP with menhir 2018-10-01 21:40:31 +08:00
README.md Update README - starting stage 7 2018-09-22 12:43:33 +08:00
run.sh Parsing binary operators. 2018-08-14 19:51:12 +08:00
utopd.sh Add utop via dune script 2018-08-09 18:07:21 +08:00

C Compiler in OCaml

Working from https://norasandler.com/2017/11/29/Write-a-Compiler.html

Stage 1 Lexer, recursive descent parser, and codegen. Can compile int main() {return 2;} and not much else.

Stage 2 Unary operators ~, ! and - added.

Stage 3 Binary operators +, -, *, and /, with correct precedence and associativity. Recursive descent is maintained as the parsing method (though Pratt parsing looks like a better bet)

Stage 4 Relational operators: &&, ||, ==, !=, <=, >=, <, >

Stage 5 Variables and assignment.

Stage 6 If statements and ternary (expression) operator.

Stage 7 In progress.

./compile.sh tests/stage_1/valid/newlines.c
./out.exe