swrast: Remove unused solve_plane_recip().
[mesa.git] / src / glsl / glsl_lexer.ll
1 %{
2 /*
3 * Copyright © 2008, 2009 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24 #include <ctype.h>
25 #include <limits.h>
26 #include "strtod.h"
27 #include "ast.h"
28 #include "glsl_parser_extras.h"
29 #include "glsl_parser.h"
30
31 static int classify_identifier(struct _mesa_glsl_parse_state *, const char *);
32
33 #ifdef _MSC_VER
34 #define YY_NO_UNISTD_H
35 #endif
36
37 #define YY_USER_ACTION \
38 do { \
39 yylloc->source = 0; \
40 yylloc->first_column = yycolumn + 1; \
41 yylloc->first_line = yylloc->last_line = yylineno + 1; \
42 yycolumn += yyleng; \
43 yylloc->last_column = yycolumn + 1; \
44 } while(0);
45
46 #define YY_USER_INIT yylineno = 0; yycolumn = 0;
47
48 /* A macro for handling reserved words and keywords across language versions.
49 *
50 * Certain words start out as identifiers, become reserved words in
51 * later language revisions, and finally become language keywords.
52 * This may happen at different times in desktop GLSL and GLSL ES.
53 *
54 * For example, consider the following lexer rule:
55 * samplerBuffer KEYWORD(130, 0, 140, 0, SAMPLERBUFFER)
56 *
57 * This means that "samplerBuffer" will be treated as:
58 * - a keyword (SAMPLERBUFFER token) ...in GLSL >= 1.40
59 * - a reserved word - error ...in GLSL >= 1.30
60 * - an identifier ...in GLSL < 1.30 or GLSL ES
61 */
62 #define KEYWORD(reserved_glsl, reserved_glsl_es, \
63 allowed_glsl, allowed_glsl_es, token) \
64 KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \
65 allowed_glsl, allowed_glsl_es, false, token)
66
67 /**
68 * Like the KEYWORD macro, but the word is also treated as a keyword
69 * if the given boolean expression is true.
70 */
71 #define KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \
72 allowed_glsl, allowed_glsl_es, \
73 alt_expr, token) \
74 do { \
75 if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \
76 || (alt_expr)) { \
77 return token; \
78 } else if (yyextra->is_version(reserved_glsl, \
79 reserved_glsl_es)) { \
80 _mesa_glsl_error(yylloc, yyextra, \
81 "illegal use of reserved word `%s'", yytext); \
82 return ERROR_TOK; \
83 } else { \
84 yylval->identifier = strdup(yytext); \
85 return classify_identifier(yyextra, yytext); \
86 } \
87 } while (0)
88
89 /**
90 * A macro for handling keywords that have been present in GLSL since
91 * its origin, but were changed into reserved words in GLSL 3.00 ES.
92 */
93 #define DEPRECATED_ES_KEYWORD(token) \
94 do { \
95 if (yyextra->is_version(0, 300)) { \
96 _mesa_glsl_error(yylloc, yyextra, \
97 "illegal use of reserved word `%s'", yytext); \
98 return ERROR_TOK; \
99 } else { \
100 return token; \
101 } \
102 } while (0)
103
104 static int
105 literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state,
106 YYSTYPE *lval, YYLTYPE *lloc, int base)
107 {
108 bool is_uint = (text[len - 1] == 'u' ||
109 text[len - 1] == 'U');
110 const char *digits = text;
111
112 /* Skip "0x" */
113 if (base == 16)
114 digits += 2;
115
116 #ifdef _MSC_VER
117 unsigned __int64 value = _strtoui64(digits, NULL, base);
118 #else
119 unsigned long long value = strtoull(digits, NULL, base);
120 #endif
121
122 lval->n = (int)value;
123
124 if (value > UINT_MAX) {
125 /* Note that signed 0xffffffff is valid, not out of range! */
126 if (state->is_version(130, 300)) {
127 _mesa_glsl_error(lloc, state,
128 "literal value `%s' out of range", text);
129 } else {
130 _mesa_glsl_warning(lloc, state,
131 "literal value `%s' out of range", text);
132 }
133 } else if (base == 10 && !is_uint && (unsigned)value > (unsigned)INT_MAX + 1) {
134 /* Tries to catch unintentionally providing a negative value.
135 * Note that -2147483648 is parsed as -(2147483648), so we don't
136 * want to warn for INT_MAX.
137 */
138 _mesa_glsl_warning(lloc, state,
139 "signed literal value `%s' is interpreted as %d",
140 text, lval->n);
141 }
142 return is_uint ? UINTCONSTANT : INTCONSTANT;
143 }
144
145 #define LITERAL_INTEGER(base) \
146 literal_integer(yytext, yyleng, yyextra, yylval, yylloc, base)
147
148 %}
149
150 %option bison-bridge bison-locations reentrant noyywrap
151 %option nounput noyy_top_state
152 %option never-interactive
153 %option prefix="_mesa_glsl_lexer_"
154 %option extra-type="struct _mesa_glsl_parse_state *"
155
156 %x PP PRAGMA
157
158 DEC_INT [1-9][0-9]*
159 HEX_INT 0[xX][0-9a-fA-F]+
160 OCT_INT 0[0-7]*
161 INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
162 SPC [ \t]*
163 SPCP [ \t]+
164 HASH ^{SPC}#{SPC}
165 %%
166
167 [ \r\t]+ ;
168
169 /* Preprocessor tokens. */
170 ^[ \t]*#[ \t]*$ ;
171 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION_TOK; }
172 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
173 {HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ {
174 /* Eat characters until the first digit is
175 * encountered
176 */
177 char *ptr = yytext;
178 while (!isdigit(*ptr))
179 ptr++;
180
181 /* Subtract one from the line number because
182 * yylineno is zero-based instead of
183 * one-based.
184 */
185 yylineno = strtol(ptr, &ptr, 0) - 1;
186 yylloc->source = strtol(ptr, NULL, 0);
187 }
188 {HASH}line{SPCP}{INT}{SPC}$ {
189 /* Eat characters until the first digit is
190 * encountered
191 */
192 char *ptr = yytext;
193 while (!isdigit(*ptr))
194 ptr++;
195
196 /* Subtract one from the line number because
197 * yylineno is zero-based instead of
198 * one-based.
199 */
200 yylineno = strtol(ptr, &ptr, 0) - 1;
201 }
202 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) {
203 BEGIN PP;
204 return PRAGMA_DEBUG_ON;
205 }
206 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) {
207 BEGIN PP;
208 return PRAGMA_DEBUG_OFF;
209 }
210 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) {
211 BEGIN PP;
212 return PRAGMA_OPTIMIZE_ON;
213 }
214 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) {
215 BEGIN PP;
216 return PRAGMA_OPTIMIZE_OFF;
217 }
218 ^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) {
219 BEGIN PP;
220 return PRAGMA_INVARIANT_ALL;
221 }
222 ^{SPC}#{SPC}pragma{SPCP} { BEGIN PRAGMA; }
223
224 <PRAGMA>\n { BEGIN 0; yylineno++; yycolumn = 0; }
225 <PRAGMA>. { }
226
227 <PP>\/\/[^\n]* { }
228 <PP>[ \t\r]* { }
229 <PP>: return COLON;
230 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
231 yylval->identifier = strdup(yytext);
232 return IDENTIFIER;
233 }
234 <PP>[1-9][0-9]* {
235 yylval->n = strtol(yytext, NULL, 10);
236 return INTCONSTANT;
237 }
238 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
239
240 \n { yylineno++; yycolumn = 0; }
241
242 attribute DEPRECATED_ES_KEYWORD(ATTRIBUTE);
243 const return CONST_TOK;
244 bool return BOOL_TOK;
245 float return FLOAT_TOK;
246 int return INT_TOK;
247 uint KEYWORD(130, 300, 130, 300, UINT_TOK);
248
249 break return BREAK;
250 continue return CONTINUE;
251 do return DO;
252 while return WHILE;
253 else return ELSE;
254 for return FOR;
255 if return IF;
256 discard return DISCARD;
257 return return RETURN;
258
259 bvec2 return BVEC2;
260 bvec3 return BVEC3;
261 bvec4 return BVEC4;
262 ivec2 return IVEC2;
263 ivec3 return IVEC3;
264 ivec4 return IVEC4;
265 uvec2 KEYWORD(130, 300, 130, 300, UVEC2);
266 uvec3 KEYWORD(130, 300, 130, 300, UVEC3);
267 uvec4 KEYWORD(130, 300, 130, 300, UVEC4);
268 vec2 return VEC2;
269 vec3 return VEC3;
270 vec4 return VEC4;
271 mat2 return MAT2X2;
272 mat3 return MAT3X3;
273 mat4 return MAT4X4;
274 mat2x2 KEYWORD(120, 300, 120, 300, MAT2X2);
275 mat2x3 KEYWORD(120, 300, 120, 300, MAT2X3);
276 mat2x4 KEYWORD(120, 300, 120, 300, MAT2X4);
277 mat3x2 KEYWORD(120, 300, 120, 300, MAT3X2);
278 mat3x3 KEYWORD(120, 300, 120, 300, MAT3X3);
279 mat3x4 KEYWORD(120, 300, 120, 300, MAT3X4);
280 mat4x2 KEYWORD(120, 300, 120, 300, MAT4X2);
281 mat4x3 KEYWORD(120, 300, 120, 300, MAT4X3);
282 mat4x4 KEYWORD(120, 300, 120, 300, MAT4X4);
283
284 in return IN_TOK;
285 out return OUT_TOK;
286 inout return INOUT_TOK;
287 uniform return UNIFORM;
288 varying DEPRECATED_ES_KEYWORD(VARYING);
289 centroid KEYWORD(120, 300, 120, 300, CENTROID);
290 invariant KEYWORD(120, 100, 120, 100, INVARIANT);
291 flat KEYWORD(130, 100, 130, 300, FLAT);
292 smooth KEYWORD(130, 300, 130, 300, SMOOTH);
293 noperspective KEYWORD(130, 300, 130, 0, NOPERSPECTIVE);
294
295 sampler1D DEPRECATED_ES_KEYWORD(SAMPLER1D);
296 sampler2D return SAMPLER2D;
297 sampler3D return SAMPLER3D;
298 samplerCube return SAMPLERCUBE;
299 sampler1DArray KEYWORD(130, 300, 130, 0, SAMPLER1DARRAY);
300 sampler2DArray KEYWORD(130, 300, 130, 300, SAMPLER2DARRAY);
301 sampler1DShadow DEPRECATED_ES_KEYWORD(SAMPLER1DSHADOW);
302 sampler2DShadow return SAMPLER2DSHADOW;
303 samplerCubeShadow KEYWORD(130, 300, 130, 300, SAMPLERCUBESHADOW);
304 sampler1DArrayShadow KEYWORD(130, 300, 130, 0, SAMPLER1DARRAYSHADOW);
305 sampler2DArrayShadow KEYWORD(130, 300, 130, 300, SAMPLER2DARRAYSHADOW);
306 isampler1D KEYWORD(130, 300, 130, 0, ISAMPLER1D);
307 isampler2D KEYWORD(130, 300, 130, 300, ISAMPLER2D);
308 isampler3D KEYWORD(130, 300, 130, 300, ISAMPLER3D);
309 isamplerCube KEYWORD(130, 300, 130, 300, ISAMPLERCUBE);
310 isampler1DArray KEYWORD(130, 300, 130, 0, ISAMPLER1DARRAY);
311 isampler2DArray KEYWORD(130, 300, 130, 300, ISAMPLER2DARRAY);
312 usampler1D KEYWORD(130, 300, 130, 0, USAMPLER1D);
313 usampler2D KEYWORD(130, 300, 130, 300, USAMPLER2D);
314 usampler3D KEYWORD(130, 300, 130, 300, USAMPLER3D);
315 usamplerCube KEYWORD(130, 300, 130, 300, USAMPLERCUBE);
316 usampler1DArray KEYWORD(130, 300, 130, 0, USAMPLER1DARRAY);
317 usampler2DArray KEYWORD(130, 300, 130, 300, USAMPLER2DARRAY);
318
319 /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */
320 /* these are reserved but not defined in GLSL 3.00 */
321 sampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMS);
322 isampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMS);
323 usampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMS);
324 sampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMSARRAY);
325 isampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMSARRAY);
326 usampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMSARRAY);
327
328 /* keywords available with ARB_texture_cube_map_array_enable extension on desktop GLSL */
329 samplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, SAMPLERCUBEARRAY);
330 isamplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, ISAMPLERCUBEARRAY);
331 usamplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, USAMPLERCUBEARRAY);
332 samplerCubeArrayShadow KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, SAMPLERCUBEARRAYSHADOW);
333
334 samplerExternalOES {
335 if (yyextra->OES_EGL_image_external_enable)
336 return SAMPLEREXTERNALOES;
337 else
338 return IDENTIFIER;
339 }
340
341 /* keywords available with ARB_gpu_shader5 */
342 precise KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_gpu_shader5_enable, PRECISE);
343
344 /* keywords available with ARB_shader_image_load_store */
345 image1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE1D);
346 image2D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2D);
347 image3D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE3D);
348 image2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DRECT);
349 imageCube KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGECUBE);
350 imageBuffer KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGEBUFFER);
351 image1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE1DARRAY);
352 image2DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DARRAY);
353 imageCubeArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGECUBEARRAY);
354 image2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DMS);
355 image2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DMSARRAY);
356 iimage1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE1D);
357 iimage2D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2D);
358 iimage3D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE3D);
359 iimage2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DRECT);
360 iimageCube KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGECUBE);
361 iimageBuffer KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGEBUFFER);
362 iimage1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE1DARRAY);
363 iimage2DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DARRAY);
364 iimageCubeArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGECUBEARRAY);
365 iimage2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DMS);
366 iimage2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DMSARRAY);
367 uimage1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE1D);
368 uimage2D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2D);
369 uimage3D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE3D);
370 uimage2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DRECT);
371 uimageCube KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGECUBE);
372 uimageBuffer KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGEBUFFER);
373 uimage1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE1DARRAY);
374 uimage2DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DARRAY);
375 uimageCubeArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGECUBEARRAY);
376 uimage2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DMS);
377 uimage2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DMSARRAY);
378 image1DShadow KEYWORD(130, 300, 0, 0, IMAGE1DSHADOW);
379 image2DShadow KEYWORD(130, 300, 0, 0, IMAGE2DSHADOW);
380 image1DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE1DARRAYSHADOW);
381 image2DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE2DARRAYSHADOW);
382
383 coherent KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, COHERENT);
384 volatile KEYWORD_WITH_ALT(110, 100, 420, 0, yyextra->ARB_shader_image_load_store_enable, VOLATILE);
385 restrict KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, RESTRICT);
386 readonly KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, READONLY);
387 writeonly KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, WRITEONLY);
388
389 atomic_uint KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_atomic_counters_enable, ATOMIC_UINT);
390
391 struct return STRUCT;
392 void return VOID_TOK;
393
394 layout {
395 if ((yyextra->is_version(140, 300))
396 || yyextra->AMD_conservative_depth_enable
397 || yyextra->ARB_conservative_depth_enable
398 || yyextra->ARB_explicit_attrib_location_enable
399 || yyextra->ARB_explicit_uniform_location_enable
400 || yyextra->has_separate_shader_objects()
401 || yyextra->ARB_uniform_buffer_object_enable
402 || yyextra->ARB_fragment_coord_conventions_enable
403 || yyextra->ARB_shading_language_420pack_enable
404 || yyextra->ARB_compute_shader_enable) {
405 return LAYOUT_TOK;
406 } else {
407 yylval->identifier = strdup(yytext);
408 return classify_identifier(yyextra, yytext);
409 }
410 }
411
412 \+\+ return INC_OP;
413 -- return DEC_OP;
414 \<= return LE_OP;
415 >= return GE_OP;
416 == return EQ_OP;
417 != return NE_OP;
418 && return AND_OP;
419 \|\| return OR_OP;
420 "^^" return XOR_OP;
421 "<<" return LEFT_OP;
422 ">>" return RIGHT_OP;
423
424 \*= return MUL_ASSIGN;
425 \/= return DIV_ASSIGN;
426 \+= return ADD_ASSIGN;
427 \%= return MOD_ASSIGN;
428 \<\<= return LEFT_ASSIGN;
429 >>= return RIGHT_ASSIGN;
430 &= return AND_ASSIGN;
431 "^=" return XOR_ASSIGN;
432 \|= return OR_ASSIGN;
433 -= return SUB_ASSIGN;
434
435 [1-9][0-9]*[uU]? {
436 return LITERAL_INTEGER(10);
437 }
438 0[xX][0-9a-fA-F]+[uU]? {
439 return LITERAL_INTEGER(16);
440 }
441 0[0-7]*[uU]? {
442 return LITERAL_INTEGER(8);
443 }
444
445 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
446 yylval->real = glsl_strtof(yytext, NULL);
447 return FLOATCONSTANT;
448 }
449 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
450 yylval->real = glsl_strtof(yytext, NULL);
451 return FLOATCONSTANT;
452 }
453 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
454 yylval->real = glsl_strtof(yytext, NULL);
455 return FLOATCONSTANT;
456 }
457 [0-9]+[eE][+-]?[0-9]+[fF]? {
458 yylval->real = glsl_strtof(yytext, NULL);
459 return FLOATCONSTANT;
460 }
461 [0-9]+[fF] {
462 yylval->real = glsl_strtof(yytext, NULL);
463 return FLOATCONSTANT;
464 }
465
466 true {
467 yylval->n = 1;
468 return BOOLCONSTANT;
469 }
470 false {
471 yylval->n = 0;
472 return BOOLCONSTANT;
473 }
474
475
476 /* Reserved words in GLSL 1.10. */
477 asm KEYWORD(110, 100, 0, 0, ASM);
478 class KEYWORD(110, 100, 0, 0, CLASS);
479 union KEYWORD(110, 100, 0, 0, UNION);
480 enum KEYWORD(110, 100, 0, 0, ENUM);
481 typedef KEYWORD(110, 100, 0, 0, TYPEDEF);
482 template KEYWORD(110, 100, 0, 0, TEMPLATE);
483 this KEYWORD(110, 100, 0, 0, THIS);
484 packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK);
485 goto KEYWORD(110, 100, 0, 0, GOTO);
486 switch KEYWORD(110, 100, 130, 300, SWITCH);
487 default KEYWORD(110, 100, 130, 300, DEFAULT);
488 inline KEYWORD(110, 100, 0, 0, INLINE_TOK);
489 noinline KEYWORD(110, 100, 0, 0, NOINLINE);
490 public KEYWORD(110, 100, 0, 0, PUBLIC_TOK);
491 static KEYWORD(110, 100, 0, 0, STATIC);
492 extern KEYWORD(110, 100, 0, 0, EXTERN);
493 external KEYWORD(110, 100, 0, 0, EXTERNAL);
494 interface KEYWORD(110, 100, 0, 0, INTERFACE);
495 long KEYWORD(110, 100, 0, 0, LONG_TOK);
496 short KEYWORD(110, 100, 0, 0, SHORT_TOK);
497 double KEYWORD(110, 100, 400, 0, DOUBLE_TOK);
498 half KEYWORD(110, 100, 0, 0, HALF);
499 fixed KEYWORD(110, 100, 0, 0, FIXED_TOK);
500 unsigned KEYWORD(110, 100, 0, 0, UNSIGNED);
501 input KEYWORD(110, 100, 0, 0, INPUT_TOK);
502 output KEYWORD(110, 100, 0, 0, OUTPUT);
503 hvec2 KEYWORD(110, 100, 0, 0, HVEC2);
504 hvec3 KEYWORD(110, 100, 0, 0, HVEC3);
505 hvec4 KEYWORD(110, 100, 0, 0, HVEC4);
506 dvec2 KEYWORD(110, 100, 400, 0, DVEC2);
507 dvec3 KEYWORD(110, 100, 400, 0, DVEC3);
508 dvec4 KEYWORD(110, 100, 400, 0, DVEC4);
509 fvec2 KEYWORD(110, 100, 0, 0, FVEC2);
510 fvec3 KEYWORD(110, 100, 0, 0, FVEC3);
511 fvec4 KEYWORD(110, 100, 0, 0, FVEC4);
512 sampler2DRect DEPRECATED_ES_KEYWORD(SAMPLER2DRECT);
513 sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT);
514 sampler2DRectShadow DEPRECATED_ES_KEYWORD(SAMPLER2DRECTSHADOW);
515 sizeof KEYWORD(110, 100, 0, 0, SIZEOF);
516 cast KEYWORD(110, 100, 0, 0, CAST);
517 namespace KEYWORD(110, 100, 0, 0, NAMESPACE);
518 using KEYWORD(110, 100, 0, 0, USING);
519
520 /* Additional reserved words in GLSL 1.20. */
521 lowp KEYWORD(120, 100, 130, 100, LOWP);
522 mediump KEYWORD(120, 100, 130, 100, MEDIUMP);
523 highp KEYWORD(120, 100, 130, 100, HIGHP);
524 precision KEYWORD(120, 100, 130, 100, PRECISION);
525
526 /* Additional reserved words in GLSL 1.30. */
527 case KEYWORD(130, 300, 130, 300, CASE);
528 common KEYWORD(130, 300, 0, 0, COMMON);
529 partition KEYWORD(130, 300, 0, 0, PARTITION);
530 active KEYWORD(130, 300, 0, 0, ACTIVE);
531 superp KEYWORD(130, 100, 0, 0, SUPERP);
532 samplerBuffer KEYWORD(130, 300, 140, 0, SAMPLERBUFFER);
533 filter KEYWORD(130, 300, 0, 0, FILTER);
534 row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR);
535
536 /* Additional reserved words in GLSL 1.40 */
537 isampler2DRect KEYWORD(140, 300, 140, 0, ISAMPLER2DRECT);
538 usampler2DRect KEYWORD(140, 300, 140, 0, USAMPLER2DRECT);
539 isamplerBuffer KEYWORD(140, 300, 140, 0, ISAMPLERBUFFER);
540 usamplerBuffer KEYWORD(140, 300, 140, 0, USAMPLERBUFFER);
541
542 /* Additional reserved words in GLSL ES 3.00 */
543 resource KEYWORD(0, 300, 0, 0, RESOURCE);
544 patch KEYWORD(0, 300, 0, 0, PATCH);
545 sample KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_gpu_shader5_enable, SAMPLE);
546 subroutine KEYWORD(0, 300, 0, 0, SUBROUTINE);
547
548
549 [_a-zA-Z][_a-zA-Z0-9]* {
550 struct _mesa_glsl_parse_state *state = yyextra;
551 void *ctx = state;
552 yylval->identifier = ralloc_strdup(ctx, yytext);
553 return classify_identifier(state, yytext);
554 }
555
556 . { return yytext[0]; }
557
558 %%
559
560 int
561 classify_identifier(struct _mesa_glsl_parse_state *state, const char *name)
562 {
563 if (state->symbols->get_variable(name) || state->symbols->get_function(name))
564 return IDENTIFIER;
565 else if (state->symbols->get_type(name))
566 return TYPE_IDENTIFIER;
567 else
568 return NEW_IDENTIFIER;
569 }
570
571 void
572 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string)
573 {
574 yylex_init_extra(state, & state->scanner);
575 yy_scan_string(string, state->scanner);
576 }
577
578 void
579 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
580 {
581 yylex_destroy(state->scanner);
582 }