--- a/c2iec.y +++ b/c2iec.y @@ -20,11 +20,18 @@ #include <stdio.h> #include <stdlib.h> +// enable debug prints for this file +#ifdef DEBUG + #define DEBUG_PRINT(args...) printf(args) +#else + #define DEBUG_PRINT(args...) +#endif + // get tail of a string #define TAIL(str) (&str[strlen(str)]) -/* fifo to store expression strings */ +// fifo to store expression strings #define STMT_SIZE 1024 #define FIFO_SIZE 200 @@ -138,7 +145,16 @@ | DEC_OP unary_expression { sprintf($<str>$, "(%s:=%s-1)",$<str>2, $<str>2); } | unary_operator cast_expression - { sprintf($<str>$, "%s^",$<str>2); } + { + if (!strcmp($<str>1, "*")) + { + sprintf($<str>$, "%s^",$<str>2); + } + else + { + sprintf($<str>$, "%s%s",$<str>1, $<str>2); + } + } | SIZEOF unary_expression { sprintf($<str>$, "%s %s",$<str>1, $<str>2); } | SIZEOF '(' type_name ')' @@ -959,18 +975,18 @@ int i; if (s_iSymTabCount >= SYM_COUNT) { - printf("error: symbol table size exceeded!\n"); + DEBUG_PRINT("error: symbol table size exceeded!\n"); exit(-1); } if (strlen(szSym) >= SYM_SIZE) { - printf("error: symbol name too long '%s'!\n", szSym); + DEBUG_PRINT("error: symbol name too long '%s'!\n", szSym); exit(-1); } i = s_iSymTabCount++; -// printf("symbol: adding '%s' (%i)\n", szSym, i); + DEBUG_PRINT("symbol: adding '%s' (%i)\n", szSym, i); strcpy(s_szSymTab[i], szSym); } @@ -980,14 +996,14 @@ int i; for (i=0; i < s_iSymTabCount; i++) { -// printf("symbol: check %d: %s\n", i, s_szSymTab[i]); + DEBUG_PRINT("symbol: check %d: %s\n", i, s_szSymTab[i]); if (!strcmp(s_szSymTab[i], szSym)) { -// printf("symbol: found '%s'\n", szSym); + DEBUG_PRINT("symbol: found '%s'\n", szSym); return 1; } } -// printf("symbol: missed '%s'\n", szSym); + DEBUG_PRINT("symbol: missed '%s'\n", szSym); return 0; }