Example #1
0
 /**
  * Small-step semantics
  *
  * @return The expression after taking a single reduction step
  */
 public Aexp reduce(Memory memory) {
   if (!a1.isValue()) return new Sub(a1.reduce(memory), a2);
   else if (!a2.isValue()) return new Sub(a1, a2.reduce(memory));
   else return new ConstantInt(a1.value() - a2.value());
 }
Example #2
0
 /**
  * Compilation
  *
  * @return List of abstract machine (AM) instructions
  */
 public Code compile() {
   return a2.compile().append(a1.compile()).append(new AM.Sub());
 }
Example #3
0
 /**
  * Big-step semantics
  *
  * @return Value of the expression
  */
 public int eval(Memory memory) {
   return a1.eval(memory) - a2.eval(memory);
 }