A compiler for a custom programming language, named UPA, created to learn basic concepts regarding the compiler theory, parsers and lexical analysers. Essentially, this language is a formal translation of the C language to Brazilian Portuguese.
Operations that are implemented are:
- Variables and function declaration;
- Assign operation;
- Printing function;
- Basic math operations;
For a full documentation on the language, please, refer to the documentation under /docs folder.
To get this compiler to work, we first have to (from the src directory):
- Generate headers and the syntactic analyser:
$ bison -d upa.y
- Then, we must generate the lexical analyser:
$ flex upa
- Finally, we are able to generate the compiler itself:
- For Linux environment:
$ gcc -g -o upa upa.tab.c lex.yy.c upa.c -lm
- For Windows:
$ gcc -g -o upa upa.tab.c lex.yy.c upa.c -lfl
- For MacOS:
$ cc -g -o upa upa.tab.c lex.yy.c upa.c -ll
Under /src/examples you will find some examples for better understanding of language syntax. Just like a normal compiler, the code can be compiled and executed as it follows (from the src directory):
$ upa ./examples/ex1.upa
$ upa ./examples/ex2.upa
$ upa ./examples/test.upa
This work was vastly based on flex & bison: Text Processing Tools, by John Levine, published by O'Reilly Media, Inc and its GitHub repo.