Implementing a compiler for the programming language Grace, during the lesson "Compilers" in the 4th year of our studies in the school of Electrical and Computer Engineering, National Technical University of Athens.
-
Short-circuiting: When the result of a logical operation can be evaluated just by the first argument, the second argument is not evaluated.
-
Function overloading: Function overloading cannot happen in the range of one scope, but two functions can share the same name and/or signature if they are defined in different scopes.
-
Function declarations and definitions: A function declaration must always be followed by its corresponding function definition. The parameters of a function's declaration and definition must match types and can not match names.
For more information about the technicalities of the Grace programming language, see the grace2023.pdf file.
-
Take grace program from standard input and print the intermediate or the final code to standard output.
-
Perform optimizations on the intermediate and the final code.
-
Provide informative error messages due to lexical, syntactic or semantic errors.
The packages needed to build the compiler are the ones below:
- opam/2.1.4
- ocamlfind/1.9.5
- menhir/20231231
- menhirLib/20231231
- llvm/14.0.6
- clang
- gcc
# Build compiler
make depend
make
# Remove object files (unnecessary files)
make clean
# Same as 'make clean', but also removes the executable program (./grace)
make distclean
./grace [-O] [-i | -f] filename
-O Optimizaztion flag
-f Read from stdin, assembly code to stdout
-i Read from stdin, intermediate code to stdout
-help Display this list of options
--help Display this list of options
Note: If neither of -i and -f flags are set, the compiler creates in the directory of the .grc file a .imm and a .asm file, which contain the intermediate and the final code, respectively.
To compile a simple hello-world program, run:
./grace examples/helloworld.grc
To run your program execute:
./a.out
Before opening a pull request ensure your code is properly formatted. To format your code we recommend the ocamlformat
tool, version 0.26.1. To install it execute:
opam install ocamlformat.0.26.1
The formatting style is given in the .ocamlformat
file in the base directory of the project. To format all (human generated) .ml files execute:
make format
Alternatively, you can use your own formatting tool. Make sure the formatting rules are the same ones included in .ocamlformat
.
Note: By default all files are gitignored in .gitignore
file. To add your files exclude them names from .gitignore
.
If you found this project useful, we would be grateful if you could give it a star ⭐ on GitHub. Your support is appreciated!
- Dimitrios Vassiliou
- Ioannis Giannoukos