Skip to content

Commit

Permalink
Added repl and very basic parser
Browse files Browse the repository at this point in the history
  • Loading branch information
buddhaman committed Aug 17, 2023
1 parent d6f358c commit 9eafa3b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package main

import "fmt"
import (
"fmt"
"os"
)

func main() {
fmt.Println("Hellow world")
user := "user"

fmt.Printf("Hello %s, this is butter :)))\n", user)
ReplStart(os.Stdin, os.Stdout)
}
30 changes: 30 additions & 0 deletions cmd/repl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"bufio"
"fmt"
"io"
)

const PROMPT = ">>"

func ReplStart(in io.Reader, out io.Writer) {
scanner := bufio.NewScanner(in)

for {
fmt.Print(PROMPT)

scanned := scanner.Scan()
if !scanned {
return
}

line := scanner.Text()

l := NewLexer(line)

for tok := l.NextToken(); tok.Type != EOF; tok = l.NextToken() {
fmt.Printf("%+v\n", tok)
}
}
}

0 comments on commit 9eafa3b

Please sign in to comment.