Simple interpreter & compiler written in Go
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ast
benchmark
bytecode
compiler
evaluator
img
lexer
object
parser
repl
token
vm
.gitignore
README.md
main.go

README.md

About

Interpreter and compiler for toy language

Written in Go

See http://datasieve.blogspot.com/2018/08/building-toy-language-interpreter-in-go.html and http://datasieve.blogspot.com/2018/08/building-toy-language-compiler-in-go.html for more details

Based on https://interpreterbook.com/

Features

Supports:

  • integers, booleans, strings, arrays, hashmaps
  • prefix, infix operators
  • index operators
  • conditionals
  • global and local bindings
  • first class functions
  • return statements
  • closures

How to Run

Build:

➜ go build -o toy

Run in interpreter mode:

➜ ./toy -engine=eval
`Welcome to the Monkey programming language, elizabethwei!`
`Feel free to type in commands. Engine = eval`
>> 

Run in compiler mode:

➜ ./toy -engine=vm
Welcome to the Monkey programming language, elizabethwei!
Feel free to type in commands. Engine = vm
>> 

Logging

Run with or without intermediate print statements:

alt text

alt text