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.
26 #include "glsl_parser_extras.h"
27 #include "glsl_parser.h"
29 #define YY_USER_ACTION \
32 yylloc->first_column = yycolumn + 1; \
33 yylloc->first_line = yylineno + 1; \
39 %option bison-bridge bison-locations reentrant noyywrap
40 %option nounput noyy_top_state
41 %option never-interactive
42 %option prefix="_mesa_glsl_"
43 %option extra-type="struct _mesa_glsl_parse_state *"
48 HEX_INT 0[xX][0-9a-fA-F]+
50 INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
58 /* Preprocessor tokens. */
60 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; }
61 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
62 {HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ {
63 /* Eat characters until the first digit is
67 while (!isdigit(*ptr))
70 /* Subtract one from the line number because
71 * yylineno is zero-based instead of
74 yylineno = strtol(ptr, &ptr, 0) - 1;
75 yylloc->source = strtol(ptr, NULL, 0);
77 {HASH}line{SPCP}{INT}{SPC}$ {
78 /* Eat characters until the first digit is
82 while (!isdigit(*ptr))
85 /* Subtract one from the line number because
86 * yylineno is zero-based instead of
89 yylineno = strtol(ptr, &ptr, 0) - 1;
91 ^[ \t]*#[ \t]*pragma { BEGIN PP; return PRAGMA; }
95 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
96 yylval->identifier = strdup(yytext);
100 yylval->n = strtol(yytext, NULL, 10);
103 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
105 \n { yylineno++; yycolumn = 0; }
107 attribute return ATTRIBUTE;
114 continue return CONTINUE;
120 discard return DISCARD;
121 return return RETURN;
135 mat2x2 return MAT2X2;
136 mat2x3 return MAT2X3;
137 mat2x4 return MAT2X4;
138 mat3x2 return MAT3X2;
139 mat3x3 return MAT3X3;
140 mat3x4 return MAT3X4;
141 mat4x2 return MAT4X2;
142 mat4x3 return MAT4X3;
143 mat4x4 return MAT4X4;
148 uniform return UNIFORM;
149 varying return VARYING;
151 if (yyextra->language_version >= 120) {
154 yylval->identifier = strdup(yytext);
159 if (yyextra->language_version >= 120) {
162 yylval->identifier = strdup(yytext);
168 if (yyextra->language_version >= 130) {
171 yylval->identifier = strdup(yytext);
176 if (yyextra->language_version >= 130) {
179 yylval->identifier = strdup(yytext);
184 if (yyextra->language_version >= 130) {
185 return NOPERSPECTIVE;
187 yylval->identifier = strdup(yytext);
192 sampler1D return SAMPLER1D;
193 sampler2D return SAMPLER2D;
194 sampler3D return SAMPLER3D;
195 samplerCube return SAMPLERCUBE;
196 sampler1DShadow return SAMPLER1DSHADOW;
197 sampler2DShadow return SAMPLER2DSHADOW;
199 struct return STRUCT;
212 \*= return MUL_ASSIGN;
213 \/= return DIV_ASSIGN;
214 \+= return ADD_ASSIGN;
215 \%= return MOD_ASSIGN;
216 \<\<= return LEFT_ASSIGN;
217 >>= return RIGHT_ASSIGN;
218 &= return AND_ASSIGN;
219 ^= return XOR_ASSIGN;
220 \|= return OR_ASSIGN;
221 -= return SUB_ASSIGN;
224 yylval->n = strtol(yytext, NULL, 10);
228 yylval->n = strtol(yytext + 2, NULL, 16);
232 yylval->n = strtol(yytext + 2, NULL, 8);
236 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
237 yylval->real = strtod(yytext, NULL);
238 return FLOATCONSTANT;
240 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
241 yylval->real = strtod(yytext, NULL);
242 return FLOATCONSTANT;
244 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
245 yylval->real = strtod(yytext, NULL);
246 return FLOATCONSTANT;
248 [0-9]+[eE][+-]?[0-9]+[fF]? {
249 yylval->real = strtod(yytext, NULL);
250 return FLOATCONSTANT;
263 /* Reserved words in GLSL 1.10. */
268 typedef return TYPEDEF;
269 template return TEMPLATE;
271 packed return PACKED;
273 switch return SWITCH;
274 default return DEFAULT;
275 inline return INLINE;
276 noinline return NOINLINE;
277 volatile return VOLATILE;
278 public return PUBLIC;
279 static return STATIC;
280 extern return EXTERN;
281 external return EXTERNAL;
282 interface return INTERFACE;
285 double return DOUBLE;
288 unsigned return UNSIGNED;
290 output return OUTPUT;
300 sampler2DRect return SAMPLER2DRECT;
301 sampler3DRect return SAMPLER3DRECT;
302 sampler2DRectShadow return SAMPLER2DRECTSHADOW;
303 sizeof return SIZEOF;
305 namespace return NAMESPACE;
308 /* Additional reserved words in GLSL 1.20. */
310 mediump return MEDIUMP;
312 precision return PRECISION;
314 [_a-zA-Z][_a-zA-Z0-9]* {
315 struct _mesa_glsl_parse_state *state = yyextra;
316 void *ctx = talloc_parent(state);
317 yylval->identifier = talloc_strdup(ctx, yytext);
321 . { return yytext[0]; }
326 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string)
328 yylex_init_extra(state, & state->scanner);
329 yy_scan_string(string, state->scanner);
333 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
335 yylex_destroy(state->scanner);