diff options
Diffstat (limited to 'minie/e2c.c')
-rw-r--r-- | minie/e2c.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/minie/e2c.c b/minie/e2c.c index f5394e6..f9215be 100644 --- a/minie/e2c.c +++ b/minie/e2c.c @@ -52,6 +52,9 @@ typedef enum { S_minus, S_star, S_slash, + S_and, + S_or, + S_not, S_lparen, S_rparen, S_lbracket, @@ -92,6 +95,9 @@ char *symname[S_eof+1] = { "-", "*", "/", + "and", + "or", + "not", "(", ")", "[", @@ -115,7 +121,7 @@ static void Err( char *s, va_list args ) fflush( stderr ); } -static void Halt( ) +static void Halt( void ) { exit( EXIT_FAILURE ); } @@ -284,6 +290,8 @@ next: identifier( ); if( strcmp( ident, "array" ) == 0 ) { return S_array; + } else if( strcmp( ident, "and" ) == 0 ) { + return S_and; } return S_ident; case 'b': @@ -336,11 +344,16 @@ next: return S_ident; case 'n': identifier( ); + if( strcmp( ident, "not" ) == 0 ) { + return S_not; + } return S_ident; case 'o': identifier( ); if( strcmp( ident, "of" ) == 0 ) { return S_of; + } else if( strcmp( ident, "or" ) == 0 ) { + return S_or; } return S_ident; case 'p': @@ -544,7 +557,7 @@ static Type symbols[MAX_SYMBOLS]; static void insert_symbol( Type type, char *name ) { if( nof_symbols >= MAX_SYMBOLS ) { - Halt( "Symbol table exhausted, increase MAX_SYMBOLS and recompile e2c" ); + Abort( "Symbol table exhausted, increase MAX_SYMBOLS and recompile e2c" ); } symbols[nof_symbols] = type; @@ -719,6 +732,9 @@ static void factor( void ) } else if( sym == S_minus ) { sym = getSym( ); emit( "-" ); + } else if( sym == S_not ) { + sym = getSym( ); + emit( "!" ); } if( sym == S_number ) { emit( "%d", num ); @@ -764,9 +780,10 @@ static void factor( void ) static void term( void ) { factor( ); - while( sym == S_star || sym == S_slash ) { + while( sym == S_star || sym == S_slash || sym == S_and ) { if( sym == S_star ) emit( "*" ); if( sym == S_slash ) emit( "/" ); + if( sym == S_and ) emit( " && " ); sym = getSym( ); factor( ); } @@ -775,9 +792,10 @@ static void term( void ) static void simpleExpression( void ) { term( ); - while( sym == S_plus || sym == S_minus ) { + while( sym == S_plus || sym == S_minus || sym == S_or ) { if( sym == S_plus ) emit( "+" ); if( sym == S_minus ) emit( "-" ); + if( sym == S_or ) emit( " || " ); sym = getSym( ); term( ); } @@ -1115,7 +1133,7 @@ static void procedureDeclaration( void ) sym = getSym( ); do { if( nof_params >= MAX_PARAMETERS ) { - Halt( "Too many parameters in definition of procedure" ); + Abort( "Too many parameters in definition of procedure" ); } identifier( ); strncpy( params[nof_params].name, ident, MAX_IDENT_LEN ); @@ -1144,13 +1162,13 @@ static void procedureDeclaration( void ) } /* do not allow empty parameter lists in C++ style */ if( nof_params == 0 ) { - Halt( "Empty parameter list must not be enclosed with ( )" ); + Abort( "Empty parameter list must not be enclosed with ( )" ); } } else if( sym == S_semicolon ) { strncpy( return_type, "void", MAX_IDENT_LEN ); /* skip, ok */ } else { - Halt( "Expected '(' after procedure declaration" ); + Abort( "Expected '(' after procedure declaration" ); } Expect( S_semicolon ); emit( "%s %s( ", return_type, procName ); |