X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=compiler.go;h=1585cb3e53c5342dd0e3b4d158e639dfa9fd110c;hb=c30c4fa892bda93ae2af21986ca0aea1a5d6e4c4;hp=84e3f5400ca3bca4e17f199724f270d5e5c31e5e;hpb=4d0fdf995ab098c19d5290b7c376eb5d143935e7;p=TinyThreePassCompiler%2F.git diff --git a/compiler.go b/compiler.go index 84e3f54..1585cb3 100644 --- a/compiler.go +++ b/compiler.go @@ -2,6 +2,44 @@ package main import "fmt" +type op int + +const ( + imm op = iota + arg + plus + min + mul + div +) + +type AST struct { + Op op + A *AST + B *AST + N int +} + + + func main() { - fmt.Println("Hello, world.") + //a := &AST{Op: imm, N: 5} + //b := &AST{Op: plus, A: a, B: &AST{Op: arg, N: 0}} + input := "[ a b ] a*a + b*b" + value := []rune(input) + for index, char := range value { + //make a stack and start pusing the [] to identify the start of a function and its end + //also check on a *-+/ for starting new operations with the last value and the next + //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 + //you should pull again the last value that you pushed + + //found [ start registering args to a map + // variable inside [] add to map of variables + // found ] stop registering new variables for the map + // found variable put to stack + // found inmmediate number put to stack + // found operation activate operation mode and upon next variable or inmediate add to the structure + // found ( can push another variable to stack and increment the indent counter + // found ) if no operation mode (that would be an error) then add the operations to the structure and decrement the indnet counter + } }