Ejemplo n.º 1
0
void Parser::match(Token tok) {
    if (tok != lookahead_) {
        std::stringstream ss;
        ss << "Unexpected token '" << tokenToString(lookahead_) << "', ";
        ss << "Expecting '" << tokenToString(tok) << "'";
        throw std::runtime_error(ss.str());
    }
    lookahead_ = scanner_.nextToken(attribute_, lineno_);
}
Ejemplo n.º 2
0
void dumpTokens(const QList<PreprocessorToken> &tokens)
{
    for (int ii = 0; ii < tokens.count(); ++ii) {
        if (tokens.at(ii).token == NEWLINE ||
           tokens.at(ii).token == STRING_START ||
           tokens.at(ii).token == STRING_END) {
            qWarning() << tokens.at(ii).line << ":" << tokens.at(ii).offset << tokenToString(tokens.at(ii).token);
        } else {
            QByteArray ba(tokens.at(ii).cStr, tokens.at(ii).cStrLen);
            qWarning() << tokens.at(ii).line << ":" << tokens.at(ii).offset << tokenToString(tokens.at(ii).token) << ba;
        }
    }
}
Ejemplo n.º 3
0
/**
 * helper function to check for a given token
 * if the pattern is found, true is returned,
 * otherwise an error text is printed to
 *  LOG_ERR and the function calls exit()
 * @param is      real value
 * @param shall   value expected
 */
void parserExpectToken(const enum eToken is,
                       const enum eToken shall )
{
    char  errtxt[64];
    if(shall != is)
    {
        sprintf(errtxt, "\"%s\" erwartet in Zeile %d, gefunden \"%s\"",
                tokenToString(shall),
                inLineNr,
                tokenToString(is));
        LOG_ERR(errtxt);
        exit(EXIT_FAILURE);
    }
}
Ejemplo n.º 4
0
static enum eToken stringToToken(const char * const pWord)
{
    enum eToken	token;

    for(token = tokNone; token < tokLast; token++)
    {
        if(!strcmp(pWord, tokenToString(token)))
        {
            /* token with this name was found	*/
            return token;
        }
    }
    return tokNone;
}
Ejemplo n.º 5
0
int main(int argc, char* argv[]) {
    if (argc == 2 && (strcmp(argv[1], "-s") == 0)) {
        Scanner scanner;
        while (scanner.nextToken() != T_EOF) {
            std::cout << tokenToString(scanner.nextToken()) << " ";
            scanner.eatToken(scanner.nextToken());
        }
        std::cout<<std::endl;
    } else if (argc == 2 && (strcmp(argv[1], "-e") == 0)) {
        Parser parser(true);
        parser.parse();
    } else {
        Parser parser(false);
        parser.parse();
    }
    return 0;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[]) {
  if(argc == 2 ){
    if(source = fopen(argv[1],"r"))  yyin = source;
    else  perror(argv[0]);
  }else{
    yyin = stdin;
  }
  int token;
  while ((token=yylex())!=ENDFILE) {
    if(token == ERROR){
      printf("Error found at line %d: %s\n", lineno, yytext);
    }else{
      printf("\'%s\' : \'%s\'\n", yytext, tokenToString(token));
    }
  }
  return(0);
}
Ejemplo n.º 7
0
std::string FlowLexer::tokenString() const
{
	switch (token()) {
		case FlowToken::Ident:
			return std::string("ident:") + stringValue_;
		case FlowToken::IP:
			return ipValue_.str();
		case FlowToken::RegExp:
			return "/" + stringValue_ + "/";
		case FlowToken::RawString:
		case FlowToken::String:
			return "string:'" + stringValue_ + "'";
		case FlowToken::Number: {
			char buf[64];
			snprintf(buf, sizeof(buf), "%lld", numberValue_);
			return buf;
		}
		case FlowToken::Boolean:
			return booleanValue() ? "true" : "false";
		default:
			return tokenToString(token());
	}
}
Ejemplo n.º 8
0
// Throw this error when the parser encounters a token that is not valid
// at the beginning of a specific grammar rule.
void parseError(int line, token found) {
    std::cerr << "Parse error: found invalid token " << tokenToString(found) << " at line " << line << std::endl;
    exit(1);
}
Ejemplo n.º 9
0
// Throw this error when the parser expects a given token from the scanner
// and the next token the scanner finds does not match.
void mismatchError(int line, token expected, token found) {
    std::cerr << "Parse error: expected " << tokenToString(expected) << " found " << tokenToString(found) << " at line " << line << std::endl;
    exit(1);
}
Ejemplo n.º 10
0
Archivo: error.c Proyecto: minh93/thctd
void missingToken(TokenType tokenType, int lineNo, int colNo) {
  printf("%d-%d:Missing %s\n", lineNo, colNo, tokenToString(tokenType));
  exit(0);
}