Skip to content

Developing a Basic Compiler for Parsing Math Equations into Three-Address Code

Notifications You must be signed in to change notification settings

MiladNooraei/Simple-Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Simple Compiler

Implemented a simple Compiler which reads a text file containing a math equation as input and gives three address code as output

Description

In this project we have a text file containing a math equation with four symbols :

  • :A: for adding (+)
  • :S: for subtracting(-)
  • :M: for multiplying(*)
  • :D: for dividing(/)

And we want to generate three address code. Only Three phases of lexical analysis, syntax analysis, intermediate code generation are implemented. The priority of the operators is as usual, but their participation is the opposite. For each operator, the calculation of operands is reversed.

Here are some input and output examples:

Input -> x = 3 :D: 4:S: 12
Output ->

t1 = 4/3;
x = 12-t1;
Input -> x = 3 :D: (4:S: 12)
Output -> 

t1 = 12-4;
x = t1/3;
Input -> x = 36 :M: test :D: ps :A:123
Output -> 

t1 = ps/test;
t2 = t1*36;
x = 123+t2;

About

Developing a Basic Compiler for Parsing Math Equations into Three-Address Code

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published