Skip to content

Commit

Permalink
feat: repel v0 to print tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Houcine EL ADDALI committed Dec 3, 2023
1 parent 9338b41 commit 554fbb4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
45 changes: 45 additions & 0 deletions REPL/repel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package repl

import (
"bufio"
"fmt"
"io"

"github.com/houcine7/JIPL/lexer"
"github.com/houcine7/JIPL/token"
)

// REPL :Read --> Evaluate --> Print --> loop
// the repl used to interact with users to read from console
// and send to interpreter to evaluate then prints back the result

/*
* Function as the start method of the repl
* To interact with the user via terminal
*/

const PROMPT="$>>"


func Start(in io.Reader, out io.Writer){
scanner := bufio.NewScanner(in);
fmt.Println(" ********** ")
fmt.Println("------------- Welcome to JIPL REPLE ------------")
fmt.Println(" ********** ")
for {
fmt.Print(PROMPT)
scanned := scanner.Scan()
if !scanned {
return
}
line :=scanner.Text()

replLexer :=lexer.InitLexer(line);

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

}
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"fmt"
"os"
"os/user"

repl "github.com/houcine7/JIPL/REPL"
)

func main() {
currUser, err := user.Current();

if err !=nil{
panic(err)
}

fmt.Printf("Hello %s!, welcome to JIPL happy coding :)",currUser.Username)
fmt.Printf("Start typing JIPL code ...\n")
repl.Start(os.Stdin,os.Stdout)
}

0 comments on commit 554fbb4

Please sign in to comment.