In this project, I tried to design a compiler for a language similar to C++. For this compiler design, I used Flex and Bison.
- Requires
flex 2.5.35
or later. - Requires
Bison 2.3
or later.
In this phase, a program is given to your code, if that program follows the lexical rules, it must print the tokens of that program in the output, otherwise, it must print the appropriate error.
flex -o Lex_Rule.cpp Lex_Rule.lex
g++ -o my Lex_Rule.cpp
./my [testCaseName]
Lexical errors detection:
Tokens of this input:
In this phase, a program is given to your code, if that program has followed the lexical and syntactic rules of the language, it will create an Abstract Syntax Tree, otherwise, it must print the appropriate error with line and column number.
bison Bison_Rule.y
bison -d Bison_Rule.y -o myapp.cpp
flex -o myapp_lex.cpp test.lex
g++ -o my myapp.cpp myapp_lex.cpp
./my [testCaseName] [number from 0 to 3]
for example to run the test case 4.in ->./my 4.in 0
- To see other run options, you can see this link
This is the Abstract Syntax Tree (AST) of 4.in:
In this phase, a program is given to your code, if that program has followed the lexical and syntactic rules of the language, it will create a MIPS code, otherwise, it must print the appropriate error with line and column number.
bison Bison_Rule.y
bison -d Bison_Rule.y -o myapp.cpp
flex -o myapp_lex.cpp test.lex
g++ -o my myapp.cpp myapp_lex.cpp
./my [testCaseName]
This is the MIPS code of testcase5_code.txt:
Reach out to me at riasiarman@yahoo.com