Recreated and improved Monkey language from the book "Writing an Interpreter in Go" by Thorsten Ball and rewrote it with Typescript. This project taught me a lot about the part that's usually automated - the parser and evaluation of parsed code. I also learned a lot about Golang and its advantages over Typescript.

Base features:

  • Integers, booleans, strings, hash maps
  • Arithmetic expressions
  • Variables
  • Conditionals
  • First-class and higher-order functions
  • Closures
  • Recursion
  • Built-in functions
  • Macros

Additional features:

  • for and while loops
  • break to stop the current loop within the scope
  • Variable scopes for if, for, and while blocks
  • Assign existing variables without keywords let
  • Execute code from files via the CLI command
  • Line number in error message for parser and evaluator
  • Float numbers (INT + FLOAT = FLOAT, INT + INT = INT)
  • Allow numbers in identifiers
  • Mandatory semicolon for expression statements
  • Add items to hashmap via built-in function - add
  • Less or Equal(<=) and Greater or Equal(>=) operators
  • Fixed bug: "!0" now evaluates correctly to TRUE

Example:

example