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() :
46 std::ostringstream msg;
47 msg << "Parse error in '" << current_file
48 << "' line " << getCurrentLine() << ": "
50 this->message = msg.str();
52 virtual ~ParseError() throw()
54 const char* what() const throw()
56 return message.c_str();
69 %token <atomic_type> T_ATOMIC_TYPE
70 %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 '(' T_STRING ')' function_attributes
314 current_function->parameter_spec = $3;
315 current_function->custom = true;
317 | T_SUSPEND function_attributes
319 current_function->suspend = true;
323 abstract_declaration:
335 | parameters ',' parameter
342 parameter.type = *($1);
344 current_function->parameters.push_back(parameter);
349 parameter.type = *($1);
353 current_function->parameters.push_back(parameter);
359 current_type = new Type();
361 prefix_type_modifiers atomic_type postfix_type_modifiers
367 prefix_type_modifiers:
369 | prefix_type_modifiers prefix_type_modifier
372 prefix_type_modifier:
374 { current_type->_unsigned = true; }
376 { current_type->_unsigned = false; }
378 { current_type->_static = true; }
380 { current_type->_const = true; }
383 postfix_type_modifiers:
385 | postfix_type_modifiers postfix_type_modifier
388 postfix_type_modifier:
390 { current_type->_const = true; }
392 { current_type->pointer++; }
394 { current_type->ref++; }
399 { current_type->atomic_type = &BasicType::VOID; }
401 { current_type->atomic_type = &BasicType::BOOL; }
403 { current_type->atomic_type = &BasicType::CHAR; }
405 { current_type->atomic_type = &BasicType::SHORT; }
407 { current_type->atomic_type = &BasicType::INT; }
409 { current_type->atomic_type = &BasicType::LONG; }
411 { current_type->atomic_type = &BasicType::FLOAT; }
413 { current_type->atomic_type = &BasicType::DOUBLE; }
415 { current_type->atomic_type = $1; }
423 | namespace_refs "::" T_ATOMIC_TYPE
426 search_namespace = 0;
434 search_namespace = $1;
437 | namespace_refs "::" T_NAMESPACEREF
439 search_namespace = $3;
445 __attribute__((noreturn))
446 void yyerror(const char* error)
448 throw ParseError(error);