Class: TimesNode

Inherits:
BinaryNode show all
Defined in:
lib/ast.rb

Instance Attribute Summary

Attributes inherited from BinaryNode

#left, #right

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ TimesNode

Returns a new instance of TimesNode.



65
66
67
# File 'lib/ast.rb', line 65

def initialize(left, right)
  super(left, right)
end

Instance Method Details

#evaluateObject



68
69
70
# File 'lib/ast.rb', line 68

def evaluate()
  return @left.evaluate() * @right.evaluate()
end

#eweObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ast.rb', line 72

def ewe()
  iniciaMN = "       sp := sp + tres \n"
  medioMN = "\n       sp := sp - tres \n   tmp := M[sp + 3] \n"
  medioMN+="       M[sp + 1] := tmp \n       sp := sp + tres \n"
  finMN ="\n      sp := sp - tres \n       tmp := M[sp + 3] \n"
  finMN+="       M[sp + 2] := tmp \n       tmp := M[sp + 1] \n"
  finMN+="       tmp2 := M[sp + 2] \n    tmp := tmp * tmp2 \n"
  finMN+="       M[sp + 0] := tmp  \n"
  times = iniciaMN + @left.ewe() + medioMN + @right.ewe() + finMN 
  return times
end