-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 1.13 KB
/
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
43
44
45
46
47
48
49
50
51
package main
import (
"flag"
"fmt"
"os"
)
type Source struct {
source string
curChar string
curPos int
symbols set
labelsDeclared set
labelsGotoed set
}
func readSource(filename string) string {
b, err := os.ReadFile(filename)
if err != nil {
fmt.Print(err)
}
txt := string(b)
return txt
//check how many new lines there are
}
func main() {
var file string
flag.StringVar(&file, "f", "", "a file to compile")
//verbose := flag.Bool("v", false, "verbose mode")
// run := flag.Bool("r", false, "run the program after compiling")
flag.Parse()
if len(file) == 0 {
panic("File missing. Usage: ./compile <filename>.urdu")
}
println("Compiling file: ", file)
if file[len(file)-5:] != ".urdu" {
panic("File must be of type .urdu")
}
codeString := readSource(file)
source := Source{source: codeString + "\n", curChar: "", curPos: -1, symbols: *NewSet(), labelsDeclared: *NewSet(), labelsGotoed: *NewSet()}
emitter := Emitter{fullPath: "output/out.c", header: "", code: ""}
parser := Parser{source: source, curToken: Token{}, peekToken: Token{}, emitter: emitter}
do_parsing(parser)
}