Skip to content

Commit

Permalink
Adds makefile to go interpreter (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
abasnfarah authored Mar 12, 2024
1 parent b9b1ff5 commit bd32b8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ go.work
*.exe
*.out
*.app
go/bin/*
12 changes: 12 additions & 0 deletions go/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
run:
@go run main.go

build:
@mkdir -p bin
@go build -o bin/monkey main.go
@echo "Build complete"
@echo "Run ./bin/monkey to start the program"
@echo "Or add the bin directory to your PATH"

test:
@go test -v ./...
14 changes: 12 additions & 2 deletions go/repl/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import (
"github.com/abasnfarah/monkey-interpreter/go/token"
)

const PROMPT = ">> "
const (
PROMPT = ">> "
HELP_MESSAGE = "help - show this help message\n" + "exit - exit the repl\n"
HELP = "help"
EXIT = "exit"
)

func Start(in io.Reader, out io.Writer) {
scanner := bufio.NewScanner(in)
Expand All @@ -22,10 +27,15 @@ func Start(in io.Reader, out io.Writer) {
}

line := scanner.Text()
if line == "exit" {
if line == EXIT {
return
}

if line == HELP || line == "h" || line == "" {
fmt.Fprint(out, HELP_MESSAGE)
continue
}

l := lexer.New(line)

fmt.Fprintf(out, "%+v\n", l)
Expand Down

0 comments on commit bd32b8f

Please sign in to comment.