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); }
void CompilationEng::compileExpressionList() { printNonterminal("expressionList"); numOfTab++; compileExpression(); while(true) { getToken(); if(m_token == ",") { printCurrentToken(false); compileExpression(); } else if(m_token == ")") { m_bPutback = true; break; } else { m_ofs << m_token << endl; break; } } numOfTab--; printNonterminal("expressionList",false); }
void CompilationEngine::compileLet() { /*'let' varName('[' expression ']')? '=' expression ';' */ tagNonTerminal("letStatement"); readKeyword("let", Keyword::kLET); nextToken(); readIdentifier(); nextToken(); if (jt.tokenType() == TokenType::kSYMBOL && jt.symbol() == '[') { readSymbol('['); nextToken(); compileExpression(); readSymbol(']'); nextToken(); } readSymbol('='); nextToken(); compileExpression(); readSymbol(';'); untagNonTerminal("letStatement"); nextToken(); }
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); }
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(); }
void compileForSt(void) { eat(KW_FOR); eat(TK_IDENT); eat(SB_ASSIGN); compileExpression(); eat(KW_TO); compileExpression(); eat(KW_DO); compileStatement(); }
void compileForSt(void) { assert("Parsing a for statement ...."); eat(KW_FOR); eat(TK_IDENT); eat(SB_ASSIGN); compileExpression(); eat(KW_TO); compileExpression(); eat(KW_DO); compileStatement(); assert("For statement parsed ...."); }
Value* IRCompiler::compileAddition(KT_Addition *add) { debug("compiling a KT_Addition"); Value* vl = compileExpression(add->getLExpression()); Value* vg = compileExpression(add->getRExpression()); vl = BasicInstructionGenerator::stripVal(vl, getCurrentBlock()); vg = BasicInstructionGenerator::stripVal(vg, getCurrentBlock()); Type *t = PrimitiveValueConverter::dominatingType(vl->getType(), vg->getType()); return PrimitiveBinaryOperationGenerator::createAdd(getModule(), t, vl, vg, getCurrentBlock()); }
void compileForSt(void) { eat(KW_FOR); eat(TK_IDENT); // TODO: check if the identifier is a variable eat(SB_ASSIGN); compileExpression(); eat(KW_TO); compileExpression(); eat(KW_DO); compileStatement(); }
void CompilationEngine::compileIf() { /* 'if' '(' expression ')' '{' statements '}' ('else' '{' statements '}')? */ tagNonTerminal("ifStatement"); readKeyword("if", Keyword::kIF); nextToken(); readSymbol('('); nextToken(); compileExpression(); readSymbol(')'); nextToken(); readSymbol('{'); nextToken(); compileStatements(); readSymbol('}'); nextToken(); if (jt.tokenType() == TokenType::kKEYWORD && jt.keyword() == Keyword::kELSE) { readKeyword("else", Keyword::kELSE); nextToken(); readSymbol('{'); nextToken(); compileStatements(); readSymbol('}'); nextToken(); } untagNonTerminal("ifStatement"); }
void CompilationEng::compileIf() { printNonterminal("ifStatement"); numOfTab++; printCurrentToken(false); //<keyword> if </keyword> printCurrentToken(); //<symbol> ( </symbol> compileExpression(); printCurrentToken(); //<symbol> ) </symbol> printCurrentToken(); //<symbol> { </symbol> m_bZeroStatements=true; compileStatements(); printCurrentToken(); //<symbol> } </symbol> //else part getToken(); if(m_token == "else") { printCurrentToken(false); //<keyword> else </keyword> printCurrentToken(); //<symbol> { </symbol> m_bZeroStatements=true; compileStatements(); printCurrentToken(); //<symbol> } </symbol> } else { m_bPutback = true; } numOfTab--; printNonterminal("ifStatement",false); }
Type* compileIndexes(Type* arrayType) { // parse a sequence of indexes, check the consistency to the arrayType, and return the element type Type *idxType = NULL; Type *elmType = NULL; while (lookAhead->tokenType == SB_LSEL) { eat(SB_LSEL); // if current element is not of array type, // then the access to the next dimension is invalid checkArrayType(arrayType); idxType = compileExpression(); checkIntType(idxType); eat(SB_RSEL); // Down 1 level of dimension arrayType = arrayType->elementType; } // arrayType becomes elmType when we traverse to the last dimension elmType = arrayType; return elmType; }
void compileCondition2(void) { // TODO 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_INVALIDCOMPARATOR, lookAhead->lineNo, lookAhead->colNo); } compileExpression(); }
void compileArguments(void) { // TODO switch (lookAhead->tokenType) { case SB_LPAR: eat(SB_LPAR); compileExpression(); compileArguments2(); eat(SB_RPAR); break; case KW_END: case SB_SEMICOLON: case KW_ELSE: case SB_TIMES: case SB_SLASH: case SB_MOD: case SB_PLUS: case SB_MINUS: case SB_EQ: case SB_NEQ: case SB_LE: case SB_LT: case SB_GE: case SB_GT: case KW_DO: case KW_TO: case KW_THEN: case SB_RPAR: case SB_RSEL: case SB_COMMA: break; default: error(ERR_INVALIDARGUMENTS, lookAhead->lineNo, lookAhead->colNo); break; } }
void compileIndexes(void) { while (lookAhead->tokenType == SB_LSEL) { eat(SB_LSEL); compileExpression(); eat(SB_RSEL); } }
void compileForSt(void) { eat(KW_FOR); eat(TK_IDENT); // TODO: check if the identifier is a variable checkDeclaredVariable(currentToken->string); eat(SB_ASSIGN); compileExpression(); eat(KW_TO); compileExpression(); eat(KW_DO); compileStatement(); }
void EditScriptDialog::compileAndSetResult(const QString& script) { QString ret = compileExpression(script); _imp->resultEdit->setPlainText(ret); }
bool CMathObject::compileParticleFlux(CMathContainer & container) { bool success = true; // The default value is NaN *mpValue = InvalidValue; // Reset the prerequisites mPrerequisites.clear(); const CReaction * pReaction = static_cast< const CReaction * >(mpDataObject->getObjectParent()); // We need to check whether this reaction is a single compartment reaction and scale // it if true. // mParticleFlux = *mUnitScalingFactor * mFlux; // mUnitScalingFactor = & pModel->getQuantity2NumberFactor(); std::ostringstream Infix; Infix.imbue(std::locale::classic()); Infix.precision(16); Infix << container.getModel().getQuantity2NumberFactor(); Infix << "*"; Infix << pointerToString(container.getMathObject(pReaction->getFluxReference())->getValuePointer()); CExpression E("ParticleFluxExpression", &container); success &= E.setInfix(Infix.str()); pdelete(mpExpression); mpExpression = new CMathExpression(E, container, !mIsInitialValue); compileExpression(); return success; }
bool CMathObject::createExtensiveODERateExpression(const CMetab * pSpecies, CMathContainer & container) { bool success = true; std::ostringstream Infix; Infix.imbue(std::locale::classic()); Infix.precision(16); /* mRate = mpModel->getQuantity2NumberFactor() * mpCompartment->getValue() * mpExpression->calcValue(); */ if (!pSpecies->getExpression().empty()) { Infix << container.getModel().getQuantity2NumberFactor(); Infix << "*"; Infix << pointerToString(container.getMathObject(pSpecies->getCompartment()->getValueReference())->getValuePointer()); Infix << "*("; Infix << pSpecies->getExpression(); Infix << ")"; } CExpression E("ExtensiveODERateExpression", &container); success &= E.setInfix(Infix.str()); pdelete(mpExpression); mpExpression = new CMathExpression(E, container, !mIsInitialValue); compileExpression(); return success; }
void compileFactor(void) { // TODO Token *tmp=lookAhead; //de chuyen tiep lookAhead o duoi switch(tmp->tokenType) { case TK_NUMBER: case TK_CHAR: compileUnsignedConstant(); break; case SB_LPAR: eat(SB_LPAR); compileExpression(); eat(SB_RPAR); break; case TK_IDENT: eat(TK_IDENT); if(lookAhead->tokenType==SB_LPAR) { compileArguments(); } else if(lookAhead->tokenType==SB_LSEL) { compileIndexes(); } //else //compileUnsignedConstant(); break; default: error(ERR_INVALIDFACTOR, lookAhead->lineNo, lookAhead->colNo); break; } //free(tmp); }
void compileFactor(void) { // TODO switch (lookAhead->tokenType) { case TK_NUMBER: eat(TK_NUMBER); break; case TK_IDENT: eat(TK_IDENT); compileIndexes(); compileArguments(); break; case TK_STRING: eat(TK_STRING); break; case TK_CHAR: eat(TK_CHAR); break; case SB_LPAR: compileExpression(); eat(SB_RPAR); break; default: error(ERR_INVALIDFACTOR, lookAhead->lineNo, lookAhead->colNo); break; } }
Type* compileIndexes(Type* arrayType) { // TODO: parse a sequence of indexes, check the consistency to the arrayType, and return the element type while (lookAhead->tokenType == SB_LSEL) { eat(SB_LSEL); compileExpression(); eat(SB_RSEL); } }
void compileForSt(void) { eat(KW_FOR); eat(TK_IDENT); // check if the identifier is a variable if (checkDeclaredVariable(currentToken->string) == NULL) error(ERR_UNDECLARED_VARIABLE, currentToken->lineNo, currentToken->colNo); eat(SB_ASSIGN); compileExpression(); eat(KW_TO); compileExpression(); eat(KW_DO); compileStatement(); }
void CompilationEngine::compileExpressionList() { // (expression(',' expression)*)? tagNonTerminal("expressionList"); if (jt.tokenType() != TokenType::kSYMBOL || (jt.symbol() == '(' )) compileExpression(); while (jt.tokenType() == TokenType::kSYMBOL && jt.symbol() == ',') { readSymbol(','); nextToken(); compileExpression(); } untagNonTerminal("expressionList"); }
void compileAssignSt(void) { assert("Parsing an assign statement ...."); // TODO eat(TK_IDENT); compileIndexes(); eat(SB_ASSIGN); compileExpression(); assert("Assign statement parsed ...."); }
void compileArguments(void) { while(lookAhead->tokenType == SB_LPAR){ eat(SB_LPAR); compileExpression(); compileArguments2(); eat(SB_RPAR); } }
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); }
bool CMathObject::compileDependentMass(CMathContainer & container) { bool success = true; // The default value is NaN *mpValue = InvalidValue; // Reset the prerequisites mPrerequisites.clear(); const CMoiety * pMoiety = static_cast< const CMoiety *>(mpDataObject->getObjectParent()); std::ostringstream Infix; Infix.imbue(std::locale::classic()); Infix.precision(16); Infix << pointerToString(container.getMathObject(pMoiety->getTotalNumberReference())->getValuePointer()); std::vector< std::pair< C_FLOAT64, CMetab * > >::const_iterator it = pMoiety->getEquation().begin(); std::vector< std::pair< C_FLOAT64, CMetab * > >::const_iterator end = pMoiety->getEquation().end(); bool First = true; // The first element in the equation is always the dependent species. We can directly update // its value and therefore point mpValue to it. mpValue = (C_FLOAT64 *) container.getMathObject(it->second->getValueReference())->getValuePointer(); ++it; for (; it != end; ++it) { const C_FLOAT64 & Multiplicity = it->first; if (First || Multiplicity >= 0.0) { Infix << "-" << Multiplicity; } else { Infix << "+" << fabs(Multiplicity); } First = false; Infix << "*"; Infix << pointerToString(container.getMathObject(it->second->getValueReference())->getValuePointer()); } CExpression E("DependentMass", &container); success &= E.setInfix(Infix.str()); pdelete(mpExpression); mpExpression = new CMathExpression(E, container, !mIsInitialValue); compileExpression(); return success; }
void compileArguments2(void) { // TODO if(lookAhead->tokenType==SB_COMMA) { eat(SB_COMMA); compileExpression(); compileArguments2(); } }
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); }