An open API service indexing awesome lists of open source software.

https://github.com/xxrjun/mini-lisp-interpreter

✨ Crafting a Mini-LISP Interpreter
https://github.com/xxrjun/mini-lisp-interpreter

compilers lex lisp lisp-interpreter ncu yacc

Last synced: 3 months ago
JSON representation

✨ Crafting a Mini-LISP Interpreter

Awesome Lists containing this project

README

          

= Mini-LISP Interpreter
xxrjun
:icons: font
:toc:
:toclevels: 3
:sectnums:
:sectnumlevels: 5
:source-highlighter: rouge
:url-repo: https://github.com/xxrjun/mini-lisp-interpreter
:important-caption: :exclamation:

[quote, NCU MIS 109403019]
____
Final project for the Compilers course at National Central University, Fall 2023.
____

== Documents

* link:./docs/Compiler%20Final%20Project.pdf[Compiler Final Project Requirements]
* link:./docs/MiniLisp.pdf[Mini-LISP Language Specification]

== Developement

* *Operating System*: Windows 11, Mac OS M2
* *Language*: C++14, Lex, Yacc (Bison)

== Features

=== Basic Features

IMPORTANT: Features 1-4 must be finished before other features.

.Basic Features
[options="header, valign="middle", cols="25%,50%,^5%,^5%,^5%,^5%,^5%"]
|=======================
|Feature|Description|Points|Public1|Public2|Hidden1|Hidden2

|Syntax Validation
|Print “syntax error” when parsing invalid syntax
|10
|✅
|✅
|✅
|✅

|Print
|Implement print-num statement
|10
|✅
|✅
|✅
|✅

|Numerical Operations
|Implement all numerical operations
|25
|✅
|✅
|✅
|✅

|Logical Operations
|Implement all logical operations
|25
|✅
|✅
|✅
|✅

|if Expression
|Implement if expression
|8
|✅
|✅
|✅
|✅

|Variable Definition
|Able to define a variable
|8
|✅
|✅
|✅
|✅

|Function
|Able to declare and call an anonymous function
|8
|✅
|✅
|✅
|✅

|Named Function
|Able to declare and call a named function
|6
|✅
|✅
|✅
|✅

|=======================

Public test case points : Hidden test case points = 80% : 20% (pass partial get partial)

=== Bonus Features

.Bonus Features
[options="header, valign="middle", cols="25%,50%,^5%,^5%,^5%,^5%,^5%"]
|=======================
|Feature|Description|Points|Public1|Public2|Hidden1|Hidden2

|Recursion
|Support recursive function call
|5
|✅
|✅
|✅
|✅

|Type Checking
|Print error messages for type errors
|5
|✅
|✅
|✅
|✅

|Nested Function
|Nested function
|5
|✅
|✅
|✅
|✅

|First-class Function
|Able to pass functions, support closure
|5
|❌
|❌
|❌
|❌
|=======================

== Usage

=== Windows

[source, bash]
----
bison -d -o src/minilisp.tab.c src/minilisp.y
gcc -c -g -I. -o src/minilisp.tab.o src/minilisp.tab.c
flex -o src/lex.yy.c src/minilisp.l
gcc -c -g -I. -o src/lex.yy.o src/lex.yy.c
gcc -o bin/minilisp src/minilisp.tab.o src/lex.yy.o
----

=== Mac & Linux

[source, bash]
----
bison -d -o src/minilisp.tab.c src/minilisp.y
gcc -c -g -I. -o src/minilisp.tab.o src/minilisp.tab.c
lex -o src/lex.yy.c src/minilisp.l
gcc -c -g -I. -o src/lex.yy.o src/lex.yy.c
gcc -o bin/minilisp src/minilisp.tab.o src/lex.yy.o
----

=== Run Test (Recommended Way)

Script Features

* Compile, execute tests, and clear output files
* Count the number of test cases passed and failed
* Display expected and actual outputs for failed test cases

Excution Method

[source, bash]
----
./run_test.sh
----

Sample Project Structure

[source, bash]
----
.
|
| run_tests.sh
|
+---bin
| minilisp.exe
|
+---src
| minilisp.l
| minilisp.y
|
\---tests
| public_test_data_ans.txt
\---public_test_data
----

If encountering issues like permission error, try modifying script permissions

[source, bash]
----
chmod +x run_tests.sh
----

== References

Books

* link:http://www.cs.nthu.edu.tw/~ychung/slides/CSC4180/Crafting%20a%20Compiler%20-%202010.pdf[Crafting a Compiler 2009]

* link:http://www.nylxs.com/docs/lexandyacc.pdf[Lex & Yacc, 2/e]

* link:http://www.cs.nthu.edu.tw/~ychung/slides/CSC4180/Alfred%20V.%20Aho,%20Monica%20S.%20Lam,%20Ravi%20Sethi,%20Jeffrey%20D.%20Ullman-Compilers%20-%20Principles,%20Techniques,%20and%20Tools-Pearson_Addison%20Wesley%20(2006).pdf[Compilers Principles, Techniques, & Tools Second Edition]

* link:https://www.craftinginterpreters.com/contents.html[Crafting Interpreters]

Documents and Other Resources

* link:https://en.wikipedia.org/wiki/Lisp_%28programming_language%29[LISP - Wikipedia]

* link:https://www.gnu.org/software/bison/manual/bison.html[Bison 3.8.1 Documentation]

* NCU CE3006 Course Video and Slides

Articles and Others

* link:https://stackoverflow.com/questions/52325823/how-can-i-traverse-the-parse-tree-generated-by-yacc[How can I traverse the parse tree generated by YACC?] (Stack Overflow) - yacc does not build a parse tree. It does build (and destroy) a parse stack as it works

* link:https://keleshev.com/abstract-syntax-tree-an-example-in-c/[Abstract Syntax Tree: an example in C]

Tools

* link:https://excalidraw.com/[Excalidraw] - Virtual whiteboard for sketching hand-drawn like diagrams, good for drawing AST