#include #include #include int c; void match( char t ) { if( c == t ) { c = getc( stdin ); } else { fprintf( stderr, "\nERR: expecting '%c', but got '%c'\n", t, c ); exit( 1 ); } } void term( void ) { if( isdigit( c ) ) { int t = c; match( c ); putchar( t ); } else { fprintf( stderr, "\nERR: expecting digit, but got '%c'\n", c ); exit( 1 ); } } void rest( void ) { if( c == '+' ) { match( '+' ); term( ); putchar( '+' ); rest( ); } else if( c == '-' ) { match( '-' ); term( ); putchar( '-' ); rest( ); } } void expr( void ) { term( ); rest( ); } int main( void ) { c = getc( stdin ); expr( ); if( ( c = getc( stdin ) ) != EOF ) { fprintf( stderr, "\nERR: superfluos input found\n" ); exit( 1 ); } puts( "" ); exit( 0 ); }