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
91 %type <_class> class_declaration
92 %type <function> function_declaration
93 %type <function> constructor_declaration;
94 %type <function> destructor_declaration;
95 %type <field> field_declaration;
97 %type <atomic_type> type_identifier
103 current_namespace = unit;
108 namespace_members: /* empty */
109 | namespace_members namespace_member
112 namespace_declaration:
115 Namespace* newNamespace = new Namespace();
116 newNamespace->name = $2;
118 current_namespace->add_namespace(newNamespace);
119 current_namespace = newNamespace;
121 namespace_members '}'
123 current_namespace = current_namespace->parent;
125 | T_NAMESPACE T_NAMESPACEREF '{'
127 current_namespace = $2;
129 namespace_members '}'
131 current_namespace = current_namespace->parent;
137 { current_namespace->add_type($1); }
138 | function_declaration
139 { current_namespace->functions.push_back($1); }
140 | namespace_declaration
142 { current_namespace->fields.push_back($1); }
148 current_class = new Class();
149 current_class->name = $2;
151 current_class->docu_comment = last_docucomment;
152 last_docucomment = "";
153 current_visibility = ClassMember::PROTECTED;
155 superclass_list '{' class_body '}' ';'
168 | superclasses ',' superclass
172 superclass_visibility type_identifier
174 Class* superclass = dynamic_cast<Class*> ($2);
176 throw ParseError("SuperClass is not a Class type");
177 current_class->super_classes.push_back(superclass);
178 superclass->sub_classes.push_back(current_class);
182 superclass_visibility:
188 class_body: /* empty */
189 | class_body class_body_element
194 | constructor_declaration
196 $1->visibility = current_visibility;
197 current_class->members.push_back($1);
199 | destructor_declaration
201 $1->visibility = current_visibility;
202 current_class->members.push_back($1);
204 | function_declaration
206 $1->visibility = current_visibility;
207 current_class->members.push_back($1);
211 $1->visibility = current_visibility;
212 current_class->members.push_back($1);
218 { current_visibility = ClassMember::PUBLIC; }
220 { current_visibility = ClassMember::PROTECTED; }
222 { current_visibility = ClassMember::PRIVATE; }
225 constructor_declaration:
228 current_function = new Function();
229 current_function->type = Function::CONSTRUCTOR;
230 current_function->docu_comment = last_docucomment;
231 last_docucomment = "";
234 parameter_list ')' ';'
236 $$ = current_function;
240 destructor_declaration:
241 '~' T_ID '(' ')' abstract_declaration ';'
243 current_function = new Function();
244 current_function->type = Function::DESTRUCTOR;
245 current_function->docu_comment = last_docucomment;
246 last_docucomment = "";
248 $$ = current_function;
255 current_field = new Field();
256 current_field->type = $1;
257 current_field->docu_comment = last_docucomment;
258 last_docucomment = "";
259 current_field->name = $2;
262 maybe_const_initialisation ';'
268 maybe_const_initialisation:
272 if(current_field->type->atomic_type == &BasicType::FLOAT) {
273 current_field->const_float_value = (float) $2;
275 current_field->const_int_value = $2;
277 current_field->has_const_value = true;
281 current_field->const_float_value = $2;
282 current_field->has_const_value = true;
286 current_field->const_string_value = $2;
287 current_field->has_const_value = true;
291 function_declaration:
294 current_function = new Function();
295 current_function->type = Function::FUNCTION;
296 current_function->return_type = *($1);
298 current_function->name = $2;
300 current_function->docu_comment = last_docucomment;
301 last_docucomment = "";
303 parameter_list ')' function_attributes abstract_declaration ';'
305 $$ = current_function;
311 | T_CONST function_attributes
312 | T_CUSTOM function_attributes
314 current_function->custom = true;
316 | T_SUSPEND function_attributes
318 current_function->suspend = true;
322 abstract_declaration:
334 | parameters ',' parameter
341 parameter.type = *($1);
343 current_function->parameters.push_back(parameter);
348 parameter.type = *($1);
352 current_function->parameters.push_back(parameter);
358 current_type = new Type();
360 prefix_type_modifiers atomic_type postfix_type_modifiers
366 prefix_type_modifiers:
368 | prefix_type_modifiers prefix_type_modifier
371 prefix_type_modifier:
373 { current_type->_unsigned = true; }
375 { current_type->_unsigned = false; }
377 { current_type->_static = true; }
379 { current_type->_const = true; }
382 postfix_type_modifiers:
384 | postfix_type_modifiers postfix_type_modifier
387 postfix_type_modifier:
389 { current_type->_const = true; }
391 { current_type->pointer++; }
393 { current_type->ref++; }
398 { current_type->atomic_type = &BasicType::VOID; }
400 { current_type->atomic_type = &BasicType::BOOL; }
402 { current_type->atomic_type = &BasicType::CHAR; }
404 { current_type->atomic_type = &BasicType::SHORT; }
406 { current_type->atomic_type = &BasicType::INT; }
408 { current_type->atomic_type = &BasicType::LONG; }
410 { current_type->atomic_type = &BasicType::FLOAT; }
412 { current_type->atomic_type = &BasicType::DOUBLE; }
414 { current_type->atomic_type = $1; }
422 | namespace_refs "::" T_ATOMIC_TYPE
425 search_namespace = 0;
433 search_namespace = $1;
436 | namespace_refs "::" T_NAMESPACEREF
438 search_namespace = $3;
444 void yyerror(const char* error)
446 throw ParseError(error);