Project for a compiler made for a C-like language using flex, bison and the C programming language with gcc.
- Counts line number
- Returns
ERROR
token for invalid entries - Ignores single-line comments (e.g
// comment
) - Returns tokens for reserved identifiers (e.g
int
,float
), compound operators (e.g<=
,!=
) and special characters (e.g!
,+
) - Returns tokens for identifiers and literals
- Displays syntax error cause
- Implements rules for variable declaration, variable assignment, function call and more
- Implements rules for expressions
- Implements rules for function definition, command blocks
- Implements rules for unary and binary operations like negation and comparison (e.g
a >= b
,a == b
)
- Creates the AST data structure
- Builds the AST in the parser
- Creates the LexicalValue data structure
- Associates the values in the scanner
- Prints the AST recursively using DFS
- Creates the Symbol Table data structure
- Builds the Symbol Table stack in the parser
- Throws
ERR_UNDECLARED
(failed to use undeclared variable/function),ERR_DECLARED
(failed to re-declare variable/function),ERR_VARIABLE
(failed to use variable as a function call) andERR_FUNCTION
(failed to use function call as a variable) errors - Infers data types on expressions and variable assignments
- Creates the Operation List data structure
- Builds the Operation List in the parser
- Implements variable declaration address logic (rfp, rbss)
- Generates code for if statements (with/without else), while statements, unary expressions (negation, logical not), comparison expressions (==, !=, <, >, <=, >=), arithmetic expressions (+, -, *, /), loading identifiers (global/local) and storing identifiers (global/local)
To build the compiler, use make
. First, navigate to the directory containing the Makefile, then run the following command:
make
Important
You should have both flex and bison generators, as well as the gcc compiler installed previously for this step to work as expected.
To run the compiler, execute the following command in terminal:
./etapaX
Tip
You can run the compiler with an input file by using ./etapaX < filename
(e.g ./etapaX < input.txt
).
If you want to clean up your environment (delete generated files and executable), you can use the following command:
make clean
To generate the deliverable etapaX.tgz
folder, run the following command:
make deliverable
This will move all important files to the etapaX
directory and then compress it into etapaX.tgz
. Then, unzip it wherever you want, open the terminal, navigate to the unzipped folder, run and execute using the previous steps.