Update name change.
This commit is contained in:
parent
d9d8a27568
commit
6a96a3dd25
43
README.md
Normal file
43
README.md
Normal file
@ -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)
|
@ -2,7 +2,7 @@ package ast
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"monkey/token"
|
"monna/token"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package ast
|
package ast
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"monkey/token"
|
"monna/token"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BIN
doc/demo.png
Normal file
BIN
doc/demo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
doc/error_handling.png
Normal file
BIN
doc/error_handling.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 288 KiB |
@ -2,7 +2,7 @@ package evaluator
|
|||||||
|
|
||||||
import(
|
import(
|
||||||
"fmt"
|
"fmt"
|
||||||
"monkey/object"
|
"monna/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
var builtins = map[string]*object.Builtin{
|
var builtins = map[string]*object.Builtin{
|
||||||
|
@ -2,8 +2,8 @@ package evaluator
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"monkey/ast"
|
"monna/ast"
|
||||||
"monkey/object"
|
"monna/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package evaluator
|
package evaluator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"monkey/lexer"
|
"monna/lexer"
|
||||||
"monkey/object"
|
"monna/object"
|
||||||
"monkey/parser"
|
"monna/parser"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package lexer
|
package lexer
|
||||||
|
|
||||||
import "monkey/token"
|
import "monna/token"
|
||||||
|
|
||||||
type Lexer struct {
|
type Lexer struct {
|
||||||
input string
|
input string
|
||||||
|
@ -3,7 +3,7 @@ package lexer
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"monkey/token"
|
"monna/token"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNextToken(t *testing.T) {
|
func TestNextToken(t *testing.T) {
|
||||||
|
4
main.go
4
main.go
@ -11,10 +11,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"monkey/repl"
|
"monna/repl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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)
|
repl.Start(os.Stdin, os.Stdout)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func NewEnvironment() *Environment {
|
|||||||
/*
|
/*
|
||||||
Enclosing Environments
|
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;
|
let i = 5;
|
||||||
@ -32,7 +32,7 @@ func NewEnvironment() *Environment {
|
|||||||
puts(i);
|
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
|
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
|
would be overwritten. The ideal situation would be to preserve the previous binding to 'i' while also making a a new
|
||||||
one.
|
one.
|
||||||
|
@ -3,7 +3,7 @@ package object
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"monkey/ast"
|
"monna/ast"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ package parser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"monkey/ast"
|
"monna/ast"
|
||||||
"monkey/lexer"
|
"monna/lexer"
|
||||||
"monkey/token"
|
"monna/token"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ package parser
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"monkey/ast"
|
"monna/ast"
|
||||||
"monkey/lexer"
|
"monna/lexer"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"monkey/evaluator"
|
"monna/evaluator"
|
||||||
"monkey/lexer"
|
"monna/lexer"
|
||||||
"monkey/object"
|
"monna/object"
|
||||||
"monkey/parser"
|
"monna/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MONKEY_FACE = ` __,__
|
const MONKEY_FACE = ` __,__
|
||||||
|
Loading…
Reference in New Issue
Block a user