3 * Copyright © 2008, 2009 Intel Corporation
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:
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
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.
28 #include "glsl_parser_extras.h"
29 #include "glsl_parser.h"
31 static int classify_identifier(struct _mesa_glsl_parse_state *, const char *);
34 #define YY_NO_UNISTD_H
37 #define YY_USER_ACTION \
40 yylloc->first_column = yycolumn + 1; \
41 yylloc->first_line = yylloc->last_line = yylineno + 1; \
43 yylloc->last_column = yycolumn + 1; \
46 #define YY_USER_INIT yylineno = 0; yycolumn = 0;
48 /* A macro for handling reserved words and keywords across language versions.
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.
54 * For example, consider the following lexer rule:
55 * samplerBuffer KEYWORD(130, 0, 140, 0, SAMPLERBUFFER)
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
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)
68 * Like the KEYWORD macro, but the word is also treated as a keyword
69 * if the given boolean expression is true.
71 #define KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \
72 allowed_glsl, allowed_glsl_es, \
75 if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \
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); \
84 yylval->identifier = strdup(yytext); \
85 return classify_identifier(yyextra, yytext); \
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.
93 #define DEPRECATED_ES_KEYWORD(token) \
95 if (yyextra->is_version(0, 300)) { \
96 _mesa_glsl_error(yylloc, yyextra, \
97 "illegal use of reserved word `%s'", yytext); \
105 literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state,
106 YYSTYPE *lval, YYLTYPE *lloc, int base)
108 bool is_uint = (text[len - 1] == 'u' ||
109 text[len - 1] == 'U');
110 const char *digits = text;
117 unsigned __int64 value = _strtoui64(digits, NULL, base);
119 unsigned long long value = strtoull(digits, NULL, base);
122 lval->n = (int)value;
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);
130 _mesa_glsl_warning(lloc, state,
131 "literal value `%s' out of range", text);
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.
138 _mesa_glsl_warning(lloc, state,
139 "signed literal value `%s' is interpreted as %d",
142 return is_uint ? UINTCONSTANT : INTCONSTANT;
145 #define LITERAL_INTEGER(base) \
146 literal_integer(yytext, yyleng, yyextra, yylval, yylloc, base)
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 %option warn nodefault
157 /* Note: When adding any start conditions to this list, you must also
158 * update the "Internal compiler error" catch-all rule near the end of
163 HEX_INT 0[xX][0-9a-fA-F]+
165 INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
173 /* Preprocessor tokens. */
175 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION_TOK; }
176 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
177 {HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ {
178 /* Eat characters until the first digit is
182 while (!isdigit(*ptr))
185 /* Subtract one from the line number because
186 * yylineno is zero-based instead of
189 yylineno = strtol(ptr, &ptr, 0) - 1;
190 yylloc->source = strtol(ptr, NULL, 0);
192 {HASH}line{SPCP}{INT}{SPC}$ {
193 /* Eat characters until the first digit is
197 while (!isdigit(*ptr))
200 /* Subtract one from the line number because
201 * yylineno is zero-based instead of
204 yylineno = strtol(ptr, &ptr, 0) - 1;
206 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) {
208 return PRAGMA_DEBUG_ON;
210 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) {
212 return PRAGMA_DEBUG_OFF;
214 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) {
216 return PRAGMA_OPTIMIZE_ON;
218 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) {
220 return PRAGMA_OPTIMIZE_OFF;
222 ^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) {
224 return PRAGMA_INVARIANT_ALL;
226 ^{SPC}#{SPC}pragma{SPCP} { BEGIN PRAGMA; }
228 <PRAGMA>\n { BEGIN 0; yylineno++; yycolumn = 0; }
234 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
235 yylval->identifier = strdup(yytext);
239 yylval->n = strtol(yytext, NULL, 10);
242 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
243 <PP>. { return yytext[0]; }
245 \n { yylineno++; yycolumn = 0; }
247 attribute DEPRECATED_ES_KEYWORD(ATTRIBUTE);
248 const return CONST_TOK;
249 bool return BOOL_TOK;
250 float return FLOAT_TOK;
252 uint KEYWORD(130, 300, 130, 300, UINT_TOK);
255 continue return CONTINUE;
261 discard return DISCARD;
262 return return RETURN;
270 uvec2 KEYWORD(130, 300, 130, 300, UVEC2);
271 uvec3 KEYWORD(130, 300, 130, 300, UVEC3);
272 uvec4 KEYWORD(130, 300, 130, 300, UVEC4);
279 mat2x2 KEYWORD(120, 300, 120, 300, MAT2X2);
280 mat2x3 KEYWORD(120, 300, 120, 300, MAT2X3);
281 mat2x4 KEYWORD(120, 300, 120, 300, MAT2X4);
282 mat3x2 KEYWORD(120, 300, 120, 300, MAT3X2);
283 mat3x3 KEYWORD(120, 300, 120, 300, MAT3X3);
284 mat3x4 KEYWORD(120, 300, 120, 300, MAT3X4);
285 mat4x2 KEYWORD(120, 300, 120, 300, MAT4X2);
286 mat4x3 KEYWORD(120, 300, 120, 300, MAT4X3);
287 mat4x4 KEYWORD(120, 300, 120, 300, MAT4X4);
291 inout return INOUT_TOK;
292 uniform return UNIFORM;
293 varying DEPRECATED_ES_KEYWORD(VARYING);
294 centroid KEYWORD(120, 300, 120, 300, CENTROID);
295 invariant KEYWORD(120, 100, 120, 100, INVARIANT);
296 flat KEYWORD(130, 100, 130, 300, FLAT);
297 smooth KEYWORD(130, 300, 130, 300, SMOOTH);
298 noperspective KEYWORD(130, 300, 130, 0, NOPERSPECTIVE);
300 sampler1D DEPRECATED_ES_KEYWORD(SAMPLER1D);
301 sampler2D return SAMPLER2D;
302 sampler3D return SAMPLER3D;
303 samplerCube return SAMPLERCUBE;
304 sampler1DArray KEYWORD(130, 300, 130, 0, SAMPLER1DARRAY);
305 sampler2DArray KEYWORD(130, 300, 130, 300, SAMPLER2DARRAY);
306 sampler1DShadow DEPRECATED_ES_KEYWORD(SAMPLER1DSHADOW);
307 sampler2DShadow return SAMPLER2DSHADOW;
308 samplerCubeShadow KEYWORD(130, 300, 130, 300, SAMPLERCUBESHADOW);
309 sampler1DArrayShadow KEYWORD(130, 300, 130, 0, SAMPLER1DARRAYSHADOW);
310 sampler2DArrayShadow KEYWORD(130, 300, 130, 300, SAMPLER2DARRAYSHADOW);
311 isampler1D KEYWORD(130, 300, 130, 0, ISAMPLER1D);
312 isampler2D KEYWORD(130, 300, 130, 300, ISAMPLER2D);
313 isampler3D KEYWORD(130, 300, 130, 300, ISAMPLER3D);
314 isamplerCube KEYWORD(130, 300, 130, 300, ISAMPLERCUBE);
315 isampler1DArray KEYWORD(130, 300, 130, 0, ISAMPLER1DARRAY);
316 isampler2DArray KEYWORD(130, 300, 130, 300, ISAMPLER2DARRAY);
317 usampler1D KEYWORD(130, 300, 130, 0, USAMPLER1D);
318 usampler2D KEYWORD(130, 300, 130, 300, USAMPLER2D);
319 usampler3D KEYWORD(130, 300, 130, 300, USAMPLER3D);
320 usamplerCube KEYWORD(130, 300, 130, 300, USAMPLERCUBE);
321 usampler1DArray KEYWORD(130, 300, 130, 0, USAMPLER1DARRAY);
322 usampler2DArray KEYWORD(130, 300, 130, 300, USAMPLER2DARRAY);
324 /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */
325 /* these are reserved but not defined in GLSL 3.00 */
326 sampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMS);
327 isampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMS);
328 usampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMS);
329 sampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMSARRAY);
330 isampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMSARRAY);
331 usampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMSARRAY);
333 /* keywords available with ARB_texture_cube_map_array_enable extension on desktop GLSL */
334 samplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, SAMPLERCUBEARRAY);
335 isamplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, ISAMPLERCUBEARRAY);
336 usamplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, USAMPLERCUBEARRAY);
337 samplerCubeArrayShadow KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, SAMPLERCUBEARRAYSHADOW);
340 if (yyextra->OES_EGL_image_external_enable)
341 return SAMPLEREXTERNALOES;
346 /* keywords available with ARB_gpu_shader5 */
347 precise KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_gpu_shader5_enable, PRECISE);
349 /* keywords available with ARB_shader_image_load_store */
350 image1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE1D);
351 image2D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2D);
352 image3D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE3D);
353 image2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DRECT);
354 imageCube KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGECUBE);
355 imageBuffer KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGEBUFFER);
356 image1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE1DARRAY);
357 image2DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DARRAY);
358 imageCubeArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGECUBEARRAY);
359 image2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DMS);
360 image2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DMSARRAY);
361 iimage1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE1D);
362 iimage2D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2D);
363 iimage3D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE3D);
364 iimage2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DRECT);
365 iimageCube KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGECUBE);
366 iimageBuffer KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGEBUFFER);
367 iimage1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE1DARRAY);
368 iimage2DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DARRAY);
369 iimageCubeArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGECUBEARRAY);
370 iimage2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DMS);
371 iimage2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DMSARRAY);
372 uimage1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE1D);
373 uimage2D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2D);
374 uimage3D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE3D);
375 uimage2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DRECT);
376 uimageCube KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGECUBE);
377 uimageBuffer KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGEBUFFER);
378 uimage1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE1DARRAY);
379 uimage2DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DARRAY);
380 uimageCubeArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGECUBEARRAY);
381 uimage2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DMS);
382 uimage2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DMSARRAY);
383 image1DShadow KEYWORD(130, 300, 0, 0, IMAGE1DSHADOW);
384 image2DShadow KEYWORD(130, 300, 0, 0, IMAGE2DSHADOW);
385 image1DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE1DARRAYSHADOW);
386 image2DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE2DARRAYSHADOW);
388 coherent KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, COHERENT);
389 volatile KEYWORD_WITH_ALT(110, 100, 420, 0, yyextra->ARB_shader_image_load_store_enable, VOLATILE);
390 restrict KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, RESTRICT);
391 readonly KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, READONLY);
392 writeonly KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, WRITEONLY);
394 atomic_uint KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_atomic_counters_enable, ATOMIC_UINT);
396 struct return STRUCT;
397 void return VOID_TOK;
400 if ((yyextra->is_version(140, 300))
401 || yyextra->AMD_conservative_depth_enable
402 || yyextra->ARB_conservative_depth_enable
403 || yyextra->ARB_explicit_attrib_location_enable
404 || yyextra->ARB_explicit_uniform_location_enable
405 || yyextra->has_separate_shader_objects()
406 || yyextra->ARB_uniform_buffer_object_enable
407 || yyextra->ARB_fragment_coord_conventions_enable
408 || yyextra->ARB_shading_language_420pack_enable
409 || yyextra->ARB_compute_shader_enable) {
412 yylval->identifier = strdup(yytext);
413 return classify_identifier(yyextra, yytext);
427 ">>" return RIGHT_OP;
429 \*= return MUL_ASSIGN;
430 \/= return DIV_ASSIGN;
431 \+= return ADD_ASSIGN;
432 \%= return MOD_ASSIGN;
433 \<\<= return LEFT_ASSIGN;
434 >>= return RIGHT_ASSIGN;
435 &= return AND_ASSIGN;
436 "^=" return XOR_ASSIGN;
437 \|= return OR_ASSIGN;
438 -= return SUB_ASSIGN;
441 return LITERAL_INTEGER(10);
443 0[xX][0-9a-fA-F]+[uU]? {
444 return LITERAL_INTEGER(16);
447 return LITERAL_INTEGER(8);
450 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
451 yylval->real = glsl_strtof(yytext, NULL);
452 return FLOATCONSTANT;
454 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
455 yylval->real = glsl_strtof(yytext, NULL);
456 return FLOATCONSTANT;
458 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
459 yylval->real = glsl_strtof(yytext, NULL);
460 return FLOATCONSTANT;
462 [0-9]+[eE][+-]?[0-9]+[fF]? {
463 yylval->real = glsl_strtof(yytext, NULL);
464 return FLOATCONSTANT;
467 yylval->real = glsl_strtof(yytext, NULL);
468 return FLOATCONSTANT;
481 /* Reserved words in GLSL 1.10. */
482 asm KEYWORD(110, 100, 0, 0, ASM);
483 class KEYWORD(110, 100, 0, 0, CLASS);
484 union KEYWORD(110, 100, 0, 0, UNION);
485 enum KEYWORD(110, 100, 0, 0, ENUM);
486 typedef KEYWORD(110, 100, 0, 0, TYPEDEF);
487 template KEYWORD(110, 100, 0, 0, TEMPLATE);
488 this KEYWORD(110, 100, 0, 0, THIS);
489 packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK);
490 goto KEYWORD(110, 100, 0, 0, GOTO);
491 switch KEYWORD(110, 100, 130, 300, SWITCH);
492 default KEYWORD(110, 100, 130, 300, DEFAULT);
493 inline KEYWORD(110, 100, 0, 0, INLINE_TOK);
494 noinline KEYWORD(110, 100, 0, 0, NOINLINE);
495 public KEYWORD(110, 100, 0, 0, PUBLIC_TOK);
496 static KEYWORD(110, 100, 0, 0, STATIC);
497 extern KEYWORD(110, 100, 0, 0, EXTERN);
498 external KEYWORD(110, 100, 0, 0, EXTERNAL);
499 interface KEYWORD(110, 100, 0, 0, INTERFACE);
500 long KEYWORD(110, 100, 0, 0, LONG_TOK);
501 short KEYWORD(110, 100, 0, 0, SHORT_TOK);
502 double KEYWORD(110, 100, 400, 0, DOUBLE_TOK);
503 half KEYWORD(110, 100, 0, 0, HALF);
504 fixed KEYWORD(110, 100, 0, 0, FIXED_TOK);
505 unsigned KEYWORD(110, 100, 0, 0, UNSIGNED);
506 input KEYWORD(110, 100, 0, 0, INPUT_TOK);
507 output KEYWORD(110, 100, 0, 0, OUTPUT);
508 hvec2 KEYWORD(110, 100, 0, 0, HVEC2);
509 hvec3 KEYWORD(110, 100, 0, 0, HVEC3);
510 hvec4 KEYWORD(110, 100, 0, 0, HVEC4);
511 dvec2 KEYWORD(110, 100, 400, 0, DVEC2);
512 dvec3 KEYWORD(110, 100, 400, 0, DVEC3);
513 dvec4 KEYWORD(110, 100, 400, 0, DVEC4);
514 fvec2 KEYWORD(110, 100, 0, 0, FVEC2);
515 fvec3 KEYWORD(110, 100, 0, 0, FVEC3);
516 fvec4 KEYWORD(110, 100, 0, 0, FVEC4);
517 sampler2DRect DEPRECATED_ES_KEYWORD(SAMPLER2DRECT);
518 sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT);
519 sampler2DRectShadow DEPRECATED_ES_KEYWORD(SAMPLER2DRECTSHADOW);
520 sizeof KEYWORD(110, 100, 0, 0, SIZEOF);
521 cast KEYWORD(110, 100, 0, 0, CAST);
522 namespace KEYWORD(110, 100, 0, 0, NAMESPACE);
523 using KEYWORD(110, 100, 0, 0, USING);
525 /* Additional reserved words in GLSL 1.20. */
526 lowp KEYWORD(120, 100, 130, 100, LOWP);
527 mediump KEYWORD(120, 100, 130, 100, MEDIUMP);
528 highp KEYWORD(120, 100, 130, 100, HIGHP);
529 precision KEYWORD(120, 100, 130, 100, PRECISION);
531 /* Additional reserved words in GLSL 1.30. */
532 case KEYWORD(130, 300, 130, 300, CASE);
533 common KEYWORD(130, 300, 0, 0, COMMON);
534 partition KEYWORD(130, 300, 0, 0, PARTITION);
535 active KEYWORD(130, 300, 0, 0, ACTIVE);
536 superp KEYWORD(130, 100, 0, 0, SUPERP);
537 samplerBuffer KEYWORD(130, 300, 140, 0, SAMPLERBUFFER);
538 filter KEYWORD(130, 300, 0, 0, FILTER);
539 row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR);
541 /* Additional reserved words in GLSL 1.40 */
542 isampler2DRect KEYWORD(140, 300, 140, 0, ISAMPLER2DRECT);
543 usampler2DRect KEYWORD(140, 300, 140, 0, USAMPLER2DRECT);
544 isamplerBuffer KEYWORD(140, 300, 140, 0, ISAMPLERBUFFER);
545 usamplerBuffer KEYWORD(140, 300, 140, 0, USAMPLERBUFFER);
547 /* Additional reserved words in GLSL ES 3.00 */
548 resource KEYWORD(0, 300, 0, 0, RESOURCE);
549 patch KEYWORD(0, 300, 0, 0, PATCH);
550 sample KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_gpu_shader5_enable, SAMPLE);
551 subroutine KEYWORD(0, 300, 0, 0, SUBROUTINE);
554 [_a-zA-Z][_a-zA-Z0-9]* {
555 struct _mesa_glsl_parse_state *state = yyextra;
557 yylval->identifier = ralloc_strdup(ctx, yytext);
558 return classify_identifier(state, yytext);
561 . { return yytext[0]; }
566 classify_identifier(struct _mesa_glsl_parse_state *state, const char *name)
568 if (state->symbols->get_variable(name) || state->symbols->get_function(name))
570 else if (state->symbols->get_type(name))
571 return TYPE_IDENTIFIER;
573 return NEW_IDENTIFIER;
577 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string)
579 yylex_init_extra(state, & state->scanner);
580 yy_scan_string(string, state->scanner);
584 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
586 yylex_destroy(state->scanner);