https://github.com/pvskand/mini-c
An implementation of mini-c (basic features of C programming).
https://github.com/pvskand/mini-c
course-project coursework mini-compiler
Last synced: about 1 year ago
JSON representation
An implementation of mini-c (basic features of C programming).
- Host: GitHub
- URL: https://github.com/pvskand/mini-c
- Owner: pvskand
- Created: 2017-04-23T21:03:10.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-30T17:52:09.000Z (about 9 years ago)
- Last Synced: 2025-02-17T22:54:50.999Z (over 1 year ago)
- Topics: course-project, coursework, mini-compiler
- Language: C
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://www.codacy.com?utm_source=github.com&utm_medium=referral&utm_content=pvskand/mini-c&utm_campaign=Badge_Grade)
# Team Members:
1) Aakarshan Gupta
2) Himanshu Tolani
3) Jatin Garg
4) Saumya Goyal
5) Skand Vishwanath Peri
----------------------------------------------------------------------------------------------------------------------------------
# Description of Program:
This program takes in basic C text file as an input (input to be given in input.txt) and simulates that C program and results the output.
----------------------------------------------------------------------------------------------------------------------------------
# Syntax:
##### Variable assignment:
`a = 5;`
`a[1] = 5l`
`a = b;` [`b` is previously assigned, else will give an error]
##### While Loop:
```
while( Condition )
{
Statement;
};
```
*Note* : There is a `;` after the `while loop` closing curly braces.
##### Operations :
Operations are similar to that in `C` language:
###### Addition:
`a = a + 1;`
`a = b + c;`
`a = 5 + 3;`
###### Subtraction:
`a = a - 1;`
`a = b - c;`
`a = 5 - 3;`
###### Multiplication:
`a = a * 1;`
`a = b * c;`
`a = 5 * 3;`
###### Division:
`a = a / 1;`
`a = b / c;`
`a = 5 / 3;`
----------------------------------------------------------------------------------------------------------------------------------
# Description of the Grammar: (with print and read commands)
P -> S; | S;P
S -> A | W | R | O
A -> V1 = E
W -> while(E){P}
V1 -> V | Vi
V -> {a-z}+ [except while]
Vi -> V[E]
E -> E < E1 | E == E1 | E1
E1 -> E1 + E2 | E1 - E2 | E2
E2 -> E2 * E3 | E2 / E3 | E3
E3 -> (E) | V1 | C
C -> {0-9}+ . {0-9}k | {0-9}+
R -> read V1
O -> print V1 | print C
Here 0 <= j <= B is the precision limit of the decimal point
----------------------------------------------------------------------------------------------------------------------------------
# NOTE :
The name of the file is input.txt.
The precision of the decimal point is taken (by default) to be 8.
----------------------------------------------------------------------------------------------------------------------------------
# Instructions to run and compile the code:
Compile:
gcc simulator.c
Run
./a.out
The output can be viewed in output.txt file that would be created.
----------------------------------------------------------------------------------------------------------------------------------