-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (32 loc) · 811 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
package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
)
func main() {
bnfIn, startRule, verbose, cnt := processArgs()
p := newBNFParser()
tree := p.parse(bnfIn)
g := newGenerator(tree, 6)
for i := 0; i < cnt; i++ {
s := g.generate(startRule, tree, verbose)
fmt.Printf("string[%d]: %s\n", i, s)
}
}
func processArgs() (io.Reader, string, bool, int) {
bnf := flag.String("bnf", "./bnf.xml", "path to an XML file containing the bnf rules for GQL")
startRule := flag.String("start", "GQL-program", "start rule name")
verbose := flag.Bool("v", false, "verbose")
cnt := flag.Int("cnt", 1, "number of grammar strings")
flag.Parse()
f, err := os.Open(*bnf)
if err != nil {
log.Fatalf("error opening xml: %s\n", err)
}
r := bufio.NewReader(f)
return r, *startRule, *verbose, *cnt
}