equal
deleted
inserted
replaced
46 #define _ABSYNTAX_HH |
46 #define _ABSYNTAX_HH |
47 |
47 |
48 |
48 |
49 #include <stdio.h> // required for NULL |
49 #include <stdio.h> // required for NULL |
50 #include <vector> |
50 #include <vector> |
|
51 #include <map> |
51 #include <string> |
52 #include <string> |
52 #include <stdint.h> // required for uint64_t, etc... |
53 #include <stdint.h> // required for uint64_t, etc... |
53 #include "../main.hh" // required for uint8_t, real_64_t, ..., and the macros INT8_MAX, REAL32_MAX, ... */ |
54 #include "../main.hh" // required for uint8_t, real_64_t, ..., and the macros INT8_MAX, REAL32_MAX, ... */ |
54 |
55 |
55 |
56 |
65 |
66 |
66 |
67 |
67 class symbol_c; // forward declaration |
68 class symbol_c; // forward declaration |
68 |
69 |
69 |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 /* Case insensitive string compare */ |
|
77 /* Case insensitive string compare copied from |
|
78 * "The C++ Programming Language" - 3rd Edition |
|
79 * by Bjarne Stroustrup, ISBN 0201889544. |
|
80 */ |
|
81 class nocasecmp_c { |
|
82 public: |
|
83 bool operator() (const std::string& x, const std::string& y) const { |
|
84 std::string::const_iterator ix = x.begin(); |
|
85 std::string::const_iterator iy = y.begin(); |
|
86 |
|
87 for(; (ix != x.end()) && (iy != y.end()) && (toupper(*ix) == toupper(*iy)); ++ix, ++iy); |
|
88 if (ix == x.end()) return (iy != y.end()); |
|
89 if (iy == y.end()) return false; |
|
90 return (toupper(*ix) < toupper(*iy)); |
|
91 }; |
|
92 }; |
70 |
93 |
71 |
94 |
72 |
95 |
73 |
96 |
74 |
97 |
97 long int last_order; /* relative order in which it is read by lexcial analyser */ |
120 long int last_order; /* relative order in which it is read by lexcial analyser */ |
98 |
121 |
99 |
122 |
100 /* |
123 /* |
101 * Annotations produced during stage 3 |
124 * Annotations produced during stage 3 |
102 */ |
125 */ |
103 /*** Data type analysis ***/ |
126 /*** Data type analysis ***/ |
104 std::vector <symbol_c *> candidate_datatypes; /* All possible data types the expression/literal/etc. may take. Filled in stage3 by fill_candidate_datatypes_c class */ |
127 std::vector <symbol_c *> candidate_datatypes; /* All possible data types the expression/literal/etc. may take. Filled in stage3 by fill_candidate_datatypes_c class */ |
105 /* Data type of the expression/literal/etc. Filled in stage3 by narrow_candidate_datatypes_c |
128 /* Data type of the expression/literal/etc. Filled in stage3 by narrow_candidate_datatypes_c |
106 * If set to NULL, it means it has not yet been evaluated. |
129 * If set to NULL, it means it has not yet been evaluated. |
107 * If it points to an object of type invalid_type_name_c, it means it is invalid. |
130 * If it points to an object of type invalid_type_name_c, it means it is invalid. |
136 const_value_uint64_t _uint64; /* status is initialised to UNDEFINED */ |
159 const_value_uint64_t _uint64; /* status is initialised to UNDEFINED */ |
137 const_value_bool_t _bool; /* status is initialised to UNDEFINED */ |
160 const_value_bool_t _bool; /* status is initialised to UNDEFINED */ |
138 } const_value_t; |
161 } const_value_t; |
139 const_value_t const_value; |
162 const_value_t const_value; |
140 |
163 |
|
164 /*** Enumeration datatype checking ***/ |
|
165 /* Not all symbols will contain the following anotations, which is why they are not declared here in symbol_c |
|
166 * They will be declared only inside the symbols that require them (have a look at absyntax.def) |
|
167 */ |
|
168 typedef std::multimap<std::string, symbol_c *, nocasecmp_c> enumvalue_symtable_t; |
|
169 |
141 |
170 |
142 public: |
171 public: |
143 /* default constructor */ |
172 /* default constructor */ |
144 symbol_c(int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */ |
173 symbol_c(int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */ |
145 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0 /* order in which it is read by lexcial analyser */ |
174 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0 /* order in which it is read by lexcial analyser */ |
151 |
180 |
152 virtual void *accept(visitor_c &visitor) {return NULL;}; |
181 virtual void *accept(visitor_c &visitor) {return NULL;}; |
153 }; |
182 }; |
154 |
183 |
155 |
184 |
|
185 |
|
186 |
156 class token_c: public symbol_c { |
187 class token_c: public symbol_c { |
157 public: |
188 public: |
158 /* WARNING: only use this method for debugging purposes!! */ |
189 /* WARNING: only use this method for debugging purposes!! */ |
159 virtual const char *absyntax_cname(void) {return "token_c";}; |
190 virtual const char *absyntax_cname(void) {return "token_c";}; |
160 |
191 |
165 token_c(const char *value, |
196 token_c(const char *value, |
166 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */ |
197 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */ |
167 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0 /* order in which it is read by lexcial analyser */ |
198 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0 /* order in which it is read by lexcial analyser */ |
168 ); |
199 ); |
169 }; |
200 }; |
|
201 |
|
202 |
170 |
203 |
171 |
204 |
172 /* a list of symbols... */ |
205 /* a list of symbols... */ |
173 class list_c: public symbol_c { |
206 class list_c: public symbol_c { |
174 public: |
207 public: |
198 }; |
231 }; |
199 |
232 |
200 |
233 |
201 |
234 |
202 |
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
203 #define SYM_LIST(class_name_c, ...) \ |
241 #define SYM_LIST(class_name_c, ...) \ |
204 class class_name_c: public list_c { \ |
242 class class_name_c: public list_c { \ |
205 public: \ |
243 public: \ |
206 __VA_ARGS__ \ |
244 __VA_ARGS__ \ |
207 public: \ |
245 public: \ |