OSDN Git Service

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