Skip to content
Mani Sai Prasad edited this page Nov 12, 2020 · 2 revisions

Welcome to the msp_lang wiki!

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

Playing with Integers

2+2

let age = 21;

Arithmetic expressions

let result = 10 * (20 / 2);

Functions

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);

Higher Order functions

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
Clone this wiki locally