21 AtomicType* atomic_type;
22 Namespace* _namespace;
27 extern int yylex(YYSTYPE* yylval);
28 void yyerror(const char* s);
31 bool search_down = true;
32 Namespace* search_namespace = 0;
33 Namespace* current_namespace = 0;
34 static Class* current_class = 0;
35 static Function* current_function = 0;
36 static Type* current_type = 0;
37 static Field* current_field = 0;
38 static ClassMember::Visibility current_visibility;
40 class ParseError : public std::exception
43 ParseError(const std::string& message) throw()
45 std::ostringstream msg;
46 msg << "Parse error in '" << current_file
47 << "' line " << getCurrentLine() << ": "
49 this->message = msg.str();
51 virtual ~ParseError() throw()
53 const char* what() const throw()
55 return message.c_str();
68 %token <atomic_type> T_ATOMIC_TYPE
69 %token <_namespace> T_NAMESPACEREF
90 %type <_class> class_declaration
91 %type <function> function_declaration
92 %type <function> constructor_declaration;
93 %type <function> destructor_declaration;
94 %type <field> field_declaration;
96 %type <atomic_type> type_identifier
102 current_namespace = unit;
107 namespace_members: /* empty */
108 | namespace_members namespace_member
111 namespace_declaration:
114 Namespace* newNamespace = new Namespace();
115 newNamespace->name = $2;
117 current_namespace->add_namespace(newNamespace);
118 current_namespace = newNamespace;
120 namespace_members '}'
122 current_namespace = current_namespace->parent;
124 | T_NAMESPACE T_NAMESPACEREF '{'
126 current_namespace = $2;
128 namespace_members '}'
130 current_namespace = current_namespace->parent;
136 { current_namespace->add_type($1); }
137 | function_declaration
138 { current_namespace->functions.push_back($1); }
139 | namespace_declaration
141 { current_namespace->fields.push_back($1); }
147 current_class = new Class();
148 current_class->name = $2;
150 current_class->docu_comment = last_docucomment;
151 last_docucomment = "";
152 current_visibility = ClassMember::PROTECTED;
154 superclass_list '{' class_body '}' ';'
167 | superclasses ',' superclass
171 superclass_visibility type_identifier
173 Class* superclass = dynamic_cast<Class*> ($2);
175 throw ParseError("SuperClass is not a Class type");
176 current_class->super_classes.push_back(superclass);
177 superclass->sub_classes.push_back(current_class);
181 superclass_visibility:
187 class_body: /* empty */
188 | class_body class_body_element
193 | constructor_declaration
195 $1->visibility = current_visibility;
196 current_class->members.push_back($1);
198 | destructor_declaration
200 $1->visibility = current_visibility;
201 current_class->members.push_back($1);
203 | function_declaration
205 $1->visibility = current_visibility;
206 current_class->members.push_back($1);
210 $1->visibility = current_visibility;
211 current_class->members.push_back($1);
217 { current_visibility = ClassMember::PUBLIC; }
219 { current_visibility = ClassMember::PROTECTED; }
221 { current_visibility = ClassMember::PRIVATE; }
224 constructor_declaration:
227 current_function = new Function();
228 current_function->type = Function::CONSTRUCTOR;
229 current_function->docu_comment = last_docucomment;
230 last_docucomment = "";
233 parameter_list ')' ';'
235 $$ = current_function;
239 destructor_declaration:
240 '~' T_ID '(' ')' abstract_declaration ';'
242 current_function = new Function();
243 current_function->type = Function::DESTRUCTOR;
244 current_function->docu_comment = last_docucomment;
245 last_docucomment = "";
247 $$ = current_function;
254 current_field = new Field();
255 current_field->type = $1;
256 current_field->docu_comment = last_docucomment;
257 last_docucomment = "";
258 current_field->name = $2;
261 maybe_const_initialisation ';'
267 maybe_const_initialisation:
271 if(current_field->type->atomic_type == &BasicType::FLOAT) {
272 current_field->const_float_value = (float) $2;
274 current_field->const_int_value = $2;
276 current_field->has_const_value = true;
280 current_field->const_float_value = $2;
281 current_field->has_const_value = true;
285 current_field->const_string_value = $2;
286 current_field->has_const_value = true;
290 function_declaration:
293 current_function = new Function();
294 current_function->type = Function::FUNCTION;
295 current_function->return_type = *($1);
297 current_function->name = $2;
299 current_function->docu_comment = last_docucomment;
300 last_docucomment = "";
302 parameter_list ')' function_attributes abstract_declaration ';'
304 $$ = current_function;
310 | T_CONST function_attributes
311 | T_CUSTOM function_attributes
313 current_function->custom = true;
315 | T_SUSPEND function_attributes
317 current_function->suspend = true;
321 abstract_declaration:
333 | parameters ',' parameter
340 parameter.type = *($1);
342 current_function->parameters.push_back(parameter);
347 parameter.type = *($1);
351 current_function->parameters.push_back(parameter);
357 current_type = new Type();
359 prefix_type_modifiers atomic_type postfix_type_modifiers
365 prefix_type_modifiers:
367 | prefix_type_modifiers prefix_type_modifier
370 prefix_type_modifier:
372 { current_type->_unsigned = true; }
374 { current_type->_unsigned = false; }
376 { current_type->_static = true; }
378 { current_type->_const = true; }
381 postfix_type_modifiers:
383 | postfix_type_modifiers postfix_type_modifier
386 postfix_type_modifier:
388 { current_type->_const = true; }
390 { current_type->pointer++; }
392 { current_type->ref++; }
397 { current_type->atomic_type = &BasicType::VOID; }
399 { current_type->atomic_type = &BasicType::BOOL; }
401 { current_type->atomic_type = &BasicType::CHAR; }
403 { current_type->atomic_type = &BasicType::SHORT; }
405 { current_type->atomic_type = &BasicType::INT; }
407 { current_type->atomic_type = &BasicType::LONG; }
409 { current_type->atomic_type = &BasicType::FLOAT; }
411 { current_type->atomic_type = &BasicType::DOUBLE; }
413 { current_type->atomic_type = $1; }
421 | namespace_refs "::" T_ATOMIC_TYPE
424 search_namespace = 0;
432 search_namespace = $1;
435 | namespace_refs "::" T_NAMESPACEREF
437 search_namespace = $3;
443 void yyerror(const char* error)
445 throw ParseError(error);