lox programming language ast-walking interpreter
Note: some differences compared to the original implementation of lox
- strings can be denoted with single quotes
/* multi-line comments (nesting them is not supported) */
- escape sequences supported by python are supported on pox as well
- truthiness is implemented with python's bool function (truth testing procedure)
fn
instead offun
let
instead ofvar
- pox has support for else-if (see the examples folder)
- the
print
statement doesn't exist
built-in classes:
list
this is a really thin wrapper around python's list type, see the source code for methods it has
print(value)
prints the given value to stdout without a trailing new lineprintln(value)
prints the given value to stdout with a trailing new lineinput(prompt)
python's input function, returnsnil
onEOFError
chr(int), ord(char)
python's chr and ord functions, they both returnnil
onTypeError
str(object), int(string), float(string)
python's str, int and float functions.int
andfloat
returnsnil
onValueError
strlen(string)
returns the length of a given string,nil
if the passed argument is not a stringstrn(string, n)
returns the nth char of a given string,nil
if n > len(string) or ifstring
is not a stringexit(value)
calls sys.exit with the givenvalue
time()
returns the time in seconds since the epoch as a floating point numbersleep(secs)
suspend execution of the program for the given number of secondspow(a, b)
returnsa**b