diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2018-09-05 21:26:47 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2018-09-05 21:26:47 +0200 |
commit | 050fc2ae7fc8b182825fe209081bae304f1cf9c5 (patch) | |
tree | d6ed2c248e2e0a8287b61ee70b75a688e409dcdc /minie | |
parent | 74a7a96124548a28d06116fcc96e9542041ea5ae (diff) | |
download | compilertests-050fc2ae7fc8b182825fe209081bae304f1cf9c5.tar.gz compilertests-050fc2ae7fc8b182825fe209081bae304f1cf9c5.tar.bz2 |
some temporary variable handling in right-hand side of expression
Diffstat (limited to 'minie')
-rw-r--r-- | minie/e2c.c | 33 | ||||
-rw-r--r-- | minie/test4.e | 6 |
2 files changed, 27 insertions, 12 deletions
diff --git a/minie/e2c.c b/minie/e2c.c index 88f9eb7..c155164 100644 --- a/minie/e2c.c +++ b/minie/e2c.c @@ -272,7 +272,7 @@ static void Expect( Symbol expect ) } } -static void emit( char *s, ... ) +static void emitLn( char *s, ... ) { va_list args; va_start( args, s ); @@ -281,9 +281,17 @@ static void emit( char *s, ... ) puts( "" ); } +static void emit( char *s, ... ) +{ + va_list args; + va_start( args, s ); + vprintf( s, args ); + va_end( args ); +} + static void prologue( void ) { - emit( "/* generated with e2c */" ); + emitLn( "/* generated with e2c */" ); } static void init( void ) @@ -298,9 +306,9 @@ static void init( void ) static void epilogue( void ) { - emit( "int main( void ) {" ); - emit( "module_%s_init( );", moduleName ); - emit( "}" ); + emitLn( "int main( void ) {" ); + emitLn( "module_%s_init( );", moduleName ); + emitLn( "}" ); } static void variableName( void ) @@ -315,6 +323,10 @@ static void variableName( void ) static void expression( void ) { if( sym == S_number ) { + emit( "%d;", num ); + sym = getSym( ); + } else if( sym == S_ident ) { + emit( "%s;", ident ); sym = getSym( ); } else { Abort( "Expected expression" ); @@ -331,8 +343,9 @@ static void statement( void ) v[MAX_IDENT_LEN-1] = '\0'; sym = getSym( ); Expect( S_assign ); + emit( "%s = ", v ); expression( ); - emit( "%s = %d;", v, num ); + emitLn( "" ); } static void statementBlock( void ) @@ -353,7 +366,7 @@ static void type( void ) if( sym == S_ident ) { /* TODO: handle build-in types in init, register them in type table */ - if( strcmp( ident, "INTEGER" ) == 0 ) { + if( strcmp( ident, "integer" ) == 0 ) { strcpy( typeName, "int" ); sym = getSym( ); } else { @@ -368,7 +381,7 @@ static void variableDeclaration( void ) sym = getSym( ); Expect( S_colon ); type( ); - emit( "static %s %s;", typeName, varName ); + emitLn( "static %s %s;", typeName, varName ); } static void declarationBlock( void ) @@ -398,9 +411,9 @@ static void module( void ) if( sym == S_var ) { declarationBlock( ); } - emit( "void module_%s_init( ) {", moduleName ); + emitLn( "void module_%s_init( ) {", moduleName ); statementBlock( ); - emit( "}" ); + emitLn( "}" ); } int main( void ) diff --git a/minie/test4.e b/minie/test4.e index 95eb1cb..18ba33b 100644 --- a/minie/test4.e +++ b/minie/test4.e @@ -1,10 +1,12 @@ module test4; var - x : INTEGER; - y : INTEGER; + x : integer; + y : integer; + z : integer; begin x := 7; y := 22; + z := x; end |