-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproto.go
44 lines (37 loc) · 857 Bytes
/
proto.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
package proto
import (
"io/ioutil"
"os"
"github.com/fabulousduck/proto/src/lexer"
"github.com/fabulousduck/proto/src/parser"
"github.com/fabulousduck/proto/src/tokens"
)
//Proto : Defines the global attributes of the interpreter
type Proto struct {
Tokens []*tokens.Token
HadError bool
}
//NewProto : Creates a new proto instance
func NewProto() *Proto {
return new(Proto)
}
//RunFile : Interprets a given file
func (proto *Proto) RunFile(filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
proto.run(string(file), filename)
if proto.HadError {
os.Exit(65)
}
}
func (proto *Proto) run(sourceCode string, filename string) {
l := new(lexer.Lexer)
l.Lex(sourceCode, filename)
proto.Tokens = l.Tokens
p := parser.NewParser(l.Tokens)
p.Parse()
// i := newInterpreter()
// i.interpret(p.ast)
}