Interpreter for a simplified C like language
It's recommended to use a virtual environment to encapsulate dependencies.
python -m venv env
source env/bin/activate
pip install -e .
Inside the projects virtual environment run:
mmci examples/operators.cmm
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);
}
Inside the projects virtual environment run:
python setup.py test
pip install -e ."[test]"
pytest