Implementing monkey interpreter while learning from Writing an Interpreter in GO `
-
Pratt top-down parsing is used by parser to populate the AST, as this is a simple and scalable strategy.
-
Walk-the-tree strategy is used at the time of evaluation. A tree- walking interpreter that recursively evaluates an AST is probably the slowest of all approaches, but easy to build, extend, reason about and as portable as the language it’s implemented in. We’re going to take the AST our parser builds for us and interpret it “on the fly”, without any preprocessing or compilation step.
-
No garbage collector of its own does monkey posses. GO's garbage collector does the job good enough for us.;)
let a=2; #Semicolons can be ommitted or used#
let a=fn(a,b){
a+b; #Functions are first class citizens and can be used as a variable,passed around in functions,etc#
}
5 #Will return 5#
5+5 # Will return 10 #
10 #Given all these expression statements, output of last expression will be returned , in this case 10. i.e output of program
# comments are enclosed between two hashes like this #
#
Multiline comments can be made like this.
#
# in case other hash is not encountered, all the code after first one will be commented.
Objects are enclosed in double-curly brackets instead of single.
let a ={{
"name:"ashish"
}}