Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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();
}
Exemplo n.º 5
0
Type* compileIndexes(Type* arrayType) {
  // TODO: parse a sequence of indexes, check the consistency to the arrayType, and return the element type
  Type* type;
  while (lookAhead->tokenType == SB_LSEL) {
    eat(SB_LSEL);
    type = compileExpression();
    checkIntType(type);
    checkArrayType(arrayType);

    arrayType = arrayType->elementType;
    eat(SB_RSEL);
  }
  checkBasicType(arrayType);
  return arrayType;
}
Exemplo n.º 6
0
Type* compileIndexes(Type* arrayType) {
  Type* type;

  
  while (lookAhead->tokenType == SB_LSEL) {
    eat(SB_LSEL);
    type = compileExpression();
    checkIntType(type);
    checkArrayType(arrayType);

    arrayType = arrayType->elementType;
    eat(SB_RSEL);
  }
  checkBasicType(arrayType);
  return arrayType;
}
Exemplo n.º 7
0
Type* compileIndexes(Type* arrayType) {
  // TODO: Generate code for computing array element address
  Type* type;

  
  while (lookAhead->tokenType == SB_LSEL) {
    eat(SB_LSEL);
    type = compileExpression();
    checkIntType(type);
    checkArrayType(arrayType);

    arrayType = arrayType->elementType;
    eat(SB_RSEL);
  }
  checkBasicType(arrayType);
  return arrayType;
}