示例#1
0
// Print error message for unbalanced symbols.
int Balance::checkBalance( )
{
    char ch;
    Symbol lastSymbol, match;
    stack<Symbol, vector<Symbol> > pendingTokens;  // Open symbols pending

    while( ( ch = tok.getNextOpenClose( ) ) != '\0' )
    {
        lastSymbol.token = ch;
        lastSymbol.theLine = tok.getLineNumber( );

        switch( ch )
        {
        case '(':
        case '[':
        case '{':
            pendingTokens.push( lastSymbol );
            break;

        case ')':
        case ']':
        case '}':
            if( pendingTokens.empty( ) )
            {
                cout << "Extraneous " << ch << " at line " << tok.getLineNumber( ) << endl;
                errors++;
            }
            else
            {
                match = pendingTokens.top( );
                pendingTokens.pop( );
                checkMatch( match, lastSymbol );
            }
            break;

        default: // Can't happen
            break;
        }
    }

    while( !pendingTokens.empty( ) )
    {
        match = pendingTokens.top( );
        pendingTokens.pop( );
        cout << "Unmatched " << match.token << " at line "
             << match.theLine << endl;
        errors++;
    }

    return errors + tok.getErrorCount( );
}
示例#2
0
status_t KeyCharacterMap::load(const String8& filename, KeyCharacterMap** outMap) {
    *outMap = NULL;

    Tokenizer* tokenizer;
    status_t status = Tokenizer::open(filename, &tokenizer);
    if (status) {
        LOGE("Error %d opening key character map file %s.", status, filename.string());
    } else {
        KeyCharacterMap* map = new KeyCharacterMap();
        if (!map) {
            LOGE("Error allocating key character map.");
            status = NO_MEMORY;
        } else {
#if DEBUG_PARSER_PERFORMANCE
            nsecs_t startTime = systemTime(SYSTEM_TIME_MONOTONIC);
#endif
            Parser parser(map, tokenizer);
            status = parser.parse();
#if DEBUG_PARSER_PERFORMANCE
            nsecs_t elapsedTime = systemTime(SYSTEM_TIME_MONOTONIC) - startTime;
            LOGD("Parsed key character map file '%s' %d lines in %0.3fms.",
                    tokenizer->getFilename().string(), tokenizer->getLineNumber(),
                    elapsedTime / 1000000.0);
#endif
            if (status) {
                delete map;
            } else {
                *outMap = map;
            }
        }
        delete tokenizer;
    }
    return status;
}
示例#3
0
// Print an error message if clSym does not match opSym.
// Update errors.
void Balance::checkMatch( const Symbol & opSym, const Symbol & clSym )
{
    if( opSym.token == '(' && clSym.token != ')' ||
            opSym.token == '[' && clSym.token != ']' ||
            opSym.token == '{' && clSym.token != '}' )
    {
        cout << "Found " << clSym.token << " on line " <<
             tok.getLineNumber( ) << "; does not match " << opSym.token
             << " at line " << opSym.theLine << endl;
        errors++;
    }
}
示例#4
0
static void errorMessagePrelude(const Tokenizer& tok)
{
    cerr << _("Error in .ssc file (line ") << tok.getLineNumber() << "): ";
}