A handcrafted scheme interpreter, with lexical scoping, closures, tail recursion, and delayed evaluation enabling use of streams, as in sample programs
reduced version of https://schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-10.html#%_sec_7.1.1
token -> keyword | identifier | number | string | boolean | character | ( | ) | .
comment -> ; all characters until line break
keyword -> else | define | quote | lambda | if | set! | begin | cond | and | or | case | let | let* | letrec | delay
identifier -> initial subsequent* | peculiaridentifier
initial -> alpha | ! | $ | % | & | * | / | : | < | = | > | ? | ^ | _ | ~
subsequent -> initial | digit | + | - | .
peculiaridentifier -> + | -
number -> sign? (digit*.digit+ | digit+.digit*)
string -> "any character except "*"
character -> #\any character | #\newline | #\space
boolean -> #t | #f
alpha -> a | b | ... | Z
digit -> 0 | 1 | ... | 9
see also:
https://www.scheme.com/tspl2d/grammar.html
https://www.scheme.com/tspl4/grammar.html
https://docs.microsoft.com/en-us/cpp/c-language/lexical-grammar?view=msvc-160
Subset of https://schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-10.html#%_sec_7.1.3
program -> (expression | definition)*
definition -> (define identifier expression) | (define (identifier defformals) body)
defformals -> identifier*
expression -> identifier | literal | call | lambda | conditional | assignment
literal -> quotation | self-evaluating
self-evaluating -> boolean | character | number | string
quotation -> 'datum | (quote datum)
datum -> boolean | character | number | string | identifier | list
list -> (datum*)
call -> (operator operand*)
operator -> expression
operand -> expression
lambda -> ("lambda" formals body)
formals -> identifier | (identifier*)
body -> defintion* expression+
conditional -> ("if" test consequent alternate?)
test -> expression
consequent -> expression
alternate -> expression
assignment -> (set! identifier expression)
in addition to derived expressions: cond, and, or, let, let*, letrec, begin, delay
for a list of derived expressions: https://schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_chap_4
see also:
https://schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-10.html#%_sec_7.1.3
https://schemers.org/Documents/Standards/R5RS/HTML/ chapters 4 & 5
- Equivalence Predicates:
- eqv?
- eq?
- equal?
- Number Operation:
- number?
- integer?
- <
- <=
- >
- >=
- =
- +
- -
- /
- *
- zero?
- positive?
- negative?
- odd?
- even?
- max
- min
- abs
- remainder
- Booleans:
- not
- boolean?
- Pairs and Lists:
- pair?
- cons
- car
- cdr
- set-car!
- set-cdr!
- caar ... cddddr
- null?
- list?
- list
- length
- append
- Control Features
- procedure?
- apply
- map
- for-each
- force
- make-promise
- Eval
for a complete list of possible procedures: https://schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html#%_chap_6