Writing An Interpreter In Go



  • Section 2.3:
    • Correct spelling of “Earley parsing” (from “Early parsing”)

7 May 2020 - 1.7

  • Code:
    • Added go.mod files to the code folder so that users with Go >= 1.13 can easily run it without having to set $GOPATH
  • Section 1.5:
    • Update wrong token types in example Lexer output
    • Change from fmt.Printf to fmt.Fprintf to make use of out
  • Section 1.3:
    • Fix a grammar mistake by removing the additional “the” in “Of the course”
  • Section 2.9:
    • Fix a typo by changing “intends” to “indents”
  • Section 3.9:
    • Change “How to we” to “How do we”
    • Fix missing word in “we should bind it too” by rewriting sentence

20 March 2019 - 1.6

  • Section 2.4:
    • Fix wrong parseOperatorExpression in pseudo-code example for recursive-descent parser
  • Section 2.5:
    • Change wrong capitalization in test error message
  • Section 4.5:
    • Correct explanation of HashKey by clarifying that ObjectType is a string (as opposed to an integer)

31 July 2018 - 1.5

Besides fixes for various typos and spelling errors:

  • Chapter 2:
    • Fix wrong mention of program.Body in test error messages and change it to program.Statements
  • Section 1.3:
    • Make it clearer where to put import "monkey/token" line
  • Section 2.4:
    • Fix wrong error message in testLetStatement helper function
    • Fix wrong indentation of input in test function
    • Fix missing imports of fmt package
  • Section 2.5:
    • Fix wrong mention of ParseProgram instead of the correct parseStatement
  • Section 2.6:
    • Fix wrong explanation of failing test output in prefix operators section
    • Fix wrong explanation of the for-loop condition in parseExpression
    • Rename local variable oe to ie in *ast.InfixExpression methods
  • Section 2.8:
    • Change post-refactoring version of TestParsingInfixExpressions to make clearer that it has been refactored
    • Fix wrong error message in testInfixExpression
    • Fix wrong output in test error message (“true” to “TRUE”)
    • Add missing import of strings package
    • Change wording to make clearer that the section includes changes to the existing test suite
  • Section 2.9:
    • Add the missing import of monkey/parser to the REPL code
  • Section 3.5:
    • Fix wrong error message in failing test output for TestEvalBooleanExpression
  • Section 3.8:
    • Add missing import of fmt
  • Section 3.10:
    • Add missing import
  • Chapter 4:
    • Remove unused import of unicode/utf8 package
  • Section 4.5:
    • Add note about hash collisions when explaining the HashKey methods
    • Fix wrong failing test output after adding a test to TestErrorHandling
  • Going Further:
    • Add link to the sequel Writing A Compiler In Go.

28 June 2017 - 1.4

  • Section 1.4:
    • Use a local variable to save the literal when creating token.EQ and token.NOT_EQ
  • Section 2.3:
    • Fix a small typo
  • Section 2.4:
    • Change incorrect mention of peekPosition in lexer to correct readPosition
  • Section 2.6:
    • Fix duplicate test input in TestOperatorPrecedenceParsing here and in the following sections where it’s referenced
  • Section 3.9:
    • In the first example the expression 5 * 5 was used and the text explained that this should evaluate to 10, which is wrong. It should evaluate to 25, of course.
  • The Lost Chapter:
    • Added a new section at the end of the book about The Lost Chapter: A Macro System For Monkey and where it can be found.

26 January 2017 - 1.3

  • License of the code:
    • The code folder and its content are now licensed under the MIT license. See the LICENSE file and/or the README.md file.
  • Section 1.1:
    • Make clear that whitespace is only significant in the sense that it separates tokens, but not its length.
  • Section 1.3:
    • Small wording change
    • Fix wrong reference to NextToken when readChar was meant
  • Section 2.8:
    • Fix the parseBlockStatement method so it doesn’t run into an endless loop when parsing incomplete input
  • Section 4.2:
    • Fix the readString method so it doesn’t run into an endless loop when a string in the input is not terminated with a closing double quote
  • Section 4.4:
    • Fix a typo in the error message of the builtin push function

20 December 2016 - 1.2

  • Section 2.8:
    • Add a missing semicolon to the test input in TestLetStatements
  • Section 4.4:
    • Fix the failing test for the builtin push function. Error was introduced with the last update. This change only occurrs in the code accompanying the book and only in subfolder 04.

8 December 2016 - 1.1

Besides fixed typos and spelling errors:

  • Introduction
    • Change the “How To Use This Book” subsection to include a link to the downloadable archive of the accompanying code
  • Section 1.4:
    • Add hint about accompanying code
    • Show the last, fully extended version of the test input for TestNextToken
  • Section 2.6:
    • The failing test output for TestParsingPrefixExpressions in the book text was wrong. It’s corrected to match the actual output one gets when building the parser from scratch
    • Fix wording that didn’t match the described test output
    • Remove token.LPAREN from the precedences table here. It somehow slipped in at this point, but should only be added later on in section 2.8, where tests are supposed to fail because it’s missing
  • Section 2.8:
    • Fix wrong test expectation ("x" changed to "y") in TestLetStatement
    • Change parser_parser_test.go to parser_test.go
    • Better show how to use testLiteralExpression in TestParsingInfixExpressions
    • Fix outdated test output for failing TestOperatorPrecedenceParsing, TestIfExpression, TestIfElseExpression, TestFunctionLiteralParsing
  • Section 3.10:
    • Change the Inspect() method of *object.Function to use fn instead of function and newlines in output
    • Remove needless semicolons in example
  • Section 3.5:
    • Change from if/else to “if and return” in nativeBoolToBooleanObject
  • Section 3.6:
    • Update the version of testNullObject to be the one in the accompanying code, with a correct call to t.Errorf
  • Section 4.4:
    • Name the token.Token field of ast.ArrayLiteral
    • Fix possible panic through nil error in “first”, “last”, “rest”, and “push” functions by adding separate check
  • Section 4.5:
    • Name the token.Token field of ast.HashLiteral
    • Replace null in output with missing error message when trying to access hash via index expression before it’s implemented
  • Section 4.6:
    • Change the expected output using puts with a function literal to match the updated Inspect() of *object.Function
    • Explain the nulls in the expected output of put better

23 November 2016 - 1.0

  • Initial Release