Concurrent lisp-type language lexer, parser, optimizer written in go.
I am calling it basilisk.
The lexer.Lex() takes a string, this could be a file or any other text string and is run concurrently on a channel. It chugs along on the string emitting tokens as it goes. The channel can then be given to parser.Parse() (along with a chan *parser.Tree), which takes these tokens and builds a parse tree, the parse tree is returned on the second channel upon completion. The parse tree can be optimized by handing it to optim.Eval(), which will return a *optim.Tree. optim.Tree has a String() interface, so you can just print it. If you want to do something else, you can just go through what's left in the tree (unknown variables and the pending/unknown keys).
For more information, refer to the wiki
Note: If you are writing a program, and want it to execute when the program is loaded, for now append it with the line:
exec
If you would like to see an implementation of this, check out Basilisk, which is an interpreter which just takes file or input text and runs the three functions above on it. Minus some subtle printing, that is about all it does.
This section lists the things that work, some pieces of the library like lang/token will allow lang/lexer to lex more tokens than either lang/parse or lang/optim will actually allow to be evaluated.
+is add-is subtract*is multipy/is divideassignassigns a variable to a value (an unevaluated ast)lambdadefines a function with a list of args the first argument, and the operations as the secondcmpevaluates the first argument, if it is 1 it executes the second arg, if it isn't it executes the thirdeqandltfor equals and less than evaluate two numbers and return 0 or 1timereturns the system time in nanosecondsprintprints somethinglazyforces non-lazy evaluation on variablesevalevaluates a string of basilisk as basilisk
This snippet would evaluate factorial 40 and then print it.
(assign factorial
(lambda (list n)
(cmp n 1
(* n (factorial (- n 1))))))
(print "Factorial 40 is " (factorial 40))Factorial 40 is 8.159152832478977e+47This code is licensed under a 2-clause BSD-style license that can be found in the LICENSE file.