summaryrefslogtreecommitdiff
path: root/miniany/cc.c
diff options
context:
space:
mode:
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( );