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
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_SUSPEND function_attributes
313 current_function->suspend = true;
317 abstract_declaration:
329 | parameters ',' parameter
336 parameter.type = *($1);
338 current_function->parameters.push_back(parameter);
343 parameter.type = *($1);
347 current_function->parameters.push_back(parameter);
353 current_type = new Type();
355 prefix_type_modifiers atomic_type postfix_type_modifiers
361 prefix_type_modifiers:
363 | prefix_type_modifiers prefix_type_modifier
366 prefix_type_modifier:
368 { current_type->_unsigned = true; }
370 { current_type->_unsigned = false; }
372 { current_type->_static = true; }
374 { current_type->_const = true; }
377 postfix_type_modifiers:
379 | postfix_type_modifiers postfix_type_modifier
382 postfix_type_modifier:
384 { current_type->_const = true; }
386 { current_type->pointer++; }
388 { current_type->ref++; }
393 { current_type->atomic_type = &BasicType::VOID; }
395 { current_type->atomic_type = &BasicType::BOOL; }
397 { current_type->atomic_type = &BasicType::CHAR; }
399 { current_type->atomic_type = &BasicType::SHORT; }
401 { current_type->atomic_type = &BasicType::INT; }
403 { current_type->atomic_type = &BasicType::LONG; }
405 { current_type->atomic_type = &BasicType::FLOAT; }
407 { current_type->atomic_type = &BasicType::DOUBLE; }
409 { current_type->atomic_type = $1; }
417 | namespace_refs "::" T_ATOMIC_TYPE
420 search_namespace = 0;
428 search_namespace = $1;
431 | namespace_refs "::" T_NAMESPACEREF
433 search_namespace = $3;
439 void yyerror(const char* error)
441 throw ParseError(error);