Nifty, though perhaps the Readme could use something a bit more explicit about the input language.
I put everything together quickly. Definitely, I could add more background info and comments ![]()
Looks like the input language is some form of Prefix-Polish LISP which uses commas instead of spaces as token separators. It is only a small compiler because the input language is small and the syntax is simple and there are no semantics.
This can be made it even simpler if coded in reverse Polish. It may be more difficult to read (for some) but doesn’t need brackets, which is the main cause of syntax errors whenever I had to program in LISP. So instead of
(add, 2, (subtract, 4, 2))
code it as
4 2 subtract 2 add
The code generation will also be a lot simpler. If it is a number, push it into the stack. If it is a keyword, perform the operation on the stack and place the result back in the stack.
Syntax compilers are simple - the old fashioned recursive descent or YACC table driven parsers are easy to understand. Once semantics are brought in stuff gets super complicated.
, but I wanted to follow The Super Tiny Compiler in JavaScript ![]()
In the LISP 1.5 spec, commas are separators, and the three following lists are equivalent:
(A,B,C)(A B C)(A, B, C)
Congratulations, you just discovered Forth.
Forth is slightly different - it has 2 stacks. ![]()