double evalNumber_pe (pathExpr *pe,VTDNav *vn){ double d = 0.0; exception e; int a = -1; int size; push2(vn); size = vn->contextBuf2->size; Try { a =evalNodeSet_pe(pe,vn); if (a!=-1){ if (getTokenType(vn,a)== TOKEN_ATTR_NAME){ a ++; }else if (getTokenType(vn,a)== TOKEN_STARTING_TAG) { a = getText(vn); } } } Catch (e){ } vn->contextBuf2->size = size; reset_pe(pe,vn); pop2(vn); Try{ if (a!=-1) return parseDouble(vn,a); }Catch (e){ } return 0/d; }
bool parserCls::factor(void) { EtokenType lTt1 = getTokenType();bool bb1 = true ; tokenContainCls lTc1 =getCurToken() ,lTc2;bool seeUnary= false; if( (lTt1 == Plus) || (lTt1==Minus) || (lTt1 == Not) ) { if(lTt1== Plus) lTc1.type = UnaryPlus; else if(lTt1== Minus) lTc1 . type = UnaryMinus; lTc2=lTc1;getToken();lTt1=getTokenType(); lTc1=getCurToken();seeUnary=true; } switch(lTt1){ case OrdNumber:case SciNumber:case Array : addOperand() ;exprFound = true ;needOperand = false ;getToken(); break ; case String : if(seeUnary) {errorUnary(lTc2 ,1);bb1 = false;break ;} addOperand();exprFound=true;needOperand=false ;getToken(); break ; case Name : exprFound = true ;needOperand=false;getToken(); if(getTokenType() == Lparen ) bb1=addFunction(lTc1); else addName(lTc1) ; break ; case Lparen :recursiveLparen() ;break ; case Rparen :if(seeUnary) {errorUnary(lTc2 , 2);bb1 = false ;break ;} break ; default :if(needOperand) errorFactor(); bb1 = false ; break ; } if(seeUnary && bb1) addOperator(lTc2); return bb1 ; }
UCSChar* evalString_pe (pathExpr *pe,VTDNav *vn){ exception e; int size = vn->contextBuf2->size ,a = -1; push2(vn); Try { a = evalNodeSet_pe(pe,vn); if (a != -1) { if (getTokenType(vn,a) == TOKEN_ATTR_NAME) { a++; } if (getTokenType(vn,a) == TOKEN_STARTING_TAG) { a = getText(vn); } } } Catch (e) { } vn->contextBuf2->size = size; reset_pe(pe,vn); pop2(vn); Try { if (a != -1) return toString(vn,a); } Catch (e) { if (e.et ==out_of_mem){ Throw e; } } return createEmptyString(); }
bool parserCls::term5(void) { bool s1 = term6();if(s1==false) return false ; EtokenType et1 = getTokenType();tokenContainCls t1 ; while( (et1== Mul )||(et1 == Div )|| (et1 == Mod)) { t1 =getCurToken();getToken();bool s2 = term6(); if(s2==false) return false ; addOperator(t1);et1 = getTokenType(); } return s1 ; }
bool parserCls::term6(void) { bool s1 = factor();if(s1==false) return false ; EtokenType et1 = getTokenType();tokenContainCls t1 ; if(et1== Pow) { t1 =getCurToken(); getToken(); bool s2 = factor(); if(s2==false) return false ; addOperator(t1); et1 = getTokenType(); } return s1 ; }
bool parserCls::term2(void) { bool s1 = term3();if(s1==false) return false ; EtokenType et1=getTokenType();tokenContainCls t1 ; if((et1==ExEq)||(et1==Ne)||(et1==Ge)||(et1==Le)|| (et1==Gt)||(et1==Lt)||(et1==Eq) ) { t1=getCurToken();getToken();bool s2 = term3(); if(s2==false) return false ; addOperator(t1);et1 = getTokenType(); } return s1 ; }
bool parserCls::term3(void) { bool s1 = term4();if(s1==false) return false ; EtokenType et1 = getTokenType();tokenContainCls t1 ; while( (et1== Concat ) ) { t1 =getCurToken();getToken();bool s2 = term4(); if(s2==false) return false ; addOperator(t1); et1 = getTokenType(); } return s1 ; }
bool parserCls::term1(void) { bool s1 = term2(); if(s1==false) return false ; EtokenType et1=getTokenType();tokenContainCls t1 ; while( (et1== And )||(et1 == Or )|| (et1 == ExOr)) { t1 =getCurToken();getToken();bool s2 = term2(); if(s2==false) return false ; addOperator(t1);et1 = getTokenType(); } return s1 ; }
// --------------------------------------------------------------------------- // RangeToken: Match methods // --------------------------------------------------------------------------- bool RangeToken::match(const XMLInt32 ch) { createMap(); bool ret; if (getTokenType() == T_RANGE) { if (ch < MAPSIZE) return ((fMap[ch/32] & (1<<(ch&0x1f))) != 0); ret = false; for (unsigned int i= fNonMapIndex; i< fElemCount; i +=2) { if (fRanges[i] <= ch && ch <= fRanges[i+1]) return true; } } else { if (ch < MAPSIZE) return ((fMap[ch/32] & (1<<(ch&0x1f))) == 0); ret = true; for (unsigned int i= fNonMapIndex; i< fElemCount; i += 2) { if (fRanges[i] <= ch && ch <= fRanges[i+1]) return false; } } return ret; }
bool parserCls::tokenInExpr(int ii1 ) { EtokenType t1 = getTokenType(); for(EtokenType *tte1 = ordList[ii1] ; *tte1 ; tte1++) if(t1 == *tte1) return true ; return false ; }
bool parserCls::factor(void) { EtokenType lTt1 = getTokenType(); bool bb1 = true ; tokenContainCls lTc1 =getCurToken(); switch(lTt1) { case OrdNumber: case SciNumber: case String : case Array : addOperand() ; exprFound = true ; needOperand = false ; noTokenInExpr++; getToken(); break ; case Name : exprFound = true ; needOperand = false ; noTokenInExpr++; getToken(); if(getTokenType() == Lparen ) addFunction(lTc1); else addName(lTc1) ; break ; case Lparen : addOperator() ; recursiveLparen() ; break ; case Rparen : break ; default : if(needOperand) errorFactor(); bb1 = false ; } return bb1 ; }
// --------------------------------------------------------------------------- // RangeToken: Getter methods // --------------------------------------------------------------------------- RangeToken* RangeToken::getCaseInsensitiveToken(TokenFactory* const tokFactory) { if (fCaseIToken == 0 && tokFactory) { bool isNRange = (getTokenType() == T_NRANGE) ? true : false; RangeToken* lwrToken = tokFactory->createRange(isNRange); for (unsigned int i = 0; i < fElemCount - 1; i += 2) { for (XMLInt32 ch = fRanges[i]; ch <= fRanges[i + 1]; ++ch) { #if defined(XML_USE_ICU_TRANSCODER) || defined (XML_USE_UNICONV390_TRANSCODER) const XMLInt32 upperCh = u_toupper(ch); if (upperCh != ch) { lwrToken->addRange(upperCh, upperCh); } const XMLInt32 lowerCh = u_tolower(ch); if (lowerCh != ch) { lwrToken->addRange(lowerCh, lowerCh); } const XMLInt32 titleCh = u_totitle(ch); if (titleCh != ch && titleCh != upperCh) { lwrToken->addRange(titleCh, titleCh); } #else if (ch >= chLatin_A && ch <= chLatin_Z) { ch += chLatin_a - chLatin_A; lwrToken->addRange(ch, ch); } else if (ch >= chLatin_a && ch <= chLatin_z) { ch -= chLatin_a - chLatin_A; lwrToken->addRange(ch, ch); } #endif } } lwrToken->mergeRanges(this); lwrToken->compactRanges(); lwrToken->createMap(); fCaseIToken = lwrToken; } return fCaseIToken; }
void parserCls::recursiveLparen(void) {tokenContainCls tc1=getCurToken();//save the Lparen token for error Reprot int curNoTok1 = noTokenInExpr; getToken();// get next token after ( if(term1() ) { EtokenType lt1= getTokenType(); if(lt1 != Rparen) errorRecursLparen(1, tc1); else if(noTokenInExpr-curNoTok1 == 0) errorRecursLparen(0, tc1); else getToken(); } }
/*---------------------------------------------------------------------*//** 定義種別を得る **//*---------------------------------------------------------------------*/ EsNameItNode::DefKind EsNameItNode::getDefKind() const { ASSERT(TFW_IS_FLAG(_defflag, DF_EXTYPE_DEFINE)); if(getTokenType() == TKN_FUNCTION) { return DK_FUNC; } if(getOpcodeType() == OP_NOP) { return DK_NULL; } if(getOpcodeType() == OP_GETARG) { return DK_ARG; } if(TFW_IS_FLAG(_defflag, DF_CONST)) { return DK_CONST; } if(TFW_IS_FLAG(_defflag, DF_LET)) { return DK_LET; } return DK_VAR; }
void CountCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { auto supergeheimeToken = node.getToken(); vector<string>& parameters = node.getContentArrayNonConstant(); shared_ptr<Variable> var = vm.getVariable(parameters[1]); if (var->getTokenType() != IToken::TYPE_FACT_ARRAY && var->getTokenType() != IToken::TYPE_NUMBER_ARRAY && var->getTokenType() != IToken::TYPE_TEXT_ARRAY) { throwCustomError("cannot count array " + var->getValue(), vm, supergeheimeToken); return; } shared_ptr<Array> array = vm.getVariableArray(parameters[1]); if (array != nullptr) { if (parameters.size() > 2) { auto var = vm.getVariable(parameters[2]); if (var->getTokenType() == IToken::TYPE_NUMBER && var->getType() == VariableType::number) { int index = atof(var->getValue().c_str()); if (index < 0) { throwCustomError("index is below zero.", vm, supergeheimeToken); } else if (index > (int)array->arraySizes.size() - 1) { throwCustomError("index out of bounds range.", vm, supergeheimeToken); } else { vm.setReturnValue(to_string(array->arraySizes.at(index))); vm.setReturnToken(IToken::TYPE_NUMBER); } } else { throwCustomError("input is not a number.", vm, supergeheimeToken); } } else { vm.setReturnValue(to_string(array->variableArrayDictionary.size())); vm.setReturnToken(IToken::TYPE_NUMBER); } } else { throwCustomError("array is not found.", vm, supergeheimeToken); } }
DataType getDataType(std::string data) { TokenType tt = getTokenType(data); if (tt == TT_NUMBER) return VT_NUMBER; if (tt == TT_STRING) return VT_STRING; if (tt == TT_BOOLEAN) return VT_BOOLEAN; unidentifiedData(data); return VT_UNDEFINED; }
void startSyntaxTree() { int temp = 0; openLexFile(); getNextToken(); while(!matchToken(PROGRAM)) { getNextToken(); } temp = lookupNumber(PROGRAM); addTokens(hand.root, getTokenName(temp), getTokenType(temp)); }
static int getStringVal(VTDNav *vn, int i){ int i1,t = getTokenType(vn,i); if (t == TOKEN_STARTING_TAG){ i1 = getText(vn); return i1; } else if (t == TOKEN_ATTR_NAME || t == TOKEN_ATTR_NS) return i+1; else return i; }
// expose and name of next procedure save in current procedure bool parserCls::getLabel(void) {bool bproc1 = false,bexpose1=false,bb2=true; nextProcSpecification.addName(getCurToken()); getToken();getToken(); if(getTokenType() == Procedure) {bproc1 = true ; getToken(); if(getTokenType()== Expose) {bexpose1=true; do{ getToken(); if((getTokenType()==Name)||(getTokenType()==Array)||(getTokenType()==Stem)) {nextProcSpecification.addListExpose(getCurToken());getToken();} else{bb2=false; errorGetLabel();} }while(getTokenType()==Comma); } } if(bb2) bb2=endWhiteLine(); if(bb2 && bproc1) if(bexpose1)nextProcSpecification.addProcType(ProcedureWithExposeType); else nextProcSpecification.addProcType(ProcedureType); else nextProcSpecification.addProcType(LabelType); return bb2; }
bool Token::isShorterThan(Token* const tok) { if (tok == 0) return false; if (getTokenType() != T_STRING && tok->getTokenType() != T_STRING) return false; //Should we throw an exception? int length = XMLString::stringLen(getString()); int tokLength = XMLString::stringLen(tok->getString()); return length < tokLength; }
void SkeletonParser::parseTokens(const std::vector<Token>& _tokenList){ TokenState currentState = start; Token currentToken = Token(); TokenType currentTokenType; while(currentState != end){ currentToken = getNextToken(); currentTokenType = getTokenType(currentToken); if(currentTokenType != endOfFile){ TokenState(SkeletonParser::*TokenFunc) (std::string&) = StateFunction[StateTable[currentTokenType][currentState]]; currentState = (this->*TokenFunc)(currentToken.str); } else return; } }
// --------------------------------------------------------------------------- // RangeToken: Getter methods // --------------------------------------------------------------------------- RangeToken* RangeToken::getCaseInsensitiveToken(TokenFactory* const tokFactory) { // REVIST // We will not build a token with case insenstive ranges // For now we will return a copy of ourselves. if (fCaseIToken == 0 && tokFactory) { bool isNRange = (getTokenType() == T_NRANGE) ? true : false; RangeToken* lwrToken = tokFactory->createRange(isNRange); lwrToken->mergeRanges(this); fCaseIToken = lwrToken; } return fCaseIToken; }
void QMapViewWidget::mouseReleaseEvent(QMouseEvent *event) { mouseMoveEvent(event); switch (pMode) { case 0: { if (pNewTokenType) { pMap[(int)pNewToken.y()][(int)pNewToken.x()] = pNewTokenType; pNewTokenType = 0; redrawMap(); update(); } } break; case 1: { if (pSelDir) { pNewTokenType = getTokenType(pMap[pSelToken.y()][pSelToken.x()]); pNewToken = pSelToken; pMap[pSelToken.y()][pSelToken.x()] = getDestType(pMap[pSelToken.y()][pSelToken.x()]); pSelToken = getEndPointOfMovement(pMap, pNewToken.toPoint(), pSelDir); QCustomVariantAnimator *animation = new QCustomVariantAnimator(); animation->setStartValue(pNewToken); animation->setEndValue(pSelToken); animation->setDuration(500); animation->setEasingCurve(QEasingCurve::InOutCubic); connect(animation, SIGNAL(valueChanged(const QVariant&)), this, SLOT(performAnimation(const QVariant&))); connect(animation, SIGNAL(finished()), this, SLOT(performAnimationFinished())); pIsAnimationRun = true; animation->start(QAbstractAnimation::DeleteWhenStopped); redrawMap(); } else { pNewTokenType = 0; } pSelDir = 0; update(); } break; default: break; }
int fillRedirectionOperands(char **input, char **output, int (*get_next_byte) (void *), void *get_next_byte_argument) { int len = 0; TOKENTYPE type = 0; while (1) { len = 0; type = getTokenType(get_next_byte(get_next_byte_argument)); switch (type) { case REDIRECTION1: type = readNextToken(input, &len, get_next_byte, get_next_byte_argument); if (!(*input) || !strlen(*input)) { goto err; } break; case REDIRECTION2: type = readNextToken(output, &len, get_next_byte, get_next_byte_argument); if (!(*output) || !strlen(*output)) { goto err; } break; default: _rewind(get_next_byte_argument, -1); goto out; } if (type == REDIRECTION2 || type == REDIRECTION1) { continue; } else { break; } } out: return type; err: printErr(); return -1; }
/// fa+b,c+d) /// f is the name of function // one error not checked f(a,,b) bool parserCls::addFunction(tokenContainCls &lTc1) { lTc1.type = FunctionName; addOperand(lTc1);bool bb2 = true ; bool bb3=false;EtokenType lt1;int iiExpr12=0,indexX=noTokenInExpr++; addOperand(lTc1); // for stack for change after end do{ if(bb3) addOperand(); else bb3 = true ; getToken();// get next token after ( if(!term1() ){ bb2 = false ;break ;} if((noTokenInExpr-2) > (indexX)) iiExpr12++; lt1= getTokenType(); }while((lt1==Comma)); if(bb2) if(lt1 != Rparen) {bb2 = false; errorRecursLparen(1, lTc1);} else {addOperator();getToken();} tokenContainCls lTc2(iiExpr12,1); addOperator(indexX, lTc2); return bb2 ; }
void MeshParser::parseTokens() { std::string currentToken; MeshParser::TokenType currentTokenType; while(tokens.size() != 0){ //get next token currentToken = getNextToken(); //detrmine token type currentTokenType = getTokenType(currentToken); //void (MeshParser::*TokenFunc) (std::string&) = StateFunction[currentTokenType]; //(this->*TokenFunc)(currentToken); switch(currentTokenType){ case positionsKeyword: gotPositionsToken(currentToken); break; case normalsKeyword: gotNormalsToken(currentToken); break; case skinWeightsKeyword: gotSkinWeightsToken(currentToken); break; case trianglesKeyword: gotTrianglesToken(currentToken); break; case bindingsKeyword: gotBindingsToken(currentToken); break; default: gotBadToken(currentToken); break; } } }
int checkRedirection(int (*get_next_byte) (void *), void *get_next_byte_argument) { char c; int flag = 0; while ((c = get_next_byte(get_next_byte_argument)) != EOF && c == ' ') { ; } switch (getTokenType(c)) { case REDIRECTION1: case REDIRECTION2: flag = 1; break; default: flag = 0; break; } _rewind(get_next_byte_argument, -1); return flag; }
int parse(FILE * fin) { char temp = getc(fin); char str[256]; str[0] = temp; int i = 0; while(temp != EOF) { str[i] = temp; printf("%c", temp); temp = getc(fin); i++; } //str[++i] = '\0'; int k = lookup(str); printf("The word has a value of %d\n", k); Strascii(str); trimString(str); k = lookup(str); k = getTokenType(k); printf("The word has a value of %d\n", k); return k; }
// --------------------------------------------------------------------------- // UnionToken: Children manipulation methods // --------------------------------------------------------------------------- void UnionToken::addChild(Token* const child, TokenFactory* const tokFactory) { if (child == 0) return; if (fChildren == 0) fChildren = new (tokFactory->getMemoryManager()) RefVectorOf<Token>(INITIALSIZE, false, tokFactory->getMemoryManager()); if (getTokenType() == T_UNION) { fChildren->addElement(child); return; } Token::tokType childType = child->getTokenType(); if (childType == T_CONCAT) { XMLSize_t childSize = child->size(); for (XMLSize_t i = 0; i < childSize; i++) { addChild(child->getChild(i), tokFactory); } return; } XMLSize_t childrenSize = fChildren->size(); if (childrenSize == 0) { fChildren->addElement(child); return; } Token* previousTok = fChildren->elementAt(childrenSize - 1); Token::tokType previousType = previousTok->getTokenType(); if (!((previousType == T_CHAR || previousType == T_STRING) && (childType == T_CHAR || childType == T_STRING))) { fChildren->addElement(child); return; } // Continue XMLBuffer stringBuf(1023, tokFactory->getMemoryManager()); if (previousType == T_CHAR) { XMLInt32 ch = previousTok->getChar(); if (ch >= 0x10000) { XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch, tokFactory->getMemoryManager()); stringBuf.append(chSurrogate); tokFactory->getMemoryManager()->deallocate(chSurrogate);//delete [] chSurrogate; } else { stringBuf.append((XMLCh) ch); } previousTok = tokFactory->createString(0); fChildren->setElementAt(previousTok, childrenSize - 1); } else { stringBuf.append(previousTok->getString()); } if (childType == T_CHAR) { XMLInt32 ch = child->getChar(); if (ch >= 0x10000) { XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch, tokFactory->getMemoryManager()); stringBuf.append(chSurrogate); tokFactory->getMemoryManager()->deallocate(chSurrogate);//delete [] chSurrogate; } else { stringBuf.append((XMLCh) ch); } } else { stringBuf.append(child->getString()); } ((StringToken*) previousTok)->setString(stringBuf.getRawBuffer()); }
bool LL1Parser::Parse() { bool retVal(true); string errorString; string test_2 = ""; char space = ' '; while ( _currentToken != _tokens.end() && retVal == true && _Done == false ) { list<Token> test; while (test.empty() != true) { test.pop_front(); } if (_ruleStack.top().getString() == _currentToken->getString() || _ruleStack.top().getTokenType() == _currentToken->getTokenType()) // might need an OR top of the stack TYPE is the same as current token TYPE { cout << "Matched a token: " << _currentToken->getString() << endl; //cout << "Matched a character: " << _currentToken->getString() << endl; if (_currentToken->getString() == "$") { _Done = true; } else { FetchNext(); _ruleStack.pop(); } } else if (_ruleStack.top().getString() == " ") { cout << "lambda at: " << _currentToken->getString() << endl; //FetchNext(); _ruleStack.pop(); } else { test = GetRule(_ruleStack.top().getString(), _currentToken->getString()); if (test.empty() != true) { _ruleStack.pop(); //push entire "test" token list onto rule stack in reverse order list<Token> List = test; List.reverse(); for (auto itr = List.begin(); itr != List.end(); ++itr) { Token Pushme(itr->getString(), itr->getTokenType()); _ruleStack.push(Pushme); //test_2 = itr->getString(); /* else { string s; s += *itr; Token s2(s, TokenType::UNDEFINED); _ruleStack.push(s2); cout << *itr << endl; } */ } } else { errorString += "Error when trying to find rule [ "; errorString += _ruleStack.top().getString(); errorString += " , "; errorString += _currentToken->getString(); errorString += " ]"; _errors.push_back(errorString); retVal = false; } } //if the rule matching was successful //_currentToken++; } return retVal; }