48 #include <iostream> |
48 #include <iostream> |
49 #include <sstream> |
49 #include <sstream> |
50 #include <typeinfo> |
50 #include <typeinfo> |
51 #include <list> |
51 #include <list> |
52 #include <strings.h> |
52 #include <strings.h> |
53 #include <string.h> /* required for strlen() */ |
53 // #include <string.h> /* required for strlen() */ |
54 #include <stdlib.h> /* required for atoi() */ |
54 // #include <stdlib.h> /* required for atoi() */ |
|
55 // #include <errno.h> /* required for errno */ |
55 |
56 |
56 #include "../util/symtable.hh" |
57 #include "../util/symtable.hh" |
57 #include "../util/dsymtable.hh" |
58 #include "../util/dsymtable.hh" |
58 #include "../absyntax/visitor.hh" |
59 #include "../absyntax/visitor.hh" |
|
60 #include "../main.hh" // required for ERROR() and ERROR_MSG() macros. |
59 |
61 |
60 |
62 |
61 |
63 |
62 //#define DEBUG |
64 //#define DEBUG |
63 #ifdef DEBUG |
65 #ifdef DEBUG |
64 #define TRACE(classname) printf("\n____%s____\n",classname); |
66 #define TRACE(classname) printf("\n____%s____\n",classname); |
65 #else |
67 #else |
66 #define TRACE(classname) |
68 #define TRACE(classname) |
67 #endif |
69 #endif |
68 |
70 |
69 #define ERROR error_exit(__FILE__,__LINE__) |
|
70 /* function defined in main.cc */ |
|
71 extern void error_exit(const char *file_name, int line_no); |
|
72 |
71 |
73 |
72 |
74 /***********************************************************************/ |
73 /***********************************************************************/ |
75 /***********************************************************************/ |
74 /***********************************************************************/ |
76 /***********************************************************************/ |
75 /***********************************************************************/ |
91 if (strcasecmp(name1->value, name2->value) == 0) |
90 if (strcasecmp(name1->value, name2->value) == 0) |
92 return 0; |
91 return 0; |
93 |
92 |
94 /* identifiers do not match! */ |
93 /* identifiers do not match! */ |
95 return 1; |
94 return 1; |
96 } |
|
97 |
|
98 |
|
99 /* extract the value of an integer from an integer_c object !! */ |
|
100 /* NOTE: it must ignore underscores! */ |
|
101 int extract_integer(symbol_c *sym) { |
|
102 std::string str = ""; |
|
103 integer_c *integer; |
|
104 neg_integer_c * neg_integer; |
|
105 |
|
106 if ((neg_integer = dynamic_cast<neg_integer_c *>(sym)) != NULL) |
|
107 return - extract_integer((integer_c *)neg_integer->exp); |
|
108 |
|
109 if ((integer = dynamic_cast<integer_c *>(sym)) == NULL) ERROR; |
|
110 |
|
111 for(unsigned int i = 0; i < strlen(integer->value); i++) |
|
112 if (integer->value[i] != '_') str += integer->value[i]; |
|
113 |
|
114 return atoi(str.c_str()); |
|
115 } |
95 } |
116 |
96 |
117 |
97 |
118 |
98 |
119 /***********************************************************************/ |
99 /***********************************************************************/ |
292 type_symtable.insert(symbol->structure_type_name, symbol->structure_specification); |
272 type_symtable.insert(symbol->structure_type_name, symbol->structure_specification); |
293 return NULL; |
273 return NULL; |
294 } |
274 } |
295 |
275 |
296 |
276 |
297 |
277 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
278 // SYM_REF4(string_type_declaration_c, string_type_name, |
|
279 // elementary_string_type_name, |
|
280 // string_type_declaration_size, |
|
281 // string_type_declaration_init) /* may be == NULL! */ |
|
282 void *visit(string_type_declaration_c *symbol) { |
|
283 TRACE("string_type_declaration_c"); |
|
284 type_symtable.insert(symbol->string_type_name, symbol); |
|
285 return NULL; |
|
286 } |
|
287 |
298 /*********************/ |
288 /*********************/ |
299 /* B 1.4 - Variables */ |
289 /* B 1.4 - Variables */ |
300 /*********************/ |
290 /*********************/ |
301 /********************************************/ |
291 /********************************************/ |
302 /* B.1.4.1 Directly Represented Variables */ |
292 /* B.1.4.1 Directly Represented Variables */ |