+func thirdPass(node *AST, variables []rune) {
+ /////////////////////////////////////////THINKING SPACE/////////////////////
+ //
+ // If I am a imm I just load to R0
+ // If I am an arg I just load to R0
+ //
+ //
+ // If I am an operator then I put my answer to my father on R0
+ // If my left child is a imm or arg just call it and then SW
+ // If my right child is a imm or arg just call it then SW then operate
+ // If my left is an operand then call it(not sure about this one)
+ // If my right is an operand PU then call it then SW then PO then SW
+ // If i am an operand at the end always just operate AD MU DI SU
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ switch node.Op {
+ case arg:
+ number, found := slices.BinarySearch(variables, rune(node.Value))
+ if found {
+ fmt.Printf("AR %d\n", number)
+ }
+
+ case imm:
+ fmt.Printf("IM %d\n", node.Value)
+ default:
+ switch node.Left.Op {
+ case arg:
+ number, valid := slices.BinarySearch(variables, rune(node.Left.Value))
+ if valid {
+ fmt.Printf("AR %d\n", number)
+ }
+ case imm:
+ fmt.Printf("IM %d\n", node.Left.Value)
+ default:
+ thirdPass(node.Left, variables)
+ }
+
+ switch node.Right.Op {
+ case arg:
+ fmt.Println("SW")
+ number, valid := slices.BinarySearch(variables, rune(node.Right.Value))
+ if valid {
+ fmt.Printf("AR %d\n", number)
+ }
+ fmt.Println("SW")
+ case imm:
+ fmt.Println("SW")
+ fmt.Printf("IM %d\n", node.Right.Value)
+ fmt.Println("SW")
+ default:
+ fmt.Println("PU")
+ thirdPass(node.Right, variables)
+ fmt.Println("SW")
+ fmt.Println("PO")
+ }
+
+ //need to think about which kind of child nodes make me want to PU & PO
+ switch node.Op {
+ case mul:
+ fmt.Println("MU")
+ case div:
+ fmt.Println("DI")
+ case min:
+ fmt.Println("SU")
+ case plus:
+ fmt.Println("AD")
+
+ }
+
+ }
+
+}
+