Skip to content

Jackevansevo/interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status

--C Interpreter

Interpreter for a simplified C like language

Installation

It's recommended to use a virtual environment to encapsulate dependencies.

python -m venv env

source env/bin/activate

pip install -e .

Example Usage

Inside the projects virtual environment run:

mmci examples/operators.cmm

Features

See more programs in \examples

Operators

/* Answer: 4 */

int main() {
  return ((1 + 2) * 4) / 3;
}

Conditionals

/* Answer: 2 */

int main() {
  int x = 30;
  if (x < 25) {
    return 1;
  } else if(x < 50) {
    return 2;
  } else {
    return 3;
  }
}

Functions

/* Answer: 16 */

int square(int x) {
  return x * x;
}

int main() {
  return square(5- 1);
}

Recursion

/* Answer: 21 */

int fib(int n) {
  if (n < 2) return n;
  return (fib(n - 1) + fib(n - 2));
}

int main() {
  int x = 8;
  return fib(x);
}

Closures

/* Answer: 16 */

int square(int a) {
  return a * a;
}

function twice(function f) {
  int g(int x) { return f(f(x)); }
  return g;
}

int main() {
  int cube = twice(square);
  return cube(2);
}

Running Tests

Inside the projects virtual environment run:

Quick Way

python setup.py test

Recommended Way

pip install -e ."[test]"

pytest

About

An interpreter for a simplified C like language

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages