コード例 #1
2
ファイル: inTopostfix.cpp プロジェクト: iamOgunyinka/MyCC
void factor( std::istringstream &ss, char &lookahead ) {
    if ( isDigit {}( lookahead ) ){
        int value = 0;
        do {
            value = value * 10 + ToDigit {}( lookahead );
            lookahead = ss.get();
        } while ( !ss.eof() && isDigit {} ( lookahead ) );
        print ( value );
    } else if ( lookahead == '(' ) {
        match ( ss, lookahead, '(' );
        expr( ss, lookahead );
        if( lookahead != ')' ){
            throw fail { "Expected a closing parenthesis before end of line." };
        }
        match ( ss, lookahead, ')' );
    } else if ( isWhiteSpace {} ( lookahead ) ) {
        for (;; lookahead = ss.get() ){
            if( isWhiteSpace {}( lookahead ) ) continue;
            else break;
        }
    } else {
        std::cerr << "Syntax Error: expecting a digit, got '" << lookahead << "' instead." << std::endl;
        abort();
    }
}
コード例 #2
0
 void convert( unsigned int count, std::istringstream& inputStream, T * value )
 {
   DP_ASSERT( count );
   for ( unsigned int i=0 ; i<count ; i++ )
   {
     DP_ASSERT( !inputStream.eof() && !inputStream.bad() );
     value[i] = convert<T>( inputStream );
   }
 }
コード例 #3
0
ファイル: inTopostfix.cpp プロジェクト: iamOgunyinka/MyCC
void rest_2( std::istringstream &ss, char &lookahead )
{
    while( !ss.eof() ){
        char tempToken = lookahead;
        if( lookahead == '*' ) {
            match( ss, lookahead, '*' );
            factor( ss, lookahead );
            print( tempToken );
        } else if ( lookahead == '/' ) {
            match ( ss, lookahead, '/' );
            factor( ss, lookahead );
            print( '/' );
        } else if ( isWhiteSpace {}( lookahead ) ) {
            for(;; lookahead = ss.get() ){
                if( isWhiteSpace {}( lookahead ) ) continue;
                else break;
            }
        } else {
            break;
        }
    }
}
コード例 #4
0
ファイル: inTopostfix.cpp プロジェクト: iamOgunyinka/MyCC
void rest( std::istringstream &ss, char &lookahead )
{
    while( !ss.eof() ) {
        char tempToken = lookahead;
        if ( lookahead == '+' ) {
            match( ss, lookahead, '+' );
            term ( ss, lookahead );
            print( tempToken );
            rest( ss, lookahead );
        } else if ( lookahead == '-' ) {
            match( ss, lookahead, '-' );
            term( ss, lookahead );
            print( tempToken );
            rest( ss, lookahead );
        } else if ( isWhiteSpace {} ( lookahead ) ) {
            for(;; lookahead = ss.get() ){
                if( isWhiteSpace {}( lookahead ) ) continue;
                else break;
            }
        } else {
            break; //we have an epsilon production
        }
    }
}