From c30c4fa892bda93ae2af21986ca0aea1a5d6e4c4 Mon Sep 17 00:00:00 2001 From: Oscar josue Rodriguez Blanco Date: Tue, 3 Jan 2023 04:23:51 +0000 Subject: [PATCH] added structs and enums --- compiler.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) 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 + } } -- 2.25.1