-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (38 loc) · 776 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
43
44
45
46
47
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
file, err := os.Open("example.sex")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer file.Close()
// Read and process each line
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
// Tokenize
tokens := lexer(line)
// Parse into AST
ast := parser(tokens)
// Interpret (execute)
evalAST(ast)
}
if err := scanner.Err(); err != nil {
fmt.Println("Error reading file:", err)
}
// Example of when operator
cases := map[string]string{
"1": "One",
"2": "Two",
"else": "Unknown",
}
value := "1"
fmt.Println("When result:", evaluateWhen(value, cases))
value = "3"
fmt.Println("When result:", evaluateWhen(value, cases))
}