diff --git a/README.md b/README.md new file mode 100644 index 0000000..fb2a1ce --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +## Monna Programming Language +This project is a result of learning the innards of compilers. Among other compiler books that I learned from, this was the most influential, especially in making this project: [Writing an Interpreter In Go](https://interpreterbook.com/). + +![Demo of Monna working](/doc/demo.png) + +### Using +To use the Monna interpreter, simply run `go run main.go` in the project directory.To get an executable, run `go build` in the project directory. + +### Features +#### Variables: + let x = 5; + +#### Return Statements: + return 5; + return false; + +#### Expressions: + if (x < y) { x } + + if (x > y) { y } else { x } + +#### Functions: + fn(x, y) { x + y; } + +#### String Literals: + "Hello World" + +#### Built-in Functions: +- **len()**: Returns the number of characters in a string. +``` +len("Dexter's Laboratory"); +19 +``` +- **puts()**: Prints the given arguments to STDOUT. It return a null. It only cares about printing not returning a value. +``` +puts("Sugar, spice, and everything nice!"); +Sugar, spice, and everything nice! + +``` + +#### Error Handling: +The Monna programming language also responds accordingly to errors: +![Error Handling](/doc/error_handling.png) diff --git a/ast/ast.go b/ast/ast.go index 50973e5..c85f7b4 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -2,7 +2,7 @@ package ast import ( "bytes" - "monkey/token" + "monna/token" "strings" ) diff --git a/ast/ast_test.go b/ast/ast_test.go index 7d2addd..540d2b3 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -1,7 +1,7 @@ package ast import ( - "monkey/token" + "monna/token" "testing" ) diff --git a/doc/demo.png b/doc/demo.png new file mode 100644 index 0000000..dc945df Binary files /dev/null and b/doc/demo.png differ diff --git a/doc/error_handling.png b/doc/error_handling.png new file mode 100644 index 0000000..723e55c Binary files /dev/null and b/doc/error_handling.png differ diff --git a/evaluator/builtins.go b/evaluator/builtins.go index 21dd659..96693b8 100644 --- a/evaluator/builtins.go +++ b/evaluator/builtins.go @@ -2,7 +2,7 @@ package evaluator import( "fmt" - "monkey/object" + "monna/object" ) var builtins = map[string]*object.Builtin{ diff --git a/evaluator/evaluator.go b/evaluator/evaluator.go index 8a8d3c9..60ca5e4 100644 --- a/evaluator/evaluator.go +++ b/evaluator/evaluator.go @@ -2,8 +2,8 @@ package evaluator import ( "fmt" - "monkey/ast" - "monkey/object" + "monna/ast" + "monna/object" ) var ( diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index abd5b01..a969d44 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -1,9 +1,9 @@ package evaluator import ( - "monkey/lexer" - "monkey/object" - "monkey/parser" + "monna/lexer" + "monna/object" + "monna/parser" "testing" ) diff --git a/go.mod b/go.mod index e3ed429..256e94d 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module monkey +module monna go 1.18 diff --git a/lexer/lexer.go b/lexer/lexer.go index 3d6493e..f517051 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -1,6 +1,6 @@ package lexer -import "monkey/token" +import "monna/token" type Lexer struct { input string diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 08c32ba..7735baa 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -3,7 +3,7 @@ package lexer import ( "testing" - "monkey/token" + "monna/token" ) func TestNextToken(t *testing.T) { diff --git a/main.go b/main.go index c38745a..fc0b249 100644 --- a/main.go +++ b/main.go @@ -11,10 +11,10 @@ import ( "fmt" "os" - "monkey/repl" + "monna/repl" ) func main() { - fmt.Printf("Welcome to the Monk programming language!\n") + fmt.Printf("Hello human, type some commands: \n") repl.Start(os.Stdin, os.Stdout) } diff --git a/object/environment.go b/object/environment.go index 851ba5b..a1b575e 100644 --- a/object/environment.go +++ b/object/environment.go @@ -20,7 +20,7 @@ func NewEnvironment() *Environment { /* Enclosing Environments - Here is a problem case, lets say in monkey I would want to type this: + Here is a problem case, lets say in monna I would want to type this: ``` let i = 5; @@ -32,7 +32,7 @@ func NewEnvironment() *Environment { puts(i); ``` - The ideal result of the above code in the monkey programming language is for 10 and 5 to be the outputs respectively. + The ideal result of the above code in the monna programming language is for 10 and 5 to be the outputs respectively. In a situation where enclosed environment does not exists, both outputs will be 10 because the current value of i would be overwritten. The ideal situation would be to preserve the previous binding to 'i' while also making a a new one. diff --git a/object/object.go b/object/object.go index 319b141..8c250e9 100644 --- a/object/object.go +++ b/object/object.go @@ -3,7 +3,7 @@ package object import ( "bytes" "fmt" - "monkey/ast" + "monna/ast" "strings" ) diff --git a/parser/parser.go b/parser/parser.go index b0202c6..e146976 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -2,9 +2,9 @@ package parser import ( "fmt" - "monkey/ast" - "monkey/lexer" - "monkey/token" + "monna/ast" + "monna/lexer" + "monna/token" "strconv" ) diff --git a/parser/parser_test.go b/parser/parser_test.go index 1c3f197..07aafeb 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -3,8 +3,8 @@ package parser import ( "fmt" - "monkey/ast" - "monkey/lexer" + "monna/ast" + "monna/lexer" "testing" ) diff --git a/repl/repl.go b/repl/repl.go index bf337fb..4a1db4f 100644 --- a/repl/repl.go +++ b/repl/repl.go @@ -4,10 +4,10 @@ import ( "bufio" "fmt" "io" - "monkey/evaluator" - "monkey/lexer" - "monkey/object" - "monkey/parser" + "monna/evaluator" + "monna/lexer" + "monna/object" + "monna/parser" ) const MONKEY_FACE = ` __,__