-
To ensure the code works well, you need make, g++, flex/lex and bison installed in your system.
-
Clone this repository into your local system. The project has a single global lex file, while has separate yacc files for each of the phases to ensure code cleanliness and ease of maintenance.
-
To build any of the phases, from a terminal, go into the directory and execute the MakeFile using the
make
command. It then builds the compiler into an executable in the name ofgocompiler
in that folder. -
To run the compiler with an input file testinput.go, from the same directory as the previous step run
./gocompiler testinput.go
Note: To help execute and test the compiler quickly, there are a set of prebuilt scripts in the scripts/ folder which will help build and execute predefined test cases using the compiler. Run sh <script-name>.sh
- Conversion of strings to numbers.
- Handling Whitespace
- Handling Comments
- Update yylval, yylloc, other global variables (line and col nums) and return token code for each action.
- Record the line number and first and last column in yylloc for all tokens.
- Report lexical errors for improper strings, lengthy identifiers, and invalid characters.
- For each character that cannot be matched to any token pattern, report it and continue parsing with the next character.
- If an identifier is longer than the maximum (31 characters), report the error, truncate the identifier to the first 31 characters (discarding the rest), and continue.
- Data Value for identifiers
- Line numbers for declaration and reference
- Printing
- Variable declaration
- Const Declaration
- Assign Variables - int , float , string , bool , null
- Print String
- Simple arithmetic expressions
- Increment and decrement variables
- Boolean operations on variables
- If condition
- If else condition
- For loop
- syntax validation
- computation - Function
- Function declaration
- Function calls - Imports
- Single import
- Multiple imports
- Identifiers
- Compute Identifier values and insert in symbol table
- [x] Print line number of syntax errors
DONE
- [x] Print col number of syntax errors - [ ] String computations - [x] Recognizing errors and suggesting fix - [x] Evaluate complex logical expressions
- Compute Identifier values and insert in symbol table
- [x] Print line number of syntax errors
- Semmatic error analysis
- Print out semantic errors and continue parsing
Currentlt stops parsing
- Quadraple format
DONE
- Update Symbol table
DONE
- Type 1 Optimisation ( Remove dead code/ unreachanble code )
DONE
- Type 2 Optimisation ( Copy Propagation )
DONE
- Type 3 Optimisation ( Constant Folding )
DONE
- Type 4 Optimisation ( Constant Propagation )
DONE
- Reduce conflicts
- Parser error recovery ? Even if its declaration related!
- CFG
- All the files related to all the tasks
- Symbol table with required Information
- ReadMe file for Syntax Error Handling Strategies
- Abstract syntax tree printed in an inorder way.
- ReadMe file for Semantic Error Handling
- Three address code (in Quadruple format)
DONE
- Optimized Three address code.
DONE
- ReadMe file for the Overall Tasks