a/c2iec.y | b/c2iec.y | ||
---|---|---|---|
... |
... |
||
18 | %{ |
18 | %{ |
19 | #include <string.h> |
19 | #include <string.h> |
20 | #include <stdio.h> |
20 | #include <stdio.h> |
21 | #include <stdlib.h> |
21 | #include <stdlib.h> |
22 | 22 | ||
23 | // enable debug prints for this file |
||
24 | #ifdef DEBUG |
||
25 | #define DEBUG_PRINT(args...) printf(args) |
||
26 | #else |
||
27 | #define DEBUG_PRINT(args...) |
||
28 | #endif |
||
29 | |||
23 | // get tail of a string |
30 | // get tail of a string |
24 | #define TAIL(str) (&str[strlen(str)]) |
31 | #define TAIL(str) (&str[strlen(str)]) |
25 | 32 | ||
26 | 33 | ||
27 | /* fifo to store expression strings */ |
34 | // fifo to store expression strings |
28 | #define STMT_SIZE 1024 |
35 | #define STMT_SIZE 1024 |
29 | #define FIFO_SIZE 200 |
36 | #define FIFO_SIZE 200 |
30 | 37 | ||
31 | typedef enum |
38 | typedef enum |
32 | { |
39 | { |
... |
... |
||
136 | | INC_OP unary_expression |
143 | | INC_OP unary_expression |
137 | { sprintf($<str>$, "(%s:=%s+1)",$<str>2, $<str>2); } |
144 | { sprintf($<str>$, "(%s:=%s+1)",$<str>2, $<str>2); } |
138 | | DEC_OP unary_expression |
145 | | DEC_OP unary_expression |
139 | { sprintf($<str>$, "(%s:=%s-1)",$<str>2, $<str>2); } |
146 | { sprintf($<str>$, "(%s:=%s-1)",$<str>2, $<str>2); } |
140 | | unary_operator cast_expression |
147 | | unary_operator cast_expression |
141 | { sprintf($<str>$, "%s^",$<str>2); } |
148 | { |
149 | if (!strcmp($<str>1, "*")) |
||
150 | { |
||
151 | sprintf($<str>$, "%s^",$<str>2); |
||
152 | } |
||
153 | else |
||
154 | { |
||
155 | sprintf($<str>$, "%s%s",$<str>1, $<str>2); |
||
156 | } |
||
157 | } |
||
142 | | SIZEOF unary_expression |
158 | | SIZEOF unary_expression |
143 | { sprintf($<str>$, "%s %s",$<str>1, $<str>2); } |
159 | { sprintf($<str>$, "%s %s",$<str>1, $<str>2); } |
144 | | SIZEOF '(' type_name ')' |
160 | | SIZEOF '(' type_name ')' |
145 | { sprintf($<str>$, "%s (%s)",$<str>1, $<str>3); } |
161 | { sprintf($<str>$, "%s (%s)",$<str>1, $<str>3); } |
146 | ; |
162 | ; |
... |
... |
||
957 | void addSym(char *szSym) |
973 | void addSym(char *szSym) |
958 | { |
974 | { |
959 | int i; |
975 | int i; |
960 | if (s_iSymTabCount >= SYM_COUNT) |
976 | if (s_iSymTabCount >= SYM_COUNT) |
961 | { |
977 | { |
962 | printf("error: symbol table size exceeded!\n"); |
978 | DEBUG_PRINT("error: symbol table size exceeded!\n"); |
963 | exit(-1); |
979 | exit(-1); |
964 | } |
980 | } |
965 | if (strlen(szSym) >= SYM_SIZE) |
981 | if (strlen(szSym) >= SYM_SIZE) |
966 | { |
982 | { |
967 | printf("error: symbol name too long '%s'!\n", szSym); |
983 | DEBUG_PRINT("error: symbol name too long '%s'!\n", szSym); |
968 | exit(-1); |
984 | exit(-1); |
969 | } |
985 | } |
970 | 986 | ||
971 | i = s_iSymTabCount++; |
987 | i = s_iSymTabCount++; |
972 | 988 | ||
973 | // printf("symbol: adding '%s' (%i)\n", szSym, i); |
989 | DEBUG_PRINT("symbol: adding '%s' (%i)\n", szSym, i); |
974 | 990 | ||
975 | strcpy(s_szSymTab[i], szSym); |
991 | strcpy(s_szSymTab[i], szSym); |
976 | } |
992 | } |
977 | 993 | ||
978 | int isSym(char *szSym) |
994 | int isSym(char *szSym) |
979 | { |
995 | { |
980 | int i; |
996 | int i; |
981 | for (i=0; i < s_iSymTabCount; i++) |
997 | for (i=0; i < s_iSymTabCount; i++) |
982 | { |
998 | { |
983 | // printf("symbol: check %d: %s\n", i, s_szSymTab[i]); |
999 | DEBUG_PRINT("symbol: check %d: %s\n", i, s_szSymTab[i]); |
984 | if (!strcmp(s_szSymTab[i], szSym)) |
1000 | if (!strcmp(s_szSymTab[i], szSym)) |
985 | { |
1001 | { |
986 | // printf("symbol: found '%s'\n", szSym); |
1002 | DEBUG_PRINT("symbol: found '%s'\n", szSym); |
987 | return 1; |
1003 | return 1; |
988 | } |
1004 | } |
989 | } |
1005 | } |
990 | // printf("symbol: missed '%s'\n", szSym); |
1006 | DEBUG_PRINT("symbol: missed '%s'\n", szSym); |
991 | return 0; |
1007 | return 0; |
992 | } |
1008 | } |
993 | 1009 | ||
994 | 1010 | ||
995 | void setFunctionName(char *szName) |
1011 | void setFunctionName(char *szName) |