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: header expression | expression | /*empty*/;
66 expression : enum_def | type_registration;
69 ENUM_KEYWORD IDENTIFIER LEFT_BRACE optional_instructions enum_list RIGHT_BRACE SEMICOLON
71 codegen->addEnum(*$5, *$4);
78 enum_list COMMA IDENTIFIER
86 $$ = new QList<QByteArray>();
93 REGISTER_TYPE_BEGIN IDENTIFIER SCOPE_RESOLUTION_OPERATOR IDENTIFIER optional_enum_id REGISTER_TYPE_END optional_instructions
95 codegen->addTypeRegistration(*$2, *$4, *$5, *$7);
103 SCOPE_RESOLUTION_OPERATOR IDENTIFIER
109 $$ = new QByteArray();
113 optional_instructions:
114 INSTRUCTIONS_BEGIN instruction_list INSTRUCTIONS_END
120 $$ = new QHash<QByteArray, QByteArray>();
124 instruction_list INSTRUCTIONS_SEPARATOR instruction
127 $$->insert($3->first, $3->second);
132 $$ = new QHash<QByteArray, QByteArray>();
133 $$->insert($1->first, $1->second);
138 IDENTIFIER INSTRUCTIONS_ASSIGN_OPERATOR IDENTIFIER
140 $$ = new QPair<QByteArray, QByteArray>();
148 $$ = new QPair<QByteArray, QByteArray>();
156 void yyerror(CodeGen *codegen, const char *msg)
158 codegen->fatalError(msg);