scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 7f4177cf55af62d6ed0d29db6bb545d640eba4ac
parent b95cc0c19c628ad8cf1f0e99548dadaff35a786f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Jun 2012 09:44:05 +0200

Removed debug information about gramatic

In this point the parser is enough robust how remove this information,
because begins to hide other useful information.

Diffstat:
decl.c | 10+---------
expr.c | 41+++--------------------------------------
flow.c | 16----------------
lex.c | 76----------------------------------------------------------------------------
4 files changed, 4 insertions(+), 139 deletions(-)

diff --git a/decl.c b/decl.c @@ -17,7 +17,6 @@ static void declarator(void); static void dirdcl(void) { - puts("dirdecl"); if (accept('(')) { declarator(); expect(')'); @@ -47,7 +46,6 @@ static void dirdcl(void) /* TODO: specify size of array */; continue; } else { - puts("leaving dirdcl"); return; } } @@ -86,7 +84,6 @@ static struct type *specifier(void) auto unsigned char sign, sclass, tqlf, nt; auto struct type *t; - puts("especifier"); t = NULL; tqlf = sign = sclass = 0; for (;; next()) { @@ -197,7 +194,6 @@ static void declarator(void) { unsigned char qlf[PTRLEVEL_MAX], *bp, *lim; - puts("declarator"); lim = qlf + PTRLEVEL_MAX; for (bp = qlf; yytoken == '*' && bp != lim; ++bp) { *bp = 0; @@ -232,7 +228,6 @@ static void declarator(void) pushtype(PTR); } - puts("leaving dcl"); return; duplicated: @@ -244,7 +239,6 @@ unsigned char decl(void) auto struct type *tp, *tbase; auto unsigned char nd = 0; - puts("decl"); if (!(tbase = specifier())) return 0; if (yytoken != ';') { @@ -253,7 +247,7 @@ unsigned char decl(void) tp = decl_type(tbase); if (isfunction(tp) && yytoken == '{') { compound(); - goto leaving; + return 1; } ++nd; } while (accept(',')); @@ -264,8 +258,6 @@ unsigned char decl(void) warning_error(user_opt.useless_typename, "useless type name in empty declaration"); } -leaving: - puts("leaving decl"); return 1; } diff --git a/expr.c b/expr.c @@ -11,7 +11,6 @@ void expr(void); static void primary(void) { - puts("primary"); switch (yytoken) { case IDENTIFIER: if (!yyval.sym) @@ -26,12 +25,10 @@ static void primary(void) expect(')'); break; } - puts("leaving primary"); } static void postfix(void) { - puts("postfix"); primary(); for (;;) { switch (yytoken) { @@ -55,7 +52,6 @@ static void postfix(void) next(); break; default: - puts("leaving postfix"); return; } } @@ -65,7 +61,6 @@ static void cast(void); static void unary(void) { - puts("unary"); for (;;) { switch (yytoken) { case SIZEOF: @@ -73,7 +68,7 @@ static void unary(void) if (accept('(')) { type_name(); expect(')'); - goto leaving; + return; } break; case INC_OP: @@ -83,132 +78,105 @@ static void unary(void) case '&': case '*': case '-': case '~': case '!': case '+': next(); cast(); - goto leaving; + return; default: postfix(); - goto leaving; + return; } } -leaving: - puts("leaving unary"); } static void cast(void) { - puts("cast"); while (accept('(')) { type_name(); /* check if it really is a type name */ expect(')'); } unary(); - puts("leaving cast"); } static void mul(void) { - puts("mul"); do cast(); while(accept('*') || accept('/') || accept('%')); - puts("leaving mul"); } static void add(void) { - puts("add"); do mul(); while (accept('+') || accept('-')); - puts("leaving add"); } static void shift(void) { - puts("shift"); do add(); while (accept(LSHIFT_OP) || accept(RSHIFT_OP)); - puts("leaving shift"); } static void relational(void) { - puts("relational"); do shift(); while (accept('<') || accept('>') || accept(GE_OP) || accept(LE_OP)); - puts("leaving relational"); } static void equality(void) { - puts("equality"); do relational(); while (accept(EQ_OP) || accept(NE_OP)); - puts("leaving equality"); } static void bit_and(void) { - puts("bit_and"); do equality(); while (accept('&')); - puts("leaving bit_and"); } static void bit_exor(void) { - puts("bit_exor"); do bit_and(); while (accept('^')); - puts("leaving bit_exor"); } static void bit_or(void) { - puts("bit_or"); do bit_exor(); while (accept('|')); - puts("leaving bit_or"); } static void and(void) { - puts("and"); do bit_or(); while (accept(AND_OP)); - puts("leaving and"); } static void or(void) { - puts("or"); do and(); while (accept(OR_OP)); - puts("leaving or"); } static void conditional(void) { - puts("conditional"); or(); if (accept('?')) { expr(); expect(':'); conditional(); } - puts("leaving conditional"); } static void assign(void) { - puts("assign"); unary(); switch (yytoken) { case '=': @@ -229,14 +197,11 @@ static void assign(void) conditional(); break; } - puts("leaving assign"); } void expr(void) { - puts("expr"); do assign(); while (yytoken == ','); - puts("leaving expr"); } diff --git a/flow.c b/flow.c @@ -9,38 +9,31 @@ void stmt(void); static void do_goto(void) { - puts("void do_goto"); expect(GOTO); expect(IDENTIFIER); - puts("leaving void do_goto"); } static void do_while(void) { - puts("void do_while"); expect(WHILE); expect('('); expr(); expect(')'); stmt(); - puts("leaving void do_while"); } static void do_do(void) { - puts("void do_do"); expect(DO); stmt(); expect(WHILE); expect('('); expr(); expect(')'); - puts("leaving void do_do"); } static void do_for(void) { - puts("void do_for"); expect(FOR); expect('('); if (yytoken != ';') @@ -53,12 +46,10 @@ static void do_for(void) expr(); expect(')'); stmt(); - puts("leaving void do_for"); } static void do_if(void) { - puts("void do_if"); expect(IF); expect('('); expr(); @@ -67,23 +58,19 @@ static void do_if(void) if (accept(ELSE)) stmt(); - puts("leaving void do_if"); } static void do_switch(void) { - puts("do_switch"); expect(SWITCH); expect('('); expr(); expect(')'); stmt(); - puts("leaving do_switch"); } void stmt(void) { - puts("stmt"); switch (yytoken) { case '{': @@ -122,12 +109,10 @@ void stmt(void) expect(';'); break; } - puts("leaving stmt"); } void compound(void) { - puts("compound"); if (accept('{')) { struct symctx ctx; @@ -138,5 +123,4 @@ void compound(void) stmt(); del_ctx(); } - puts("leaving compound"); } diff --git a/lex.c b/lex.c @@ -73,76 +73,6 @@ static unsigned char hashfun(register const char *s) return h; } -#ifndef NDEBUG -static char *toknames[] = { - [INT] = "INT", - [CHAR] = "CHAR", - [FLOAT] = "FLOAT", - [LONG] = "LONG", - [LLONG] = "LLONG", - [SHORT] = "SHORT", - [VOID] = "VOID", - [DOUBLE] = "DOUBLE", - [LDOUBLE] = "LDOUBLE", - [STRUCT] = "STRUCT", - [UNION] = "UNION", - [ENUM] = "ENUM", - [UTYPE] = "UTYPE", - [BOOL] = "BOOL", - [TYPEDEF] = "TYPEDEF", - [EXTERN] = "EXTERN", - [STATIC] = "STATIC", - [AUTO] = "AUTO", - [REGISTER] = "REGISTER", - [VOLATILE] = "VOLATILE", - [CONST] = "CONST", - [RESTRICTED] = "RESTRICTED", - [UNSIGNED] = "UNSIGNED", - [SIGNED] = "SIGNED", - [IDENTIFIER] = "IDENTIFIER", - [CONSTANT] = "CONSTANT", - [STRING_LITERAL] = "STRING_LITERAL", - [SIZEOF] = "SIZEOF", - [PTR_OP] = "PTR_OP", - [INC_OP] = "INC_OP", - [DEC_OP] = "DEC_OP", - [LSHIFT_OP] = "LEFT_OP", - [RSHIFT_OP] = "RIGHT_OP", - [LE_OP] = "LE_OP", - [GE_OP] = "GE_OP", - [EQ_OP] = "EQ_OP", - [NE_OP] = "NE_OP", - [AND_OP] = "AND_OP", - [OR_OP] = "OR_OP", - [MUL_ASSIGN] = "MUL_ASSIGN", - [DIV_ASSIGN] = "DIV_ASSIGN", - [MOD_ASSIGN] = "MOD_ASSIGN", - [ADD_ASSIGN] = "ADD_ASSIGN", - [SUB_ASSIGN] = "SUB_ASSIGN", - [LSHIFT_ASSIGN] = "LSHIFT_ASSIGN", - [RSHIFT_ASSIGN] = "RSHIFT_ASSIGN", - [AND_ASSIGN] = "AND_ASSIGN", - [XOR_ASSIGN] = "XOR_ASSIGN", - [OR_ASSIGN] = "OR_ASSIGN", - [TYPE_NAME] = "TYPE_NAME", - [ELLIPSIS] = "ELLIPSIS", - [CASE] = "CASE", - [DEFAULT] = "DEFAULT", - [IF] = "IF", - [ELSE] = "ELSE", - [SWITCH] = "SWITCH", - [WHILE] = "WHILE", - [DO] = "DO", - [FOR] = "FOR", - [GOTO] = "GOTO", - [CONTINUE] = "CONTINUE", - [BREAK] = "BREAK", - [RETURN] = "RETURN", - [EOFTOK] = "EOFTOK" -}; - -#endif - void init_lex(void) { register struct keyword *bp; @@ -312,12 +242,6 @@ unsigned char next(void) } return_token: -#ifndef NDEBUG - printf(!toknames[ch] ? - "Token = (%u, '%s')\n" : - "Token = (%u, '%s' %s)\n", - (unsigned) ch, yytext, toknames[ch]); -#endif return yytoken = ch; }