A simple compiler for Go-- fictional language
This is a very simple Hybird Compiler, which means it translates the code into machine code and runs in a VM. I wrote this as part of my assignments at University for the Compiler Construction course. The language it compiles is a made up language called Go--. Rules for this language are as follows:
- Basic Data Types: integer, char.
- Keywords:
- Decision statements: if elif else.
- Looping statement: while.
- Read data statement: in.
- Function declaration statement: func.
- Write data statements: print (print and remain on same line), println (print and move to next line).
- Return keyword: ret.
- Arithmetic Operators: + - * /.
- Relational operators: < <= > >= = /=.
- Comments: /* enclose comment in */.
- Identifier: A letter followed by any number of letters or digits.
- Numeric constants: Only integers.
- Variable declaration Operator: :.
- Literal constants: A letter enclosed in single quotes.
- Strings: Only used in print statements(no variables for them).
- Parenthesis, Braces, Square Brackets.
- Aassignment operator: :=.
- Input operator: >>.
- semi colon, colon, comma.
NOTE:
Refer to Documentation.pdf for further details, including CFGs.
To get a local copy up and running follow these simple steps.
- C++ - Google for your OS.
- git
- Clone the repo
git clone https://github.com/saeenyoda/Gomm_Compiler.git
- Open up command line or terminal and navigate to the cloned repo's directory
cd "PATH-TO-DIRECTORY"
- Run the main.cpp file (Using terminal on mac)
clang++ -std=c++14 -stdlib=libc++ -I "PATH-TO-includes-FOLDER" "PATH-TO-main.cpp" "PATH-TO-lexical_analyzer.cpp" "PATH-TO-parser.cpp" "PATH-TO-translator.cpp" -o out/release/main
NOTE:
The instructions given above are for mac and that too using the terminal. For other OS and IDEs refer to the relevant docs.
This will present you with the following Screen:
Now enter the file path for the source code here. It will then run the compiler and output following files inside data folder:
- words.txt: Generated by the Lexical Analyzer, contains tokens.
- parsetree.txt: Generated by the Parser, contains parsed tree of the code.
- parse-symboltable.txt: Generated by the Parser, contains Symbol Table with Identifier and Datatype rows.
- tac.txt: Generated by the Translator, contains the three address code.
- translator-symboltable.txt: Generated by the Translator, contains updated Symbol Table, now with memory addresses.
Distributed under the MIT License. See LICENSE
for more information.