Skip to content

This is a C-based simple interpreter that scans a list of expressions and variable assignments from a given file, then evaluates these expressions and prints them using basic data structures such as arrays, stacks, heaps and binary search trees.

License

Notifications You must be signed in to change notification settings

MohEsmail143/simple-interpreter

Repository files navigation

Simple Interpreter

This is a simple C-based interpreter that executes instructions and print the result of execution. The program accepts a text file as source code, parses it, and prints the value of each variable. For example:

Src.txt

X = 12.5
Y = X*4/5
Z = X*Y/5
M = Z*-2
K = 10.5+ (Z-2.5)/(X+Y)

First, the output of the process should be the display of all variables each one with its value, sorted by the variable name:

K = 11.5
M = -50
X = 12.5
Y = 10
Z = 25

Second, all variables are displayed each one with its value sorted by value, such as:

M = -50
Y = 10
K = 11.5
X = 12.5
Z = 25

Implementation Details

  • Expression evaluation was done by converting the expression from infix to postfix notation, using stacks.
  • Variables are stored in a BST each node having a key/value:
    • Key as the variable name
    • Value is the value of the variable
  • Insertion of a new item is done by calling a function put(k,v) where k is key and v is value:
    • If the key already exists update the value
    • If not, insert a new key/value pair.
  • Sorting by variable name is done using inorder traversal for BST.
  • Sorting by value is done using the heapsort algorithm.
  • Data Structures used:
    • Arrays
    • Stacks
    • Binary Search Trees
    • Heaps

This project was developed as the final project of the course Data Structures I in the Spring 2020 semester at the Faculty of Engineering, Alexandria University, under the Computer and Communications Engineering department, supervised by Dr. Mohamed Salama.

Prerequisites

This project was developed using the Code::Blocks IDE as a C console application.

Installing

1- Clone the repository to your local machine:

git clone https://github.com/MohEsmail143/simple-interpreter.git

2- Open the project using the Code::Blocks IDE.

3- Run the project by clicking on the button Build and run. The following window should appear:

CLI of Interpreter

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

This is a C-based simple interpreter that scans a list of expressions and variable assignments from a given file, then evaluates these expressions and prints them using basic data structures such as arrays, stacks, heaps and binary search trees.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages