Skip to content

Commit 9ad6324

Browse files
committed
A test script for parsing and lexing
1 parent ccfbbf6 commit 9ad6324

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

notes.txt

+8
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,11 @@ Introspection idea
166166
fmt.Printf("*** method not found\n")
167167
}
168168

169+
170+
Parser
171+
======
172+
173+
Use Python's Grammar file - converted into parser/grammar.y
174+
175+
Use go tool yacc and a hand built lexer in parser/lexer.go
176+

parser/testparser/testparser.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"os"
8+
9+
"github.com/ncw/gpython/parser"
10+
)
11+
12+
var (
13+
lex = flag.Bool("l", false, "Lex the file only")
14+
)
15+
16+
func main() {
17+
flag.Parse()
18+
for _, path := range flag.Args() {
19+
if *lex {
20+
fmt.Printf("Lexing %q\n", path)
21+
} else {
22+
fmt.Printf("Parsing %q\n", path)
23+
}
24+
in, err := os.Open(path)
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
fmt.Printf("-----------------\n")
29+
if *lex {
30+
parser.Lex(in)
31+
} else {
32+
parser.Parse(in)
33+
}
34+
fmt.Printf("-----------------\n")
35+
in.Close()
36+
}
37+
}

0 commit comments

Comments
 (0)