diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2019-02-14 21:12:16 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2019-02-14 21:12:16 +0100 |
commit | 638b7de7d7fb19b756a2f2bc266222b74b4e7295 (patch) | |
tree | ad666652e6929cffcc5ad5e2bcb92c540d263298 /minie | |
parent | d084f5980e5e51c9df239b4cc76905e13a3bf5fa (diff) | |
download | compilertests-638b7de7d7fb19b756a2f2bc266222b74b4e7295.tar.gz compilertests-638b7de7d7fb19b756a2f2bc266222b74b4e7295.tar.bz2 |
some more work on parser in ec.e
Diffstat (limited to 'minie')
-rw-r--r-- | minie/TODOS | 10 | ||||
-rwxr-xr-x | minie/build.sh | 3 | ||||
-rw-r--r-- | minie/e2c.c | 35 | ||||
-rw-r--r-- | minie/ec.e | 42 |
4 files changed, 63 insertions, 27 deletions
diff --git a/minie/TODOS b/minie/TODOS index d2ccd26..4c1d2f0 100644 --- a/minie/TODOS +++ b/minie/TODOS @@ -157,7 +157,7 @@ to be adapted and the compiler has to be recompiled. But the benefits are that you are not using any dynamic memory allocation which can go wrong in some ways. -procedure/function declarations and calls +procedure/function declarations: Pascalish: procedure f : char; @@ -168,11 +168,19 @@ procedure f( ) : char; procedure f( ); => matter of definition of ParameterList in ProcedureDeclaration +function getChar : char; +procedure getChar : char; +=> doesn't add anything to help parsing +=> pascal/oberon calls it function procedures +=> had some weird discussions telling me functions are not procedures.. + procedure f( var a : integer ); function sin( x : float ) : float; => function seems more mathematical, but otherwise we don't gain anything to have a keyword more for detecting anything we couldn't detect already +using/calling: + procedure call: init; proc( a, b ); diff --git a/minie/build.sh b/minie/build.sh index 5d7ccf6..af3b490 100755 --- a/minie/build.sh +++ b/minie/build.sh @@ -6,6 +6,7 @@ gcc -m32 --stack-usage -g -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e tcc -m32 -g -O0 -o e2c e2c.c pcc -melf_i386 -g -Wall -O0 -g -D__float128="long double" -o e2c e2c.c clang -m32 -g -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c + ./e2c < test1.e set +e ./e2c < test2.e @@ -30,3 +31,5 @@ set -e nasm -o test1.bin -f bin test1.asm ndisasm -b32 test1.bin ../crenshaw/emul test1.bin + +./ec < ec.e diff --git a/minie/e2c.c b/minie/e2c.c index 9d46f52..def9d99 100644 --- a/minie/e2c.c +++ b/minie/e2c.c @@ -11,7 +11,7 @@ enum { MAX_NUMBER_LEN = 9, MAX_ERRMSG_LEN = 64, MAX_STRING_LEN = 64, - MAX_SYMBOLS = 32, + MAX_SYMBOLS = 64, MAX_RECORD_MEMBERS = 8, MAX_PARAMETERS = 4, MAX_TYPE_DATA_SIZE = 2048 @@ -156,7 +156,7 @@ static int getChar( void ) static int isWhite( int c ) { - if( c == ' ' || c == '\n' || c == '\t' ) return 1; + if( c == ' ' || c == '\r' || c == '\n' || c == '\t' ) return 1; return 0; } @@ -181,6 +181,7 @@ static int isCharacter( int c ) case '[': case ']': case ':': + case ';': case ',': /* TODO: allow more characters as we go along */ return 1; @@ -611,7 +612,7 @@ static char *basicTypeToCType( BasicType type ) case TYPE_BYTE: return "unsigned char"; default: - Abort( "Unknown basic type" ); + Abort( "Unknown basic type, no mapping defined to C" ); } } @@ -622,7 +623,7 @@ static char *typeToCType( Type *type ) if( type->type == TYPE_ARRAY ) { sprintf( s, "%s*", basicTypeToCType( type->details.array.type->type ) ); } else { - Abort( "Unknown type" ); + sprintf( s, "%s ", basicTypeToCType( type->type ) ); } return s; @@ -734,6 +735,16 @@ static void register_internal_constants( void ) insert_symbol( type, "false" ); } +static void init( void ) +{ + col = 1; + row = 1; + look = getChar( ); + ident[0] = '\0'; + num = 0; + sym = getSym( ); +} + static void prologue( void ) { emitLn( "/* generated with e2c */" ); @@ -758,16 +769,6 @@ static void prologue( void ) register_internal_constants( ); } -static void init( void ) -{ - col = 1; - row = 1; - look = getChar( ); - ident[0] = '\0'; - num = 0; - sym = getSym( ); -} - static void epilogue( void ) { emitLn( "int main( void ) {" ); @@ -1098,6 +1099,8 @@ static void parameterList( void ) emit( "printf( \"%%s\", " ); } else if( strcmp( funcName, "system.writeinteger" ) == 0 ) { emit( "printf( \"%%d\", " ); + } else if( strcmp( funcName, "system.writechar" ) == 0 ) { + emit( "printf( \"%%c\", " ); } else if( strcmp( funcName, "system.halt" ) == 0 ) { emit( "exit( " ); } else if( strcmp( funcName, "system.readline" ) == 0 ) { @@ -1410,7 +1413,7 @@ static void importBlock( void ) Expect( S_semicolon ); } -static void module( void ) +static void doModule( void ) { Expect( S_module ); if( sym == S_ident ) { @@ -1432,7 +1435,7 @@ int main( void ) { prologue( ); init( ); - module( ); + doModule( ); epilogue( ); exit( EXIT_SUCCESS ); @@ -7,10 +7,9 @@ var row : integer; look : char; -procedure init; +procedure Halt; begin - col := 1; - row := 1; + system.halt( 1 ) end procedure getChar : char; @@ -30,6 +29,21 @@ begin return c; end +procedure isWhite( c : char ) : boolean; +begin + if ( c = char( 0 ) ) or ( c = char( 10 ) ) or ( c = char( 13 ) ) or ( c = char( 9 ) ) do + return true; + else + return false; + end +end + +procedure init; +begin + col := 1; + row := 1; +end + procedure prologue; begin system.writeline( "[bits 32]" ); @@ -37,20 +51,28 @@ begin system.writeline( "org 0x1000000" ); end +procedure doModule; +begin +(* Expect( S_module ); *) + look := getChar( ); + while ( look <> char( 0 ) ) do + if not isWhite( look ) do + system.writechar( look ); + end; + look := getChar( ); + end; +end + procedure epilogue; begin system.writeline( "hlt" ); end begin - init; prologue; + init; + doModule; epilogue; - - look := getChar( ); - while ( look <> char( 0 ) ) do - look := getChar( ); - end; - + system.halt( 0 ); end |