Clisp – Demo Lisp Compiler

 

CLisp is a sample lisp compiler which compiles to MSIL. CLisp is developed in C# and uses reflection emit to generate MSIL. It can also be adapted as an interpreter if the generated MSIL is executed dynamically instead of persisting to a PE file.

 

It compiles functions like car, cdr, cons, atom, null, subst. Not all the Lisp functions are implemented, others can be added with ease, as they are implemented as a runtime library.  Control flow structures such as if-then-else and do-while have been implemented.   Recursive function calls are supported

 

The compiler consists of the following modules (also seperate c# source files):

 

Lexer:

            converts the input file into a token stream. Strips out the source code comments.

Parser:

            parses the token stream outputing an AST.  Syntax errors are reported, but error recovery is not great. Multiple errors are not reported.

Semantic Analyzer:

            Analyzes the AST and augments it with semantic information using an bottom-up approach. Currently Int and lists are the only types. Floating points are not supported now.

Code Generator:

            Visits the AST and generates corresponding IL.

 

 

Usage:

clisp <lisp-filename> (Sort.lisp and Fibo.lisp are included as sample input files)