-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
76 lines (68 loc) · 1.29 KB
/
main.go
File metadata and controls
76 lines (68 loc) · 1.29 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"github.com/Mellywins/GoLexThatJava/lexical"
"github.com/timtadh/getopt"
"github.com/timtadh/lexmachine"
)
func main() {
short := "hv"
long := []string{
"help",
"verbose",
}
_, optargs, err := getopt.GetOpt(os.Args[1:], short, long)
if err != nil {
log.Print(err)
log.Println("try --help")
os.Exit(1)
}
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
fmt.Println("parse a java file")
os.Exit(0)
case "-v", "--verbose":
lexical.PrintLexing()
}
}
lexer := newLexer()
stmts, err := parse(lexer, os.Stdin)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
for _, stmt := range stmts {
fmt.Println(stmt)
}
for _, v := range CheckVariableHierarchyQueue {
FindHealthyOccurenceInParentContexts(v, v.Token.Value.(string))
}
}
func parse(lexer *lexmachine.Lexer, fin io.Reader) (stmts []*Node, err error) {
defer func() {
if e := recover(); e != nil {
switch e.(type) {
case error:
err = e.(error)
stmts = nil
default:
panic(e)
}
}
}()
text, err := ioutil.ReadFile("test/example.java")
if err != nil {
return nil, err
}
scanner, err := newGoLex(lexer, text)
if err != nil {
return nil, err
}
yyParse(scanner)
return scanner.stmts, nil
}