20 AtomicType* atomic_type;
21 Namespace* _namespace;
26 extern int yylex(YYSTYPE* yylval);
27 void yyerror(const char* s);
30 bool search_down = true;
31 Namespace* search_namespace = 0;
32 Namespace* current_namespace = 0;
33 static Class* current_class = 0;
34 static Function* current_function = 0;
35 static Type* current_type = 0;
36 static Field* current_field = 0;
37 static ClassMember::Visbility current_visibility;
39 class ParseError : public std::exception
42 ParseError(const std::string& message) throw()
44 std::ostringstream msg;
45 msg << "Parse error in '" << current_file
46 << "' line " << getCurrentLine() << ": "
48 this->message = msg.str();
50 virtual ~ParseError() throw()
52 const char* what() const throw()
54 return message.c_str();
67 %token <atomic_type> T_ATOMIC_TYPE
68 %token <_namespace> T_NAMESPACEREF
89 %type <_class> class_declaration
90 %type <function> function_declaration
91 %type <function> constructor_declaration;
92 %type <function> destructor_declaration;
93 %type <field> field_declaration;
95 %type <atomic_type> type_identifier
101 current_namespace = unit;
106 namespace_members: /* empty */
107 | namespace_members namespace_member
110 namespace_declaration:
113 Namespace* newNamespace = new Namespace();
114 newNamespace->name = $2;
116 current_namespace->add_namespace(newNamespace);
117 current_namespace = newNamespace;
119 namespace_members '}'
121 current_namespace = current_namespace->parent;
123 | T_NAMESPACE T_NAMESPACEREF '{'
125 current_namespace = $2;
127 namespace_members '}'
129 current_namespace = current_namespace->parent;
135 { current_namespace->add_type($1); }
136 | function_declaration
137 { current_namespace->functions.push_back($1); }
138 | namespace_declaration
140 { current_namespace->fields.push_back($1); }
146 current_class = new Class();
147 current_class->name = $2;
149 current_class->docu_comment = last_docucomment;
150 last_docucomment = "";
151 current_visibility = ClassMember::PROTECTED;
159 class_body: /* empty */
160 | class_body class_body_element
165 | constructor_declaration
167 $1->visibility = current_visibility;
168 current_class->members.push_back($1);
170 | destructor_declaration
172 $1->visibility = current_visibility;
173 current_class->members.push_back($1);
175 | function_declaration
177 $1->visibility = current_visibility;
178 current_class->members.push_back($1);
182 $1->visibility = current_visibility;
183 current_class->members.push_back($1);
189 { current_visibility = ClassMember::PUBLIC; }
191 { current_visibility = ClassMember::PROTECTED; }
193 { current_visibility = ClassMember::PRIVATE; }
196 constructor_declaration:
199 current_function = new Function();
200 current_function->type = Function::CONSTRUCTOR;
201 current_function->docu_comment = last_docucomment;
202 last_docucomment = "";
205 parameter_list ')' ';'
207 $$ = current_function;
211 destructor_declaration:
212 '~' T_ID '(' ')' abstract_declaration ';'
214 current_function = new Function();
215 current_function->type = Function::DESTRUCTOR;
216 current_function->docu_comment = last_docucomment;
217 last_docucomment = "";
219 $$ = current_function;
226 current_field = new Field();
227 current_field->type = $1;
228 current_field->name = $2;
231 maybe_const_initialisation ';'
237 maybe_const_initialisation:
241 if(current_field->type->atomic_type == &BasicType::FLOAT) {
242 current_field->const_float_value = (float) $2;
244 current_field->const_int_value = $2;
246 current_field->has_const_value = true;
250 current_field->const_float_value = $2;
251 current_field->has_const_value = true;
255 current_field->const_string_value = $2;
256 current_field->has_const_value = true;
260 function_declaration:
264 current_function = new Function();
265 current_function->type = Function::FUNCTION;
266 current_function->return_type = *($2);
268 current_function->name = $3;
270 current_function->docu_comment = last_docucomment;
271 last_docucomment = "";
274 current_function = new Function();
275 current_function->type = Function::FUNCTION;
276 current_function->return_type = *($1);
278 current_function->name = $2;
280 current_function->docu_comment = last_docucomment;
281 last_docucomment = "";
283 parameter_list ')' abstract_declaration ';'
285 $$ = current_function;
289 abstract_declaration:
301 | parameters ',' parameter
308 parameter.type = *($1);
310 current_function->parameters.push_back(parameter);
315 parameter.type = *($1);
319 current_function->parameters.push_back(parameter);
325 current_type = new Type();
327 prefix_type_modifiers atomic_type postfix_type_modifiers
333 prefix_type_modifiers:
335 | prefix_type_modifiers prefix_type_modifier
338 prefix_type_modifier:
340 { current_type->_unsigned = true; }
342 { current_type->_unsigned = false; }
344 { current_type->_static = true; }
346 { current_type->_const = true; }
349 postfix_type_modifiers:
351 | postfix_type_modifiers postfix_type_modifier
354 postfix_type_modifier:
356 { current_type->_const = true; }
358 { current_type->pointer++; }
360 { current_type->ref++; }
365 { current_type->atomic_type = &BasicType::VOID; }
367 { current_type->atomic_type = &BasicType::BOOL; }
369 { current_type->atomic_type = &BasicType::CHAR; }
371 { current_type->atomic_type = &BasicType::SHORT; }
373 { current_type->atomic_type = &BasicType::INT; }
375 { current_type->atomic_type = &BasicType::LONG; }
377 { current_type->atomic_type = &BasicType::FLOAT; }
379 { current_type->atomic_type = &BasicType::DOUBLE; }
381 { current_type->atomic_type = $1; }
387 // search for type in current compilation unit...
390 | namespace_refs "::" T_ATOMIC_TYPE
393 search_namespace = 0;
401 search_namespace = $1;
404 | namespace_refs "::" T_NAMESPACEREF
406 search_namespace = $3;
412 void yyerror(const char* error)
414 throw ParseError(error);