added structs and enums
[TinyThreePassCompiler/.git] / compiler.go
1 package main
2
3 import "fmt"
4
5 type op int
6
7 const (
8    imm op = iota
9    arg
10    plus
11    min
12    mul
13    div
14 )
15
16 type AST struct {
17    Op op
18    A  *AST
19    B  *AST
20    N  int
21 }
22
23
24
25 func main() {
26     //a := &AST{Op: imm, N: 5}
27     //b := &AST{Op: plus, A: a, B: &AST{Op: arg, N: 0}}
28     input := "[ a b ] a*a + b*b"
29     value := []rune(input)
30     for index, char := range value {
31         //make a stack and start pusing the [] to identify the start of a function and its end
32         //also check on a *-+/ for starting new operations with the last value and the next
33         //or can be a ( which pushes last value to a stack and picks up a new "first value" for this operation and ) indicating that order of operation is finish and
34         //you should pull again the last value that you pushed
35
36         //found [ start registering args to a map
37         // variable inside [] add to map of variables
38         // found ] stop registering new variables for the map
39         // found variable put to stack
40         // found inmmediate number put to stack
41         // found operation activate operation mode and upon next variable or inmediate add to the structure
42         // found ( can push another variable to stack and increment the indent counter
43         // found ) if no operation mode (that would be an error) then add the operations to the structure and decrement the indnet counter
44     }
45 }