1 
2 %{
3 /****************************************************************************
4 **
5 ** Copyright (C) 2016 The Qt Company Ltd.
6 ** Contact: https://www.qt.io/licensing/
7 **
8 ** This file is part of the QLALR tool of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
11 ** Commercial License Usage
12 ** Licensees holding valid commercial Qt licenses may use this file in
13 ** accordance with the commercial license agreement provided with the
14 ** Software or, alternatively, in accordance with the terms contained in
15 ** a written agreement between you and The Qt Company. For licensing terms
16 ** and conditions see https://www.qt.io/terms-conditions. For further
17 ** information use the contact form at https://www.qt.io/contact-us.
18 **
19 ** GNU General Public License Usage
20 ** Alternatively, this file may be used under the terms of the GNU
21 ** General Public License version 3 as published by the Free Software
22 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
23 ** included in the packaging of this file. Please review the following
24 ** information to ensure the GNU General Public License requirements will
25 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
26 **
27 ** $QT_END_LICENSE$
28 **
29 ****************************************************************************/
30 
31 #include <cassert>
32 #define YY_DECL int GLSLParser::nextToken()
33 %}
34 
35 %option noyywrap
36 
37 hex [0-9a-fA-F]
38 dec [1-9][0-9]*
39 oct [0-7]
40 digit [0-9]
41 
42 fract {digit}*\.{digit}+|{digit}+\.
43 exp [eE][+-]?{digit}+
44 
45 hexfract {hex}*\.{hex}+|{hex}+\.
46 binexp [pP][+-]?{digit}+
47 
48 icst ({dec}|0{oct}*|0[xX]{hex}+)
49 
50 %%
51 
52 [\n] { ++context.line; }
53 [ \t\r]+ { /* skip */ }
54 
55 "+=" { return ADD_ASSIGN; }
56 "&" { return AMPERSAND; }
57 "&=" { return AND_ASSIGN; }
58 "&&" { return AND_OP; }
59 "attribute" { return ATTRIBUTE; }
60 "!" { return BANG; }
61 "bool" { return BOOL; }
62 "true" { return BOOLCONSTANT; }
63 "false" { return BOOLCONSTANT; }
64 "break" { return BREAK; }
65 "bvec2" { return BVEC2; }
66 "bvec3" { return BVEC3; }
67 "bvec4" { return BVEC4; }
68 ":" { return COLON; }
69 "," { return COMMA; }
70 "const" { return CONST; }
71 "continue" { return CONTINUE; }
72 "-" { return DASH; }
73 "--" { return DEC_OP; }
74 "discard" { return DISCARD; }
75 "/=" { return DIV_ASSIGN; }
76 "do" { return DO; }
77 "." { return DOT; }
78 "else" { return ELSE; }
79 "=" { return EQUAL; }
80 "==" { return EQ_OP; }
81 "float" { return FLOAT; }
82 "for" { return FOR; }
83 ">=" { return GE_OP; }
84 "if" { return IF; }
85 "in" { return IN; }
86 "++" { return INC_OP; }
87 "inout" { return INOUT; }
88 "int" { return INT; }
89 "ivec2" { return IVEC2; }
90 "ivec3" { return IVEC3; }
91 "ivec4" { return IVEC4; }
92 "<" { return LEFT_ANGLE; }
93 "<<=" { return LEFT_ASSIGN; }
94 "{" { return LEFT_BRACE; }
95 "[" { return LEFT_BRACKET; }
96 "<<" { return LEFT_OP; }
97 "(" { return LEFT_PAREN; }
98 "<=" { return LE_OP; }
99 "mat2" { return MAT2; }
100 "mat3" { return MAT3; }
101 "mat4" { return MAT4; }
102 "%=" { return MOD_ASSIGN; }
103 "*=" { return MUL_ASSIGN; }
104 "!=" { return NE_OP; }
105 "|=" { return OR_ASSIGN; }
106 "||" { return OR_OP; }
107 "out" { return OUT; }
108 "%" { return PERCENT; }
109 "+" { return PLUS; }
110 "?" { return QUESTION; }
111 "return" { return RETURN; }
112 ">" { return RIGHT_ANGLE; }
113 ">>=" { return RIGHT_ASSIGN; }
114 "}" { return RIGHT_BRACE; }
115 "]" { return RIGHT_BRACKET; }
116 ">>" { return RIGHT_OP; }
117 ")" { return RIGHT_PAREN; }
118 "sampler1D" { return SAMPLER1D; }
119 "sampler1DShadow" { return SAMPLER1DSHADOW; }
120 "sampler2D" { return SAMPLER2D; }
121 "sampler2DShadow" { return SAMPLER2DSHADOW; }
122 "sampler3D" { return SAMPLER3D; }
123 "samplerCube" { return SAMPLERCUBE; }
124 ";" { return SEMICOLON; }
125 "/" { return SLASH; }
126 "*" { return STAR; }
127 "struct" { return STRUCT; }
128 "-=" { return SUB_ASSIGN; }
129 "~" { return TILDE; }
130 "uniform" { return UNIFORM; }
131 "varying" { return VARYING; }
132 "vec2" { return VEC2; }
133 "vec3" { return VEC3; }
134 "vec4" { return VEC4; }
135 "|" { return VERTICAL_BAR; }
136 "void" { return VOID; }
137 "while" { return WHILE; }
138 "^=" { return XOR_ASSIGN; }
139 "^" { return XOR_OP; }
140 "highp" { return HIGH_PRECISION; }
141 "mediump" { return MEDIUM_PRECISION; }
142 "lowp" { return LOW_PRECISION; }
143 
144 #[ \t]+[0-9]+.* {
145   char *eptr = 0;
146   context.line = (int) strtod(&yytext[1], &eptr);
147   QString fn = QString::fromUtf8(eptr).trimmed();
148   if (fn.length() > 2)
149     context.fileName = fn.mid(1, fn.length()-2);
150 }
151 
152 #.* {
153   /* skip */
154 }
155 
156 [_a-zA-Z][_a-zA-Z0-9]* {
157   yylval.s = intern (yytext);
158 
159   if (isTypename (yylval.s))
160     return TYPE_NAME;
161 
162   return IDENTIFIER;
163 }
164 
165 {icst} {
166   yylval.i = (int) strtol (yytext, 0, 0);
167   return INTCONSTANT;
168 }
169 
170 {icst}[uU] {
171   yylval.u = (unsigned) strtoul (yytext, 0, 0);
172   return INTCONSTANT;
173 }
174 
175 {icst}[uU][lL] {
176   yylval.ul = strtoul (yytext, 0, 0);
177   return INTCONSTANT;
178 }
179 
180 {icst}[lL][uU] {
181   yylval.ul = strtoul (yytext, 0, 0);
182   return INTCONSTANT;
183 }
184 
185 {icst}[lL] {
186   yylval.l = strtol (yytext, 0, 0);
187   return INTCONSTANT;
188 }
189 
190 {icst}[uU](ll|LL) {
191   yylval.l = strtoull (yytext, 0, 0);
192   return INTCONSTANT;
193 }
194 
195 {icst}(ll|LL) {
196   yylval.l = strtoll (yytext, 0, 0);
197   return INTCONSTANT;
198 }
199 
200 {icst}(ll|LL)[uU] {
201   yylval.l = strtoull (yytext, 0, 0);
202   return INTCONSTANT;
203 }
204 
205 {fract}{exp}?[flFL]? {
206   yylval.f = strtof (yytext, 0);
207   return FLOATCONSTANT;
208 }
209 
210 {digit}+{exp}[flFL]? {
211   yylval.f = strtof (yytext, 0);
212   return FLOATCONSTANT;
213 }
214 
215 0[xX]{hexfract}{binexp}[flFL]? {
216   yylval.f = strtof (yytext, 0);
217   return FLOATCONSTANT;
218 }
219 
220 0[xX]{hex}+{binexp}[flFL]? {
221   yylval.f = strtof (yytext, 0);
222   return FLOATCONSTANT;
223 }
224 
225 . {
226   fprintf (stderr, "invalid char: %d\n", yytext [0]);
227   return ERROR;
228 }
229 
230 
231 %%
232 
233