This is a compiler that extends on a subclass of common-LISP that covers integer arithmetic, an experimental string handling, if clause, if-else clause and switch clause. The authors of the module have taken liberty to handle strings in an experimental way that strays away from the common-LISP standard to give a better experience for the users.
As a part of the project, the contributors have implemented:
- Lexical Analysis
- Parsing
- Abstract Syntax Tree creation
- Syntax Directed Translation to 3 Address Code
- Intermediate code optimization
- Superoptimization using pre-computation
- Assembly code generation to NASM targeting x86_64 machines running GNU/Linux
To generate relocatable binary, we are using GCC to convert object file generated by NASM assembler into a relocatable binary that can be run on an x86_64 machine running GNU/Linux based operating system.
The compiler is built using:
- POSIX Lex
- POSIX Yacc
- GCC
- NASM
- Boolean: #t for true and #f for false
- Number: Signed integer from −( 2^31 ) to 2^31
| Name | Symbol | Example |
|---|---|---|
| Plus | + | (+ 1 2) => 3 |
| Minus | - | (- 1 2) => -1 |
| Multiply | * | (* 2 3) => 6 |
| Divide | / | (/ 6 3) => 2 |
| Modulus | mod | (mod 8 3) => 2 |
| Greater | > | (> 1 2) => #f |
| Smaller | < | (< 1 2) => #t |
| Equal | = | (= 1 2) => #f |
| And | and | (and #t #f) => #f |
| Or | or | (or #t #f) => #t |
| Not | not | (not #t) => #f |
| define | ||
| fun | ||
| if |
separator [ \t\n\r]
letter [a-z]
digit [0-9]
number 0|[1-9]{digit}*|-[1-9]{digit}*
ID {letter}({letter}|{digit}|"-")*
bool-val #[t|f]
- Program
PROGRAM : STMT STMTS
STMTS : STMT STMTS | {}
STMT : EXP | DEF-STMT | PRINT-STMT
PRINT_STMT : '(' print_num EXP ')'
| '(' print_bool EXP ')'
- Expression
EXPS : EXP EXPS | {}
EXP : bool_val | number | VARIABLE | NUM_OP | LOGICAL_OP | FUN_EXP | FUN_CALL | IF_EXP
- Numerical Operations
NUM_OP : PLUS | MINUS | MULTIPLY | DIVIDE | MODULES | GREATER | SMALLER | EQUAL
- Logical Operations
LOGICAL_OP : AND_OP | OR_OP | NOT_OP
- Define statement
DEF_STMT : '(' define VARIABLE EXP ')'
VARIABLE : id
- If Expression
IF_EXP : '(' _if TEST_EXP THAN_EXP ELSE_EXP ')'
TEST_EXP: EXP
THAN_EXP: EXP
ELSE_EXP: EXP
Clone this repository and execute the following command:
./compile.sh <path to lisp file> Further elaborate details regarding this project can be found in 'Project Report.pdf' file present in this repository