Skip to content

A simple compiler for a language similar to C++ (Creates an Abstract Syntax Tree (AST) and MIPS code)

Notifications You must be signed in to change notification settings

arman324/My-Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple compiler for a language similar to C++

Overview

In this project, I tried to design a compiler for a language similar to C++. For this compiler design, I used Flex and Bison.

Requirements

  • Requires flex 2.5.35 or later.
  • Requires Bison 2.3 or later.

Goal:

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.

How to Run:

  1. flex -o Lex_Rule.cpp Lex_Rule.lex
  2. g++ -o my Lex_Rule.cpp
  3. ./my [testCaseName]

Output:

Lexical errors detection:

2020-05-01 15 37 56

Tokens of this input:

Screen Shot 2020-08-07 at 10 06 35 PM

Goal:

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.

How to Run:

  1. bison Bison_Rule.y
  2. bison -d Bison_Rule.y -o myapp.cpp
  3. flex -o myapp_lex.cpp test.lex
  4. g++ -o my myapp.cpp myapp_lex.cpp
  5. ./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

Output:

This is the Abstract Syntax Tree (AST) of 4.in:

Screen Shot 2020-08-07 at 1 43 12 PM

Goal:

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.

How to Run:

  1. bison Bison_Rule.y
  2. bison -d Bison_Rule.y -o myapp.cpp
  3. flex -o myapp_lex.cpp test.lex
  4. g++ -o my myapp.cpp myapp_lex.cpp
  5. ./my [testCaseName]

Output:

This is the MIPS code of testcase5_code.txt:

Screen Shot 2020-08-07 at 2 49 00 PM

Support

Reach out to me at riasiarman@yahoo.com

About

A simple compiler for a language similar to C++ (Creates an Abstract Syntax Tree (AST) and MIPS code)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published