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
89 %type <_class> class_declaration
90 %type <function> function_declaration
91 %type <function> constructor_declaration;
92 %type <function> destructor_declaration;
93 %type <field> field_declaration;
95 %type <atomic_type> type_identifier
101 current_namespace = unit;
106 namespace_members: /* empty */
107 | namespace_members namespace_member
110 namespace_declaration:
113 Namespace* newNamespace = new Namespace();
114 newNamespace->name = $2;
116 current_namespace->add_namespace(newNamespace);
117 current_namespace = newNamespace;
119 namespace_members '}'
121 current_namespace = current_namespace->parent;
123 | T_NAMESPACE T_NAMESPACEREF '{'
125 current_namespace = $2;
127 namespace_members '}'
129 current_namespace = current_namespace->parent;
135 { current_namespace->add_type($1); }
136 | function_declaration
137 { current_namespace->functions.push_back($1); }
138 | namespace_declaration
140 { current_namespace->fields.push_back($1); }
146 current_class = new Class();
147 current_class->name = $2;
149 current_class->docu_comment = last_docucomment;
150 last_docucomment = "";
151 current_visibility = ClassMember::PROTECTED;
153 superclass_list '{' class_body '}' ';'
166 | superclasses ',' superclass
170 superclass_visibility type_identifier
172 Class* superclass = dynamic_cast<Class*> ($2);
174 throw ParseError("SuperClass is not a Class type");
175 current_class->super_classes.push_back(superclass);
176 superclass->sub_classes.push_back(current_class);
180 superclass_visibility:
186 class_body: /* empty */
187 | class_body class_body_element
192 | constructor_declaration
194 $1->visibility = current_visibility;
195 current_class->members.push_back($1);
197 | destructor_declaration
199 $1->visibility = current_visibility;
200 current_class->members.push_back($1);
202 | function_declaration
204 $1->visibility = current_visibility;
205 current_class->members.push_back($1);
209 $1->visibility = current_visibility;
210 current_class->members.push_back($1);
216 { current_visibility = ClassMember::PUBLIC; }
218 { current_visibility = ClassMember::PROTECTED; }
220 { current_visibility = ClassMember::PRIVATE; }
223 constructor_declaration:
226 current_function = new Function();
227 current_function->type = Function::CONSTRUCTOR;
228 current_function->docu_comment = last_docucomment;
229 last_docucomment = "";
232 parameter_list ')' ';'
234 $$ = current_function;
238 destructor_declaration:
239 '~' T_ID '(' ')' abstract_declaration ';'
241 current_function = new Function();
242 current_function->type = Function::DESTRUCTOR;
243 current_function->docu_comment = last_docucomment;
244 last_docucomment = "";
246 $$ = current_function;
253 current_field = new Field();
254 current_field->type = $1;
255 current_field->docu_comment = last_docucomment;
256 last_docucomment = "";
257 current_field->name = $2;
260 maybe_const_initialisation ';'
266 maybe_const_initialisation:
270 if(current_field->type->atomic_type == &BasicType::FLOAT) {
271 current_field->const_float_value = (float) $2;
273 current_field->const_int_value = $2;
275 current_field->has_const_value = true;
279 current_field->const_float_value = $2;
280 current_field->has_const_value = true;
284 current_field->const_string_value = $2;
285 current_field->has_const_value = true;
289 function_declaration:
292 current_function = new Function();
293 current_function->type = Function::FUNCTION;
294 current_function->return_type = *($1);
296 current_function->name = $2;
298 current_function->docu_comment = last_docucomment;
299 last_docucomment = "";
301 parameter_list ')' maybe_const abstract_declaration ';'
303 $$ = current_function;
312 abstract_declaration:
324 | parameters ',' parameter
331 parameter.type = *($1);
333 current_function->parameters.push_back(parameter);
338 parameter.type = *($1);
342 current_function->parameters.push_back(parameter);
348 current_type = new Type();
350 prefix_type_modifiers atomic_type postfix_type_modifiers
356 prefix_type_modifiers:
358 | prefix_type_modifiers prefix_type_modifier
361 prefix_type_modifier:
363 { current_type->_unsigned = true; }
365 { current_type->_unsigned = false; }
367 { current_type->_static = true; }
369 { current_type->_const = true; }
372 postfix_type_modifiers:
374 | postfix_type_modifiers postfix_type_modifier
377 postfix_type_modifier:
379 { current_type->_const = true; }
381 { current_type->pointer++; }
383 { current_type->ref++; }
388 { current_type->atomic_type = &BasicType::VOID; }
390 { current_type->atomic_type = &BasicType::BOOL; }
392 { current_type->atomic_type = &BasicType::CHAR; }
394 { current_type->atomic_type = &BasicType::SHORT; }
396 { current_type->atomic_type = &BasicType::INT; }
398 { current_type->atomic_type = &BasicType::LONG; }
400 { current_type->atomic_type = &BasicType::FLOAT; }
402 { current_type->atomic_type = &BasicType::DOUBLE; }
404 { current_type->atomic_type = $1; }
412 | namespace_refs "::" T_ATOMIC_TYPE
415 search_namespace = 0;
423 search_namespace = $1;
426 | namespace_refs "::" T_NAMESPACEREF
428 search_namespace = $3;
434 void yyerror(const char* error)
436 throw ParseError(error);