Remove commented out line of code
Create a new SourceLocation object for each Token
Fix flake8 errors
Python 3 implementation of the interpreter for the Monkey language from Thorsten Ball's Writing an Interpreter in Go.
SourceLocation
data structure and uses that
line number when reporting parse errors:
$ cat examples/parse-error.monkey
let add = fn(x, y) { x + y }
add(1, $)
$ ./monkey.py examples/parse-error.monkey
[examples/parse-error.monkey, line 2] Expected expression, found ILLEGAL($)
int64
for the Value
field of the
IntegerLiteral
struct. This interpreter uses Python's builtin arbitrary
precision int
type to represent the value of integers.nil
up the stack upon parse failure.
Rather than return the equivalent None
this interpreter chooses to instead
raise a ParseError
exception.nil
as the result of a call to
evaluator.Eval
when passed an ast.LetStatement
. Returning nil
from a
function that should always return an object.Object
violates type safety, so
this interpreter chooses to instead return a null object.HashKey
, for holding the keys of
a hash data type. Rather than define a separate type, this interpreter uses
Python's builtin __hash__
and __eq__
methods for hash key comparison.