/* main * * do some main stuff. */ int main( int argc, char ** argv ) { basic_program * bp; basic_line * bl; printf( "0\n" ); /* set up our program space */ bp = newProgram(); if( !bp ) { errorReport( kErrorMalloc, 1 ); return 0; } /* display version info */ cmd_info( bp, NULL ); bl = consumeString( bp, program[0] ); bl = consumeString( bp, program[1] ); bl = consumeString( bp, program[2] ); bl = consumeString( bp, program[3] ); bl = consumeString( bp, program[4] ); /* and run the program, if we should... */ printf( "Running program\n" ); runProgram( bp, 0 ); while( run_poll( bp ) ); /* just show access of variables */ printf( "Variable 'a' is %ld\n", getVariableNumber( bp->variables, "a" )); deleteProgram( bp ); return 0; }
xml::token Lexer::nextToken() { while (skipWhitespace() || skipComments()) { } if (buffer_empty()) { buffer_put(m_input->get()); } switch (buffer_peek()) { case '<': m_token = token::chevron_left; buffer_pop(); break; case '>': m_token = token::chevron_right; buffer_pop(); break; case '?': m_token = token::questionMark; buffer_pop(); break; case '=': m_token = token::assignment; buffer_pop(); break; case '/': m_token = token::slash; buffer_pop(); break; case '"': case '\'': consumeString(); break; case EOF: /* * TODO: Replace EOF with std::char_traits<char>::eof() once VS * will learn what "constexpr" is. */ m_token = token::eof; buffer_pop(); break; default: consumeIdentifier(); break; } return m_token; }
//11 int CSSParser::parseHexPair(){ #ifdef CSS_DEBUG qDebug() << Q_FUNC_INFO; #endif /* CSS_DEBUG */ QString doubledigit = consumeString(2); bool isdigit; int hexpair = doubledigit.toInt(&isdigit, 10); if( isdigit ){ return hexpair; } else { qDebug() << "not a valid double digit" << doubledigit; return -1; } }
void LexBase::nextToken(LexToken &token) { StringBuffer spelling; bool found; short funcType; short symbol; //-------- // Skip leading white space //-------- while (m_ch.isSpace()) { nextChar(); } //-------- // Check for EOF. //-------- if (m_atEOF) { if (m_sourceType == Configuration::INPUT_STRING) { token.reset(LEX_EOF_SYM, m_lineNum, "<end of string>"); } else { token.reset(LEX_EOF_SYM, m_lineNum, "<end of file>"); } return; } //-------- // Note the line number at the start of the token //-------- const int lineNum = m_lineNum; //-------- // Miscellaneous kinds of tokens. //-------- switch (m_ch.c_str()[0]) { case '?': nextChar(); if (m_ch == '=') { nextChar(); token.reset(LEX_QUESTION_EQUALS_SYM, lineNum, "?="); } else { token.reset(LEX_UNKNOWN_SYM, lineNum, spelling.c_str()); } return; case '!': nextChar(); if (m_ch == '=') { nextChar(); token.reset(LEX_NOT_EQUALS_SYM, lineNum, "!="); } else { token.reset(LEX_NOT_SYM, lineNum, "!"); } return; case '@': spelling.append(m_ch.c_str()); nextChar(); while (!m_atEOF && isKeywordChar(m_ch)) { spelling.append(m_ch.c_str()); nextChar(); } searchForKeyword(spelling.c_str(), found, symbol); if (found) { token.reset(symbol, lineNum, spelling.c_str()); } else { token.reset(LEX_UNKNOWN_SYM, lineNum, spelling.c_str()); } return; case '+': nextChar(); token.reset(LEX_PLUS_SYM, lineNum, "+"); return; case '&': nextChar(); if (m_ch == '&') { nextChar(); token.reset(LEX_AND_SYM, lineNum, "&&"); } else { spelling << '&' << m_ch.c_str(); token.reset(LEX_UNKNOWN_SYM, lineNum, spelling.c_str()); } return; case '|': nextChar(); if (m_ch == '|') { nextChar(); token.reset(LEX_OR_SYM, lineNum, "||"); } else { spelling << '|' << m_ch.c_str(); token.reset(LEX_UNKNOWN_SYM, lineNum, spelling.c_str()); } return; case '=': nextChar(); if (m_ch == '=') { nextChar(); token.reset(LEX_EQUALS_EQUALS_SYM, lineNum, "=="); } else { token.reset(LEX_EQUALS_SYM, lineNum, "="); } return; case ';': nextChar(); token.reset(LEX_SEMICOLON_SYM, lineNum, ";"); return; case '[': nextChar(); token.reset(LEX_OPEN_BRACKET_SYM, lineNum, "["); return; case ']': nextChar(); token.reset(LEX_CLOSE_BRACKET_SYM, lineNum, "]"); return; case '{': nextChar(); token.reset(LEX_OPEN_BRACE_SYM, lineNum, "{"); return; case '}': nextChar(); token.reset(LEX_CLOSE_BRACE_SYM, lineNum, "}"); return; case '(': nextChar(); token.reset(LEX_OPEN_PAREN_SYM, lineNum, "("); return; case ')': nextChar(); token.reset(LEX_CLOSE_PAREN_SYM, lineNum, ")"); return; case ',': nextChar(); token.reset(LEX_COMMA_SYM, lineNum, ","); return; case '"': consumeString(token); return;; case '<': nextChar(); if (m_ch != '%') { token.reset(LEX_UNKNOWN_SYM, lineNum, "<"); return; } nextChar(); // skip over '%' consumeBlockString(token); return; case '#': //-------- // A comment. Consume it and immediately following // comments (without resorting to recursion). //-------- while (m_ch == '#') { //-------- // Skip to the end of line //-------- while (!m_atEOF && m_ch != '\n') { nextChar(); } if (m_ch == '\n') { nextChar(); } //-------- // Skip leading white space on the next line //-------- while (m_ch.isSpace()) { nextChar(); } //-------- // Potentially loop around again to consume // more comment lines that follow immediately. //-------- } //-------- // Now use (a guaranteed single level of) recursion // to obtain the next (non-comment) token. //-------- nextToken(token); return; } //-------- // Is it a function or identifier? //-------- if (isIdentifierChar(m_ch)) { //-------- // Consume all the identifier characters // but not an immediately following "(", if any //-------- spelling.append(m_ch.c_str()); nextChar(); while (!m_atEOF && isIdentifierChar(m_ch)) { spelling.append(m_ch.c_str()); nextChar(); } //-------- // If "(" follows immediately then it is (supposed to be) // a function. //-------- if (m_ch == '(') { spelling.append(m_ch.c_str()); nextChar(); searchForFunction(spelling.c_str(), found, funcType, symbol); if (found) { token.reset(symbol, lineNum, spelling.c_str(), funcType); } else { token.reset(LEX_UNKNOWN_FUNC_SYM, lineNum, spelling.c_str()); } return; } //-------- // It's not a function so it looks like an identifier. // Better check it's a legal identifier. //-------- if (strcmp(spelling.c_str(), ".") == 0) { token.reset(LEX_SOLE_DOT_IDENT_SYM, lineNum, spelling.c_str()); } else if (strstr(spelling.c_str(), "..") != 0) { token.reset(LEX_TWO_DOTS_IDENT_SYM, lineNum, spelling.c_str()); } else { try { m_uidIdentifierProcessor->expand(spelling); token.resetWithOwnership(LEX_IDENT_SYM, lineNum, spelling); } catch (const ConfigurationException &) { token.resetWithOwnership(LEX_ILLEGAL_IDENT_SYM, lineNum, spelling); } } return; } //-------- // None of the above //-------- spelling << m_ch.c_str(); nextChar(); token.reset(LEX_UNKNOWN_SYM, lineNum, spelling.c_str()); }
void Tokenizer::shift() { mpCurrent.reset(); if (mBlockComment) { skipEOL(); } else { skipWhiteSpaces(); if (mpInput->eof()) return; } mpCurrent.reset(new Token); mpCurrent->setLine(line()); mpCurrent->setBeginColumn(column()); if (mBlockComment) { consumeCStyleBlockComment(); return; } auto ch = mpInput->get(); if (isLetter(ch) || isUnderscore(ch)) { consumeIdentifier(ch); } else if (isBiwiseOperatorSymbol(ch)) { mpCurrent->setType(Token::TYPE_BITWISE_OPERATOR); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isDot(ch) && consumeDot(ch)) { // nothing } else if ((isDecimalDigit(ch) || isDot(ch) || isSign(ch)) && consumeNumber(ch)) { // nothing } else if (isQuotationMark(ch)) { if (!consumeString(ch)) shift(); } else if (isCStyleInitialCommentChar(ch)) { consumeComment(ch); } else if (isArrowSymbol(ch) && consumeArrow(ch)) { // nothing } else if (isBracket(ch)) { mpCurrent->setType(Token::TYPE_BRACKET); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isAngleBracket(ch)) { mpCurrent->setType(Token::TYPE_ANGLE_BRACKET); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isDelimiter(ch)) { mpCurrent->setType(Token::TYPE_DELIMITER); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isOperator(ch) && consumeEqualOperator(ch)) { // nothing } else if (isOperator(ch)) { mpCurrent->setType(Token::TYPE_OPERATOR); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else if (isAsterisk(ch)) { mpCurrent->setType(Token::TYPE_ASTERISK); absorbed(ch); mpCurrent->addChar(ch); mpCurrent->setEndColumn(column()); } else { mpCurrent.reset(); } }
string IOBuffer::consumeStringWithSizeLE() { rx_uint16 num_bytes_in_string = consumeUI16LE(); return consumeString(num_bytes_in_string); }