https://github.com/ecelis/byol
Build Your Own Lisp
https://github.com/ecelis/byol
Last synced: about 1 year ago
JSON representation
Build Your Own Lisp
- Host: GitHub
- URL: https://github.com/ecelis/byol
- Owner: ecelis
- Created: 2015-09-12T00:49:24.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-06-19T06:57:50.000Z (almost 4 years ago)
- Last Synced: 2025-02-16T04:44:16.034Z (over 1 year ago)
- Language: C
- Size: 31.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
# BYOL
Basic LISP[1] interpreter based on the book Build your own Lisp[2] by Daniel Holden
### Build
cc -std=c99 -Wall parsing.c mpc.c -lreadline -lcursesw -lm -o parsing
### Run
./parsing
To get the prompt
Lezchty Version 0.0.4
(C) 2014 Daniel Holden, 2015 modifications by Ernesto Celis
Learn C and Build your own lisp at http://www.buildyourownlisp.com/
Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0
Press Ctrl+c to Exit
lez>
### Dialect specification
Lezchty grammar is based on a mathematical subset called Polish Notation[3]
which is a notation for arithmetic where the operator comes before theoperands.
1 + 2 + 6 is + 1 2 6
6 + (2 * 9) is + 6 (* 2 9)
(10 * 2) / (4 + 2) is / (10 * 2) (+ 4 2)
We say that _a program is an operator followed by one or more expressions_
where _an expression is either a number or in parentheses an operator followed
by one or more expressions_.
TODO expand dialect description.
S-Expressions are implemented as variable size arrays for simplicity, so
S-expressions in Lezchty aren't defined inductively as either atom or symbol of
number or two other S-expresions joined (_cons_) togheter. This is a change in
the roadmap.
Variables are immutable
### Examples
(+ 2 3)
(list 1 2 3 4)
{head (list 1 2 3 4)}
(eval {head (list 1 2 3 4)})
(eval (head {(+ 1 2) (+ 10 20)}))
### To-Do
* FIXME Add floating point numbers support.
* FIXME Add missing and useful operators such as ^, %, min, max
* FIXME Change - operator so that when it receives one argument negates it
* Add builtin `cons` that takes a Q-expression and appends it to the front.
* Add builtin `len` function that returns the number of elements in a Q-Expression.
* Add builtin `init` that returns all Q-Expressions except final one.
* Define JSON grammar
### References
* [C reference](http://en.cppreference.com/w/c)
* [mpc C Parser combinator library](https://github.com/orangeduck/mpc)
* [Polish notation](http://en.wikipedia.org/wiki/Polish_notation)
* [Differnce between unin and struct](https://stackoverflow.com/a/346541/1366519)
* [S-Expressions](https://en.wikipedia.org/wiki/S-expression)
[1](https://en.wikipedia.org/wiki/Lisp_(programming_language))
[2](https://github.com/orangeduck/mpc)