Build me a LISP
BRANK

Normally programming language blog posts get started with grammars and syntax and parsing and all sorts of stuff like that. I can't be bothered with all of that, so instead, let's start with the (maybe more interesting aspect) of the actual evaluation of the code. Here we'll build an evaluation engine for LISP like languages in less than 50 lines of C++ — and literate C++ at that!Lisp uses something called a "cons cell" to store each part of both the program and the data. Let's just say we have something called a cell for now, and we'll come back to defining what it is later on.S-ExpressionsA Lisp program is actually just something called an s-expression. It's a fancy term for a list of cells, but there is a special way to interpret these s-expressions. We'll come back to that later on.For now, we just need to know that s-expressions describe our LISP program, and to run a LISP program we simply evaluate the s-expression.#include <vector> using sexpr = std::vector<cell>; CellsNow we …

kirit.com
Related Topics: Lisp C++