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 #define YY_DECL int yylex(CodeGen *codegen)
22 void yyerror(CodeGen *codegen, const char *msg);
29 id [a-zA-Z][a-zA-Z_0-9]*
33 %x ENUM_EAT_ASSIGNMENT
44 <REGISTER_TYPE,ENUM,INSTRUCTION>{id} { yylval.Id = new QByteArray(yytext); return IDENTIFIER; }
46 QGLIB_REGISTER_TYPE\( { yy_push_state(REGISTER_TYPE); return REGISTER_TYPE_BEGIN; }
48 :: { return SCOPE_RESOLUTION_OPERATOR; }
49 \) { yy_pop_state(); return REGISTER_TYPE_END; }
51 . { yyerror(codegen, "Syntax error in QGLIB_REGISTER_TYPE"); }
54 enum { yy_push_state(ENUM); return ENUM_KEYWORD; }
56 \{ { return LEFT_BRACE; }
57 \} { return RIGHT_BRACE; }
59 = { yy_push_state(ENUM_EAT_ASSIGNMENT); }
60 ; { yy_pop_state(); return SEMICOLON; }
62 . { yyerror(codegen, "Syntax error in enum definition"); }
65 <ENUM_EAT_ASSIGNMENT>{
66 , { unput(','); yy_pop_state(); }
67 \} { unput('}'); yy_pop_state(); }
72 <*>\/\/ { yy_push_state(LINE_COMMENT); }
74 \n { yy_pop_state(); }
75 codegen: { yy_push_state(INSTRUCTION); return INSTRUCTIONS_BEGIN; }
80 \n { unput('\n'); yy_pop_state(); return INSTRUCTIONS_END; }
81 = { return INSTRUCTIONS_ASSIGN_OPERATOR; }
82 , { return INSTRUCTIONS_SEPARATOR; }
84 . { yyerror(codegen, "Syntax error in instruction comment"); }
87 <*>\/\* { yy_push_state(C_STYLE_COMMENT); }
89 \*\/ { yy_pop_state(); }
94 namespace { yy_push_state(NAMESPACE); }
96 {id} { codegen->setCurrentNameSpace(yytext); yy_pop_state(); }
98 . { yyerror(codegen, "Expected identifier after namespace keyword"); }
101 class { yy_push_state(CLASS); }
103 {id} { codegen->setCurrentClass(yytext); yy_pop_state(); }
105 . { yyerror(codegen, "Expected identifier after class keyword"); }
108 template[[:space:]]*\< { yy_push_state(EAT_TEMPLATE); }
110 \< { yy_push_state(EAT_TEMPLATE); };
111 \> { yy_pop_state(); }
116 /* Eats only one-line defines. Used to eat the #define QGLIB_REGISTER_TYPE(T),
117 which would be a syntax error for codegen otherwise. */
118 #define { yy_push_state(MACRO); }
120 \n { yy_pop_state(); }
124 <*><<EOF>> { return EOF; }