#include "parse.h" #include "io.h" #include "string.h" #include "stdlib.h" void parser_init( Parser *p, Scanner *s ) { p->s = s; } void parser_done( Parser *p ) { } void parser_debug( Parser *p, int enable ) { p->debug = enable; if( p->debug ) { print( "PARSER DEBUGGING ENABLED" ); } } static void print_symbol( scanner_Symbol sym ) { char s[MAX_TMP_LEN]; char s2[MAX_TMP_LEN]; s[0] = '\0'; s2[0] = '\0'; switch( sym.sym ) { case S_eof: print( "PARSER(EOF)" ); break; case S_INT: print( "PARSER(INT)" ); break; case S_VOID: print( "PARSER(VOID)" ); break; case S_RETURN: print( "PARSER(RETURN)" ); break; case S_DIV: print( "PARSER(DIV)" ); break; case S_IDENT: strcat( s, "PARSER(IDENT," ); strcat( s, sym.data.s ); strcat_c( s, ')' ); print( s ); break; case S_INT_CONST: strcat( s, "PARSER(INT_CONST," ); itoa( sym.data.i, s2, 10 ); strcat( s, s2 ); strcat_c( s, ')' ); print( s ); break; case S_SEMICOLON: print( "PARSER(SEMICOLON)" ); break; case S_LPARENT: print( "PARSER(LPARENT)" ); break; case S_RPARENT: print( "PARSER(RPARENT)" ); break; case S_LCURL: print( "PARSER(LCURL)" ); break; case S_RCURL: print( "PARSER(RCURL)" ); break; default: print( "PARSER()" ); } } void parser_parse( Parser *p ) { scanner_Symbol s; s = scanner_scan( p->s ); while( s.sym != S_eof ) { if( p->debug ) { print_symbol( s ); } s = scanner_scan( p->s ); } }