A tiny Lisp-like language in C
“A terribly useless language to solve none of your problems.”
~Anshul Dhawan
- Philosophy and Motives
- Prerequisites
- Installation & Usage
- Terminology
- Project Layout
- Future updates
- Contributing
Crox was developed for a variety of reasons—some stupid, some pathetic, and some astoundingly genius. To display only the golden side would be to betray the core principles of the creator’s life and the project’s raison d’être. Integrity is valued above all. Collaboration follows. Service comes third. With this attempt, the creator not only wanted to learn more about languages but also to provide a frame for what can be done outside the boundaries of what one has been taught or told to learn. A full list of misguided, pathetic, and occasionally brilliant motivations follows:
- To embark on a “real big project” and understand how languages work.
- To create everything from scratch—you must first simulate the universe (because why not?).
- As a tribute to loved ones.
- To let a stranger know this language was written with love. The sole reason it exists is because it was written for you.
- To chase the dream of a “perfect” language (spoiler: failure was spectacular).
Before invoking Crox, one must satisfy the following prerequisites:
- C Compiler
- GNU Readline (for optional line‑editing capabilities)
- make (build tool)
as it has been tested on Fedora linux this command was necessary:
sudo dnf install gcc readline-devel make- Clone the repo:
git clone https://github.com/Adheroad/Crox.git - Get inside the folder
cd Crox - Build and run the interpreter:
make run - To run tests make a .crox file and put it in test/ directory and run the following command:
make test FILE={your_file_name}.crox
$ make run // `make test` for automatic texting or you can `make` then .Crox test/`YOUR_FILE_NAME.crox`
Crox -> 1 + 2 ^ 3 ^ 2 // infix notation
513
Crox -> [+ 2 3 4] //S-Expression inside [] following polish notation
9
Crox -> {1 2 3 4} //Q-Expression inside {} Code as data follows polish notation
{1 2 3 4}
Crox -> join {1 2} {3 4}
{1 2 3 4}
Crox -> [* 3 [eval {+1 2}]]
9
Crox -> { 1 2 [* 3 4]}
{1 2 [* 3 4]}
Crox -> join {1 2} [head [init [join {[eval {+ 1 2 3 4}]} {2 3}]]]
{1 2 2}
Crox -> def {y} 20 // using Q-Expr Property to declare a variable
[]
Crox -> def {x} 30
[]
Crox -> [+ x y] // Arithmetic operations can be done on variables like simple datatypes
50
Crox -> def {x y z} 1 2 3
[]
Crox -> [+ x y z]
6
ari is the core datatype (an Atomic Runtime Instance for public). It represents all Lisp values.
Crox is a funny name whose origins are forgotten. but it still stands out and is why remains as is.
The code is divided into three subfolders: include, lib, and src.
- lib/ contains mpc.h and mpc.c from orangeduck. Thank you. These files are under the BSD license, so they were used with creative freedom.
- include/ contains all header files. All declared functions live here. Walking through this folder will give the reader a sense of Crox’s capabilities.
- src/ provides implementations for those headers.
repl.c— repl.c contains main logicari.h/ari.c— defines the ari datatype and its operationseval.c/eval.h— evaluation logic for expressionsparser.c/parser.h— defines and cleans up language parsersio.c/io.h— handles reading and printing
- basic repl
- Parsers and error handling
- Infix notation
- Polish notation
- S-Expressions
- Q-Expressions (code as data)
- variables
- functions
- conditionals
- strings
- many more
Spot an error? Feel free to open an issue or submit a pull request. Disagree with a design choice? Feedback is welcome even without a proposed fix.