19 AtomicType* atomic_type;
20 Namespace* _namespace;
25 extern int yylex(YYSTYPE* yylval);
26 void yyerror(const char* s);
29 bool search_down = true;
30 Namespace* search_namespace = 0;
31 Namespace* current_namespace = 0;
32 static Class* current_class = 0;
33 static Function* currentFunction = 0;
34 static Type* current_type = 0;
35 static ClassMember::Visbility current_visibility;
37 class ParseError : public std::exception
40 ParseError(const std::string& message) throw()
42 std::ostringstream msg;
43 msg << "Parse error in '" << current_file
44 << "' line " << getCurrentLine() << ": "
46 this->message = msg.str();
48 virtual ~ParseError() throw()
50 const char* what() const throw()
52 return message.c_str();
65 %token <atomic_type> T_ATOMIC_TYPE
66 %token <_namespace> T_NAMESPACEREF
88 %type <_class> class_declaration
89 %type <function> function_declaration
90 %type <function> constructor_declaration;
91 %type <function> destructor_declaration;
93 %type <atomic_type> type_identifier
99 current_namespace = unit;
104 namespace_members: /* empty */
105 | namespace_members namespace_member
108 namespace_declaration:
111 Namespace* newNamespace = new Namespace();
112 newNamespace->name = $2;
114 current_namespace->add_namespace(newNamespace);
115 current_namespace = newNamespace;
117 namespace_members '}'
119 current_namespace = current_namespace->parent;
121 | T_NAMESPACE T_NAMESPACEREF '{'
123 current_namespace = $2;
125 namespace_members '}'
127 current_namespace = current_namespace->parent;
133 { current_namespace->add_type($1); }
134 | function_declaration
135 { current_namespace->functions.push_back($1); }
136 | namespace_declaration
142 current_class = new Class();
143 current_class->name = $2;
145 current_class->docu_comment = last_docucomment;
146 last_docucomment = "";
147 current_visibility = ClassMember::PROTECTED;
155 class_body: /* empty */
156 | class_body class_body_element
161 | constructor_declaration
163 $1->visibility = current_visibility;
164 current_class->members.push_back($1);
166 | destructor_declaration
168 $1->visibility = current_visibility;
169 current_class->members.push_back($1);
171 | function_declaration
173 $1->visibility = current_visibility;
174 current_class->members.push_back($1);
176 | variable_declaration
181 { current_visibility = ClassMember::PUBLIC; }
183 { current_visibility = ClassMember::PROTECTED; }
185 { current_visibility = ClassMember::PRIVATE; }
188 constructor_declaration:
191 currentFunction = new Function();
192 currentFunction->type = Function::CONSTRUCTOR;
193 currentFunction->docu_comment = last_docucomment;
194 last_docucomment = "";
197 parameter_list ')' ';'
199 $$ = currentFunction;
203 destructor_declaration:
204 maybe_virtual '~' T_ID '(' ')' abstract_declaration ';'
206 currentFunction = new Function();
207 currentFunction->type = Function::DESTRUCTOR;
208 currentFunction->docu_comment = last_docucomment;
209 last_docucomment = "";
211 $$ = currentFunction;
220 variable_declaration:
224 function_declaration:
225 maybe_virtual type T_ID '('
227 currentFunction = new Function();
228 currentFunction->type = Function::FUNCTION;
229 currentFunction->return_type = *($2);
231 currentFunction->name = $3;
233 currentFunction->docu_comment = last_docucomment;
234 last_docucomment = "";
236 parameter_list ')' abstract_declaration ';'
238 $$ = currentFunction;
242 abstract_declaration:
254 | parameters ',' parameter
261 parameter.type = *($1);
263 currentFunction->parameters.push_back(parameter);
268 parameter.type = *($1);
270 parameter.name = *($2);
272 currentFunction->parameters.push_back(parameter);
278 current_type = new Type();
280 prefix_type_modifiers atomic_type postfix_type_modifiers
286 prefix_type_modifiers:
288 | prefix_type_modifiers prefix_type_modifier
291 prefix_type_modifier:
293 { current_type->_unsigned = true; }
295 { current_type->_unsigned = false; }
297 { current_type->_static = true; }
299 { current_type->_const = true; }
302 postfix_type_modifiers:
304 | postfix_type_modifiers postfix_type_modifier
307 postfix_type_modifier:
309 { current_type->_const = true; }
311 { current_type->pointer++; }
313 { current_type->ref++; }
318 { current_type->atomic_type = &BasicType::VOID; }
320 { current_type->atomic_type = &BasicType::BOOL; }
322 { current_type->atomic_type = &BasicType::CHAR; }
324 { current_type->atomic_type = &BasicType::SHORT; }
326 { current_type->atomic_type = &BasicType::INT; }
328 { current_type->atomic_type = &BasicType::LONG; }
330 { current_type->atomic_type = &BasicType::FLOAT; }
332 { current_type->atomic_type = &BasicType::DOUBLE; }
334 { current_type->atomic_type = $1; }
340 // search for type in current compilation unit...
343 | namespace_refs "::" T_ATOMIC_TYPE
346 search_namespace = 0;
354 search_namespace = $1;
357 | namespace_refs "::" T_NAMESPACEREF
359 search_namespace = $3;
365 void yyerror(const char* error)
367 throw ParseError(error);