summaryrefslogtreecommitdiff
path: root/miniany/cc.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2021-08-19 18:49:25 +0000
committerAndreas Baumann <mail@andreasbaumann.cc>2021-08-19 18:49:25 +0000
commitb74b9a8ef45137611e53e779d932d9d222e8eb35 (patch)
tree2db882d77318369a0fe63cfbb7ed5a83e4f5c11e /miniany/cc.c
parent3f553969451504d020ff90644edd348ffbcd2907 (diff)
downloadcompilertests-b74b9a8ef45137611e53e779d932d9d222e8eb35.tar.gz
compilertests-b74b9a8ef45137611e53e779d932d9d222e8eb35.tar.bz2
added symbol struct and memory management
Diffstat (limited to 'miniany/cc.c')
-rw-r--r--miniany/cc.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/miniany/cc.c b/miniany/cc.c
index cf4f880..d77def0 100644
--- a/miniany/cc.c
+++ b/miniany/cc.c
@@ -278,25 +278,39 @@ void parseExpression( )
}
}
-/*
struct Symbol {
char *name;
+ struct Symbol *next;
};
struct Symbol *symbol;
-*/
-void newSymbol( char *s )
+struct Symbol *createSymbol( char *s )
{
+ struct Symbol *sym;
+ sym = (struct Symbol *)malloc( sizeof ( struct Symbol ) );
+ sym->name = strdup( s );
+ sym->next = NULL;
+
+ return sym;
+}
+
+void freeSymbol( struct Symbol *sym )
+{
+ free( sym->name );
+ free( (char *)sym );
}
void parseDeclaration( )
{
+ struct Symbol *sym;
+
expect( S_INT, "int" );
expect( S_IDENT, "identifier" );
putstring( "Adding glob: " ); putstring( ident ); putnl( );
- newSymbol( ident );
+ sym = createSymbol( ident );
+ freeSymbol( sym );
expect( S_SEMICOLON, ";" );
}
@@ -325,7 +339,7 @@ int main( int argc, char **argv )
row = 1;
pushback = 0;
DEBUG_SCANNER = 1;
- /* symbol = NULL; */
+ symbol = NULL;
ident = "12345678901234567890";
token = getToken( );