-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Houcine EL ADDALI
committed
Dec 3, 2023
1 parent
9338b41
commit 554fbb4
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |