Exemplo n.º 1
0
 public void L() throws IOException {
   S();
   stackMachine.evaluate(null);
   if (currentAssigneeSymbol != null) {
     currentAssigneeSymbol.value = stackMachine.value;
     // System.out.println();
     postFix.append("\n");
     if (currentAssigneeSymbol.type == "int" && stackMachine.value instanceof Float) {
       postFix.append(
           "Warning : Stack Machine-Time mismatch (Narrowing convention) between assignee id type ="
               + currentAssigneeSymbol.type
               + " calculated value type="
               + Type.Float.tostring()
               + "\n");
       // System.out.println("Warning : Stack Machine-Time mismatch (Narrowing convention) between
       // assignee id type ="+currentAssigneeSymbol.typeOb.tostring()+ " calculated value
       // type="+Type.Float.tostring());
     } else if (currentAssigneeSymbol.type == "float" && stackMachine.value instanceof Integer) {
       postFix.append(
           "Warning : Stack Machine-Time mismatch (Widening convention) between assignee id type ="
               + currentAssigneeSymbol.type
               + " calculated value type="
               + Type.Int.tostring()
               + "\n");
       // System.out.println("Warning : Stack Machine-Time mismatch (Widening convention) between
       // assignee id type ="+currentAssigneeSymbol.typeOb.tostring()+ " calculated value
       // type="+Type.Int.tostring());
     }
     // System.out.println(currentAssigneeSymbol.lexeme+"="+currentAssigneeSymbol.value);
     postFix.append(currentAssigneeSymbol.lexeme + "=" + currentAssigneeSymbol.value + "\n");
   } else {
     // System.out.println();
     postFix.append("\n");
     postFix.append(stackMachine.value);
   }
   currentAssigneeSymbol = null;
   // toCode(AbsNode.used,bw);
   AbstractNode.processedSymbols = new ArrayList<AbstractNode>(); // new set of nodes for new stmt
   AbstractNode.tempVal = 0;
   System.out.println("Postfix notation and value of the statement");
   System.out.println(postFix);
   System.out.println();
   postFix = new StringBuffer();
   match(';');
   L1();
 }
Exemplo n.º 2
0
 public AbstractNode T1(AbstractNode factnodeinh) throws IOException {
   AbstractNode node; // node which rerpesents the operation so far
   AbstractNode snode; // synthesised attribute which gives the full answer
   AbstractNode prefn = factnodeinh; // previous factor nonterminal is inherited
   AbstractNode curfn;
   if (look.tag == '*') {
     match('*');
     curfn = F();
     // System.out.print("*");
     postFix.append("*");
     stackMachine.evaluate("*");
     node =
         threeAddressCodeGenerator.generateCodeForNode(
             prefn, curfn, "*"); // generate code for node
     snode = T1(node);
   } else {
     snode = factnodeinh;
   }
   return snode;
 }