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 line " << yylineno << ": "
45 this->message = msg.str();
47 virtual ~ParseError() throw()
49 const char* what() const throw()
51 return message.c_str();
64 %token <atomic_type> T_ATOMIC_TYPE
65 %token <_namespace> T_NAMESPACEREF;
86 %type <_class> class_declaration
87 %type <function> function_declaration
88 %type <function> constructor_declaration;
89 %type <function> destructor_declaration;
91 %type <atomic_type> type_identifier
97 current_namespace = unit;
102 namespace_members: /* empty */
103 | namespace_members namespace_member
106 namespace_declaration:
109 Namespace* newNamespace = new Namespace();
110 newNamespace->name = $2;
112 current_namespace->add_namespace(newNamespace);
113 current_namespace = newNamespace;
115 namespace_members '}'
117 current_namespace = current_namespace->parent;
119 | T_NAMESPACE T_NAMESPACEREF '{'
121 current_namespace = $2;
123 namespace_members '}'
125 current_namespace = current_namespace->parent;
131 { current_namespace->add_type($1); }
132 | function_declaration
133 { current_namespace->functions.push_back($1); }
134 | namespace_declaration
140 current_class = new Class();
141 current_class->name = $2;
143 current_visibility = ClassMember::PROTECTED;
151 class_body: /* empty */
152 | class_body class_body_element
157 | constructor_declaration
159 $1->visibility = current_visibility;
160 current_class->members.push_back($1);
162 | destructor_declaration
164 $1->visibility = current_visibility;
165 current_class->members.push_back($1);
167 | function_declaration
169 $1->visibility = current_visibility;
170 current_class->members.push_back($1);
172 | variable_declaration
177 { current_visibility = ClassMember::PUBLIC; }
179 { current_visibility = ClassMember::PROTECTED; }
181 { current_visibility = ClassMember::PRIVATE; }
184 constructor_declaration:
187 currentFunction = new Function();
188 currentFunction->type = Function::CONSTRUCTOR;
191 parameter_list ')' ';'
193 $$ = currentFunction;
197 destructor_declaration:
200 currentFunction = new Function();
201 currentFunction->type = Function::DESTRUCTOR;
203 $$ = currentFunction;
207 variable_declaration:
211 function_declaration:
214 currentFunction = new Function();
215 currentFunction->type = Function::FUNCTION;
216 currentFunction->return_type = *($1);
218 currentFunction->name = $2;
221 parameter_list ')' ';'
223 $$ = currentFunction;
234 | parameters ',' parameter
241 parameter.type = *($1);
243 currentFunction->parameters.push_back(parameter);
248 parameter.type = *($1);
250 parameter.name = *($2);
252 currentFunction->parameters.push_back(parameter);
258 current_type = new Type();
260 prefix_type_modifiers atomic_type postfix_type_modifiers
266 prefix_type_modifiers:
268 | prefix_type_modifiers prefix_type_modifier
271 prefix_type_modifier:
278 postfix_type_modifiers:
280 | postfix_type_modifiers postfix_type_modifier
283 postfix_type_modifier:
285 { current_type->_const = true; }
287 { current_type->pointer++; }
289 { current_type->ref++; }
294 { current_type->atomic_type = &BasicType::VOID; }
296 { current_type->atomic_type = &BasicType::BOOL; }
298 { current_type->atomic_type = &BasicType::CHAR; }
300 { current_type->atomic_type = &BasicType::SHORT; }
302 { current_type->atomic_type = &BasicType::INT; }
304 { current_type->atomic_type = &BasicType::LONG; }
306 { current_type->atomic_type = &BasicType::FLOAT; }
308 { current_type->atomic_type = &BasicType::DOUBLE; }
310 { current_type->atomic_type = $1; }
316 // search for type in current compilation unit...
319 | namespace_refs "::" T_ATOMIC_TYPE
322 search_namespace = 0;
330 search_namespace = $1;
333 | namespace_refs "::" T_NAMESPACEREF
335 search_namespace = $3;
341 void yyerror(const char* error)
343 throw ParseError(error);