Class: AddNode
- Inherits:
-
BinaryNode
- Object
- BinaryNode
- AddNode
- Defined in:
- lib/ast.rb
Instance Attribute Summary
Attributes inherited from BinaryNode
Instance Method Summary collapse
- #evaluate ⇒ Object
- #ewe ⇒ Object
-
#initialize(left, right) ⇒ AddNode
constructor
A new instance of AddNode.
Constructor Details
#initialize(left, right) ⇒ AddNode
Returns a new instance of AddNode.
21 22 23 |
# File 'lib/ast.rb', line 21 def initialize(left, right) super(left,right) end |
Instance Method Details
#evaluate ⇒ Object
25 26 27 |
# File 'lib/ast.rb', line 25 def evaluate() return @left.evaluate() + @right.evaluate() end |
#ewe ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ast.rb', line 29 def ewe() iniciaAN = " sp := sp + tres \n" medioAN = "\n sp := sp - tres \n tmp := M[sp + 3] \n" medioAN = medioAN + " M[sp + 1] := tmp \n sp := sp + tres \n" finAN ="\n sp := sp - tres \n tmp := M[sp + 3] \n" finAN = finAN + " M[sp + 2] := tmp \n tmp := M[sp + 1] \n" finAN = finAN + " tmp2 := M[sp + 2] \n tmp := tmp + tmp2 \n" finAN = finAN + " M[sp + 0] := tmp \n" suma = iniciaAN + @left.ewe() + medioAN + @right.ewe() + finAN return suma end |