Skip to content

mosamaasif/Gomm_Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MIT License


Logo

Simple Go-- Compiler

A simple compiler for Go-- fictional language

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. License

About The Project

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:

  1. Basic Data Types: integer, char.
  2. Keywords:
    1. Decision statements: if elif else.
    2. Looping statement: while.
    3. Read data statement: in.
    4. Function declaration statement: func.
    5. Write data statements: print (print and remain on same line), println (print and move to next line).
    6. Return keyword: ret.
  3. Arithmetic Operators: + - * /.
  4. Relational operators: < <= > >= = /=.
  5. Comments: /* enclose comment in */.
  6. Identifier: A letter followed by any number of letters or digits.
  7. Numeric constants: Only integers.
  8. Variable declaration Operator: :.
  9. Literal constants: A letter enclosed in single quotes.
  10. Strings: Only used in print statements(no variables for them).
  11. Parenthesis, Braces, Square Brackets.
  12. Aassignment operator: :=.
  13. Input operator: >>.
  14. semi colon, colon, comma.

NOTE:
      Refer to Documentation.pdf for further details, including CFGs.

Built With

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

  • C++ - Google for your OS.
  • git

Installation

  1. Clone the repo
    git clone https://github.com/saeenyoda/Gomm_Compiler.git

Usage

How to Run

  1. Open up command line or terminal and navigate to the cloned repo's directory
    cd "PATH-TO-DIRECTORY"
  2. 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:

  1. words.txt: Generated by the Lexical Analyzer, contains tokens.
  2. parsetree.txt: Generated by the Parser, contains parsed tree of the code.
  3. parse-symboltable.txt: Generated by the Parser, contains Symbol Table with Identifier and Datatype rows.
  4. tac.txt: Generated by the Translator, contains the three address code.
  5. translator-symboltable.txt: Generated by the Translator, contains updated Symbol Table, now with memory addresses.

License

Distributed under the MIT License. See LICENSE for more information.