-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (34 loc) · 787 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 (
"flag"
"fmt"
"os"
"github.com/antlr4-go/antlr/v4"
"github.com/itsubaki/q"
"github.com/itsubaki/qasm/gen/parser"
"github.com/itsubaki/qasm/visitor"
)
func main() {
var filepath string
flag.StringVar(&filepath, "f", "", "filepath")
flag.Parse()
if filepath == "" {
fmt.Printf("Usage: %s -f filepath\n", os.Args[0])
return
}
text, err := os.ReadFile(filepath)
if err != nil {
panic(err)
}
lexer := parser.Newqasm3Lexer(antlr.NewInputStream(string(text)))
p := parser.Newqasm3Parser(antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel))
qsim := q.New()
v := visitor.New(qsim, visitor.NewEnviron())
switch err := v.Visit(p.Program()).(type) {
case error:
panic(err)
}
for _, s := range qsim.State() {
fmt.Println(s)
}
}