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::Visbility 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
92 %type <_class> class_declaration
93 %type <function> function_declaration
94 %type <function> constructor_declaration;
95 %type <function> destructor_declaration;
96 %type <field> field_declaration;
98 %type <atomic_type> type_identifier
104 current_namespace = unit;
109 namespace_members: /* empty */
110 | namespace_members namespace_member
113 namespace_declaration:
116 Namespace* newNamespace = new Namespace();
117 newNamespace->name = $2;
119 current_namespace->add_namespace(newNamespace);
120 current_namespace = newNamespace;
122 namespace_members '}'
124 current_namespace = current_namespace->parent;
126 | T_NAMESPACE T_NAMESPACEREF '{'
128 current_namespace = $2;
130 namespace_members '}'
132 current_namespace = current_namespace->parent;
138 { current_namespace->add_type($1); }
139 | function_declaration
140 { current_namespace->functions.push_back($1); }
141 | namespace_declaration
143 { current_namespace->fields.push_back($1); }
149 current_class = new Class();
150 current_class->name = $2;
152 current_class->docu_comment = last_docucomment;
153 last_docucomment = "";
154 current_visibility = ClassMember::PROTECTED;
156 superclass_list '{' class_body '}' ';'
169 | superclasses ',' superclass
173 superclass_visibility type_identifier
175 Class* superclass = dynamic_cast<Class*> ($2);
177 throw ParseError("SuperClass is not a Class type");
178 current_class->super_classes.push_back(superclass);
179 superclass->sub_classes.push_back(current_class);
183 superclass_visibility:
189 class_body: /* empty */
190 | class_body class_body_element
195 | constructor_declaration
197 $1->visibility = current_visibility;
198 current_class->members.push_back($1);
200 | destructor_declaration
202 $1->visibility = current_visibility;
203 current_class->members.push_back($1);
205 | function_declaration
207 $1->visibility = current_visibility;
208 current_class->members.push_back($1);
212 $1->visibility = current_visibility;
213 current_class->members.push_back($1);
219 { current_visibility = ClassMember::PUBLIC; }
221 { current_visibility = ClassMember::PROTECTED; }
223 { current_visibility = ClassMember::PRIVATE; }
226 constructor_declaration:
229 current_function = new Function();
230 current_function->type = Function::CONSTRUCTOR;
231 current_function->docu_comment = last_docucomment;
232 last_docucomment = "";
235 parameter_list ')' ';'
237 $$ = current_function;
241 destructor_declaration:
242 '~' T_ID '(' ')' abstract_declaration ';'
244 current_function = new Function();
245 current_function->type = Function::DESTRUCTOR;
246 current_function->docu_comment = last_docucomment;
247 last_docucomment = "";
249 $$ = current_function;
256 current_field = new Field();
257 current_field->type = $1;
258 current_field->docu_comment = last_docucomment;
259 last_docucomment = "";
260 current_field->name = $2;
263 maybe_const_initialisation ';'
269 maybe_const_initialisation:
273 if(current_field->type->atomic_type == &BasicType::FLOAT) {
274 current_field->const_float_value = (float) $2;
276 current_field->const_int_value = $2;
278 current_field->has_const_value = true;
282 current_field->const_float_value = $2;
283 current_field->has_const_value = true;
287 current_field->const_string_value = $2;
288 current_field->has_const_value = true;
292 function_declaration:
295 current_function = new Function();
296 current_function->type = Function::FUNCTION;
297 current_function->return_type = *($1);
299 current_function->name = $2;
301 current_function->docu_comment = last_docucomment;
302 last_docucomment = "";
304 parameter_list ')' function_attributes abstract_declaration ';'
306 $$ = current_function;
312 | T_CONST function_attributes
313 | T_CUSTOM function_attributes
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 void yyerror(const char* error)
447 throw ParseError(error);