示例#1
0
 public void S() throws IOException {
   AbstractNode node;
   AbstractNode exprn;
   Id assId;
   if (look.tag == '(' || look.tag == Tag.NUM) {
     node = E();
   } else if (look.tag == Tag.ID) {
     currentAssigneeSymbol = (Id) look;
     match(Tag.ID);
     if (look.tag == '=') {
       match('=');
       exprn = E();
       node =
           threeAddressCodeGenerator.generateCodeForNode(
               threeAddressCodeGenerator.insertAndGetLeaf(currentAssigneeSymbol),
               exprn,
               "="); //// generate code for assignment
     } else {
       skipId = currentAssigneeSymbol;
       currentAssigneeSymbol = null;
       skipFlag = 1;
       node = E();
     }
   } else {
     throw new Error("Syntax Error");
   }
 }
示例#2
0
  public AbstractNode F() throws IOException {
    AbstractNode abstractNode = null;
    if (look.tag == '(') {
      match('(');
      abstractNode = E();
      match(')');
    } else if (look.tag == Tag.ID) {
      Id word = (Id) look;
      String workLex = word.lexeme;
      stackMachine.postfixTokenStack.push(word);
      match(Tag.ID);
      abstractNode =
          threeAddressCodeGenerator.insertAndGetLeaf(
              word); // insert leaf to  processed symbols if not exists
      postFix.append(workLex);
      // System.out.print(workLex);

    } else if (look.tag == Tag.NUM) {
      Num num = (Num) look;
      String IntNum = num.tostring();
      match(Tag.NUM);
      stackMachine.postfixTokenStack.push(num);
      abstractNode =
          threeAddressCodeGenerator.insertAndGetLeaf(
              num); // insert leaf to  processed symbols if not exists
      postFix.append(IntNum);
      // System.out.print(IntNum);
    } else if (look.tag == Tag.FLOAT) {
      Real real = (Real) look;
      String floatNum = real.tostring();
      match(Tag.FLOAT);
      stackMachine.postfixTokenStack.push(real);
      abstractNode =
          threeAddressCodeGenerator.insertAndGetLeaf(
              real); // insert leaf to  processed symbols if not exists
      postFix.append(floatNum);
      // System.out.print(floatNum);
    } else if (skipId != null && skipFlag == 1) {
      Id word = (Id) skipId;
      String workLex = word.lexeme;
      stackMachine.postfixTokenStack.push(word);
      match(Tag.ID);
      abstractNode =
          threeAddressCodeGenerator.insertAndGetLeaf(
              word); // insert leaf to  processed symbols if not exists
      postFix.append(workLex);
      skipId = null;
      // System.out.print(workLex);
    } else {
      throw new Error("Syntax Error");
    }
    return abstractNode;
  }
示例#3
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;
 }