Exemplo n.º 1
0
void compileDoWhileSt(void) {
  assert("Parsing a do..while statement ....");
  // TODO
    eat(KW_DO); 
    compileStatement();  
    eat(KW_WHILE);
    compileCondition();  

  assert("Do..While statement parsed ....");
void compileForSt(void) {
  Type* varType;
  Type *type;

  eat(KW_FOR);

  varType = compileLValue();
  eat(SB_ASSIGN);
  type = compileExpression();
  checkTypeEquality(varType, type);

  eat(KW_TO);
  type = compileExpression();
  checkTypeEquality(varType, type);

  eat(KW_DO);
  compileStatement();

}
Exemplo n.º 2
0
void compileArgument(Object* param) {
  Type* type;

  if (param->paramAttrs->kind == PARAM_VALUE) {
    type = compileExpression();
    checkTypeEquality(type, param->paramAttrs->type);
  } else {
    type = compileLValue();
    checkTypeEquality(type, param->paramAttrs->type);
  }
}
Exemplo n.º 3
0
void compileArgument(Object* param) {
  // TODO: parse an argument, and check type consistency
  //       If the corresponding parameter is a reference, the argument must be a lvalue
  Type* type;
  if (param->paramAttrs->kind == PARAM_VALUE) {
    type = compileExpression();
    checkTypeEquality(type, param->paramAttrs->type);
  } else {
    type = compileLValue();
    checkTypeEquality(type, param->paramAttrs->type);
  }
}
Exemplo n.º 4
0
void compileCondition(void) {
  Type* type1;
  Type* type2;
  TokenType op;

  type1 = compileExpression();
  checkBasicType(type1);

  op = lookAhead->tokenType;
  switch (op) {
  case SB_EQ:
    eat(SB_EQ);
    break;
  case SB_NEQ:
    eat(SB_NEQ);
    break;
  case SB_LE:
    eat(SB_LE);
    break;
  case SB_LT:
    eat(SB_LT);
    break;
  case SB_GE:
    eat(SB_GE);
    break;
  case SB_GT:
    eat(SB_GT);
    break;
  default:
    error(ERR_INVALID_COMPARATOR, lookAhead->lineNo, lookAhead->colNo);
  }

  type2 = compileExpression();
  checkTypeEquality(type1,type2);
}
Exemplo n.º 5
0
void compileCondition(void) {
  // DONE: check the type consistency of LHS and RSH, check the basic type
  Type* type1;
  Type* type2;

  type1 = compileExpression();
  checkBasicType(type1);

  switch (lookAhead->tokenType) {
  case SB_EQ:
    eat(SB_EQ);
    break;
  case SB_NEQ:
    eat(SB_NEQ);
    break;
  case SB_LE:
    eat(SB_LE);
    break;
  case SB_LT:
    eat(SB_LT);
    break;
  case SB_GE:
    eat(SB_GE);
    break;
  case SB_GT:
    eat(SB_GT);
    break;
  default:
    error(ERR_INVALID_COMPARATOR, lookAhead->lineNo, lookAhead->colNo);
  }

  type2 = compileExpression();
  checkTypeEquality(type1,type2);
}
Exemplo n.º 6
0
void compileCondition(void) {
  // check the type consistency of LHS and RSH, check the basic type
  Type *exp1 = compileExpression();
  checkBasicType(exp1);

  switch (lookAhead->tokenType) {
  case SB_EQ:
    eat(SB_EQ);
    break;
  case SB_NEQ:
    eat(SB_NEQ);
    break;
  case SB_LE:
    eat(SB_LE);
    break;
  case SB_LT:
    eat(SB_LT);
    break;
  case SB_GE:
    eat(SB_GE);
    break;
  case SB_GT:
    eat(SB_GT);
    break;
  default:
    error(ERR_INVALID_COMPARATOR, lookAhead->lineNo, lookAhead->colNo);
  }

  Type *exp2 = compileExpression();
  checkBasicType(exp2);

  // Compare 2 sides
  checkTypeEquality(exp1, exp2);
}
Exemplo n.º 7
0
void compileAssignSt(void) {
  // TODO: parse the assignment and check type consistency
  Type* varType;
  Type* expType;
  varType=compileLValue();
  eat(SB_ASSIGN);
  expType=compileExpression();
  checkTypeEquality(varType, expType);
}
Exemplo n.º 8
0
void compileAssignSt(void) {
  Type* varType;
  Type* expType;

  varType = compileLValue();
  
  eat(SB_ASSIGN);
  expType = compileExpression();
  checkTypeEquality(varType, expType);
}
Exemplo n.º 9
0
void compileAssignSt(void) {
  // parse the assignment and check type consistency
  Type *lvalueType = NULL;
  Type *expType = NULL;

  lvalueType = compileLValue();
  eat(SB_ASSIGN);
  expType = compileExpression();
  checkTypeEquality(lvalueType, expType);
}
Exemplo n.º 10
0
void compileForSt(void) {
  CodeAddress beginLoop;
  Instruction* fjInstruction;
  Type* varType;
  Type *type;

  eat(KW_FOR);

  varType = compileLValue();
  eat(SB_ASSIGN);

  genCV();
  type = compileExpression();
  checkTypeEquality(varType, type);
  genST();
  genCV();
  genLI();
  beginLoop = getCurrentCodeAddress();
  eat(KW_TO);

  type = compileExpression();
  checkTypeEquality(varType, type);
  genLE();
  fjInstruction = genFJ(DC_VALUE);

  eat(KW_DO);
  compileStatement();

  genCV();  
  genCV();
  genLI();
  genLC(1);
  genAD();
  genST();

  genCV();
  genLI();

  genJ(beginLoop);
  updateFJ(fjInstruction, getCurrentCodeAddress());
  genDCT(1);

}
Exemplo n.º 11
0
void compileForSt(void) {
  // DONE: Check type consistency of FOR's variable
  Type* varType;
  Type *type;

  eat(KW_FOR);
  varType = compileLValue();

  eat(SB_ASSIGN);
  type = compileExpression();
  checkTypeEquality(varType, type);

  eat(KW_TO);
  type = compileExpression();
  checkTypeEquality(varType, type);

  eat(KW_DO);
  compileStatement();
}
Exemplo n.º 12
0
Type* compileTerm(void) {
  Type* type1;
  Type* type2;

  type1 = compileFactor();
  type2 = compileTerm2();
  if (type2 != NULL) {
    checkTypeEquality(type1,type2);
  }

  return type1;
}
Exemplo n.º 13
0
Type* compileExpression2(void) {
  Type* type1;
  Type* type2;

  type1 = compileTerm();
  type2 = compileExpression3();
  if (type2 == NULL) return type1;
  else {
    checkTypeEquality(type1,type2);
    return type1;
  }
}
Exemplo n.º 14
0
void compileAssignSt(void) {
  // TODO: Generate code for the assignment
  Type* varType;
  Type* expType;

  varType = compileLValue();
  
  eat(SB_ASSIGN);
  expType = compileExpression();
  checkTypeEquality(varType, expType);
  genST();
}
Exemplo n.º 15
0
void compileForSt(void) {
  // TODO: Check type consistency of FOR's variable
  Type* varType;
  Type *type;

  eat(KW_FOR);
  //eat(TK_IDENT);

  // check if the identifier is a variable
  //checkDeclaredVariable(currentToken->string);
  varType = compileLValue();
  eat(SB_ASSIGN);
  type = compileExpression();
  checkTypeEquality(varType, type);

  eat(KW_TO);
  type = compileExpression();
  checkTypeEquality(varType, type);

  eat(KW_DO);
  compileStatement();
}
Exemplo n.º 16
0
void compileArgument(Object* param) {
  // parse an argument, and check type consistency
  //       If the corresponding parameter is a reference, the argument must be a lvalue
  if (param->paramAttrs->kind == PARAM_REFERENCE) {
    if (lookAhead->tokenType == TK_IDENT) {
        checkDeclaredLValueIdent(lookAhead->string);
    } else {
        error(ERR_TYPE_INCONSISTENCY, lookAhead->lineNo, lookAhead->colNo);
    }
  }

  Type *argType = compileExpression();
  checkTypeEquality(argType, param->paramAttrs->type);

}
Exemplo n.º 17
0
void compileForSt(void) {
  // Check type consistency of FOR's variable
  eat(KW_FOR);
  eat(TK_IDENT);

  // check if the identifier is a variable
  Object *var = checkDeclaredVariable(currentToken->string);
  checkBasicType(var->varAttrs->type);

  eat(SB_ASSIGN);
  Type *exp1Type = compileExpression();
  checkBasicType(exp1Type);

  eat(KW_TO);
  Type *exp2Type = compileExpression();
  checkBasicType(exp2Type);

  // Compare 3 types
  checkTypeEquality(var->varAttrs->type, exp1Type);
  checkTypeEquality(exp1Type, exp2Type);

  eat(KW_DO);
  compileStatement();
}