-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Mani Sai Prasad edited this page Nov 12, 2020
·
2 revisions
msp_lang is a simple and hackable programming language for learning about compiler design
Here are some simple examples that you can perform in the msp_lang interpreter
2+2
let age = 21;
let result = 10 * (20 / 2);
We defined functions as simple as possible with let statements
Here’s a small function that adds two numbers:
let add = fn(a, b) { return a + b; };
But msp not only supports return statements. But also returns values, which means we can leave out the return if we want to:
let add = fn(a, b) { a + b; };
And calling a function is as easy as you’d expect:
add(1, 2);
We also support a special type of function, called a higher-order function.
These are functions that take other functions as arguments.
Here is an example:
>> let twice = fn(f, x) { return f(f(x)); };
>> let addTwo = fn(x) { return x + 2; };
>> twice(addTwo, 2);
6
msp Script