https://github.com/arpith/interpreter
Interpreter in Rust
https://github.com/arpith/interpreter
Last synced: 15 days ago
JSON representation
Interpreter in Rust
- Host: GitHub
- URL: https://github.com/arpith/interpreter
- Owner: arpith
- License: mit
- Created: 2018-09-26T10:07:54.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-02T12:30:54.000Z (over 7 years ago)
- Last Synced: 2025-02-25T14:50:31.119Z (over 1 year ago)
- Language: Rust
- Size: 243 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Interpreter
Interpreter in Rust
## Status
The tokenizer and parser have been implemented and example programs are interpreted. See tests directory for sample programs.
## Usage
`$ cargo run tests/input1.txt`
## Description
This is an interpreter written in Rust for [this simple language](http://www.sci.brooklyn.cuny.edu/~zhou/teaching/cis7120/project.html) (grammar described below), in which a program consists of assignments and each variable is assumed to be of the integer type. Only operators that give integer values are included.
The interpreter can detect syntax errors, report uninitialized variables and perform the assignments (if there are no errors) and print the values of the variables after all assignments.
## Grammar
```
Program:
Assignment*
Assignment:
Identifier = Exp;
Exp:
Exp + Term | Exp - Term | Term
Term:
Term * Fact | Fact
Fact:
( Exp ) | - Fact | + Fact | Literal | Identifier
Identifier:
Letter [Letter | Digit]*
Letter:
a|...|z|A|...|Z|_
Literal:
0 | NonZeroDigit Digit*
NonZeroDigit:
1|...|9
Digit:
0|1|...|9
```
## Test cases
Sample inputs and outputs. See the tests directory for more inputs.
```
Input 1
x = 001;
Output 1
error
Input 2
x_2 = 0;
Output 2
x_2 = 0
Input 3
x = 0
y = x;
z = ---(x+y);
Output 3
error
Input 4
x = 1;
y = 2;
z = ---(x+y)*(x+-y);
Output 4
x = 1
y = 2
z = 3
```