-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (31 loc) · 777 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"os"
"github.com/CedricFauth/math-lang-go/interpreter"
"github.com/CedricFauth/math-lang-go/lexer"
"github.com/CedricFauth/math-lang-go/parser"
)
func failed(what ...any) {
fmt.Println(what...)
os.Exit(1)
}
func main() {
//inputs := []string{"abc = 1", "a=abc+1"}
inputs := []string{"abc TRUE FALSE == >= <= != < > = !"}
interpet := interpreter.New()
for _, input := range inputs {
lexer := lexer.New(input)
err := lexer.Scan()
if err != nil {
failed(err)
}
fmt.Printf("%v\n", lexer.Tokens())
parser := parser.New(lexer.Tokens())
expr := parser.Parse(lexer.Tokens())
res := interpreter.Evaluate(expr, interpet)
fmt.Printf("%v (%T)\n", res, res)
}
//parser.TestASTPrinter1()
//parser.TestASTPrinter2()
}