2 Copyright (C) 2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "generator.h"
21 int yylex(CodeGen *codegen);
22 void yyerror(CodeGen *codegen, const char *msg);
26 %parse-param {CodeGen *codegen}
27 %lex-param {CodeGen *codegen}
31 %token REGISTER_TYPE_BEGIN
32 SCOPE_RESOLUTION_OPERATOR
35 INSTRUCTIONS_ASSIGN_OPERATOR
36 INSTRUCTIONS_SEPARATOR
44 %token <Id> IDENTIFIER
45 %destructor { delete $$; } IDENTIFIER
47 %type <IdList> enum_list
48 %destructor { delete $$; } enum_list
50 %type <Id> optional_enum_id
51 %destructor { delete $$; } optional_enum_id
53 %type <HashMap> optional_instructions
54 %destructor { delete $$; } optional_instructions
56 %type <HashMap> instruction_list
57 %destructor { delete $$; } instruction_list
59 %type <Pair> instruction
60 %destructor { delete $$; } instruction
64 header: enum_def_list type_registrations_list;
67 enum_def_list: enum_def_list enum_def | enum_def | /*empty*/;
70 ENUM_KEYWORD IDENTIFIER LEFT_BRACE optional_instructions enum_list RIGHT_BRACE SEMICOLON
72 codegen->addEnum(*$5, *$4);
79 enum_list COMMA IDENTIFIER
87 $$ = new QList<QByteArray>();
93 type_registrations_list: type_registrations_list type_registration | type_registration | /*empty*/;
96 REGISTER_TYPE_BEGIN IDENTIFIER SCOPE_RESOLUTION_OPERATOR IDENTIFIER optional_enum_id REGISTER_TYPE_END optional_instructions
98 codegen->addTypeRegistration(*$2, *$4, *$5, *$7);
106 SCOPE_RESOLUTION_OPERATOR IDENTIFIER
112 $$ = new QByteArray();
116 optional_instructions:
117 INSTRUCTIONS_BEGIN instruction_list INSTRUCTIONS_END
123 $$ = new QHash<QByteArray, QByteArray>();
127 instruction_list INSTRUCTIONS_SEPARATOR instruction
130 $$->insert($3->first, $3->second);
135 $$ = new QHash<QByteArray, QByteArray>();
136 $$->insert($1->first, $1->second);
141 IDENTIFIER INSTRUCTIONS_ASSIGN_OPERATOR IDENTIFIER
143 $$ = new QPair<QByteArray, QByteArray>();
151 $$ = new QPair<QByteArray, QByteArray>();
159 void yyerror(CodeGen *codegen, const char *msg)
161 codegen->fatalError(msg);