Ejemplo n.º 1
2
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();
    }
}
Ejemplo n.º 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 );
   }
 }
Ejemplo n.º 3
0
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;
        }
    }
}
Ejemplo n.º 4
0
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
        }
    }
}