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; \
37 #define YY_USER_INIT yylineno = 0; yycolumn = 0;
41 %option bison-bridge bison-locations reentrant noyywrap
42 %option nounput noyy_top_state
43 %option never-interactive
44 %option prefix="_mesa_glsl_"
45 %option extra-type="struct _mesa_glsl_parse_state *"
50 HEX_INT 0[xX][0-9a-fA-F]+
52 INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
60 /* Preprocessor tokens. */
62 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; }
63 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
64 {HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ {
65 /* Eat characters until the first digit is
69 while (!isdigit(*ptr))
72 /* Subtract one from the line number because
73 * yylineno is zero-based instead of
76 yylineno = strtol(ptr, &ptr, 0) - 1;
77 yylloc->source = strtol(ptr, NULL, 0);
79 {HASH}line{SPCP}{INT}{SPC}$ {
80 /* Eat characters until the first digit is
84 while (!isdigit(*ptr))
87 /* Subtract one from the line number because
88 * yylineno is zero-based instead of
91 yylineno = strtol(ptr, &ptr, 0) - 1;
93 ^[ \t]*#[ \t]*pragma { BEGIN PP; return PRAGMA; }
97 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
98 yylval->identifier = strdup(yytext);
102 yylval->n = strtol(yytext, NULL, 10);
105 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
107 \n { yylineno++; yycolumn = 0; }
109 attribute return ATTRIBUTE;
110 const return CONST_TOK;
116 continue return CONTINUE;
122 discard return DISCARD;
123 return return RETURN;
137 mat2x2 return MAT2X2;
138 mat2x3 return MAT2X3;
139 mat2x4 return MAT2X4;
140 mat3x2 return MAT3X2;
141 mat3x3 return MAT3X3;
142 mat3x4 return MAT3X4;
143 mat4x2 return MAT4X2;
144 mat4x3 return MAT4X3;
145 mat4x4 return MAT4X4;
150 uniform return UNIFORM;
151 varying return VARYING;
153 if (yyextra->language_version >= 120) {
156 yylval->identifier = strdup(yytext);
161 if (yyextra->language_version >= 120) {
164 yylval->identifier = strdup(yytext);
170 if (yyextra->language_version >= 130) {
173 yylval->identifier = strdup(yytext);
178 if (yyextra->language_version >= 130) {
181 yylval->identifier = strdup(yytext);
186 if (yyextra->language_version >= 130) {
187 return NOPERSPECTIVE;
189 yylval->identifier = strdup(yytext);
194 sampler1D return SAMPLER1D;
195 sampler2D return SAMPLER2D;
196 sampler3D return SAMPLER3D;
197 samplerCube return SAMPLERCUBE;
198 sampler1DShadow return SAMPLER1DSHADOW;
199 sampler2DShadow return SAMPLER2DSHADOW;
201 struct return STRUCT;
214 \*= return MUL_ASSIGN;
215 \/= return DIV_ASSIGN;
216 \+= return ADD_ASSIGN;
217 \%= return MOD_ASSIGN;
218 \<\<= return LEFT_ASSIGN;
219 >>= return RIGHT_ASSIGN;
220 &= return AND_ASSIGN;
221 ^= return XOR_ASSIGN;
222 \|= return OR_ASSIGN;
223 -= return SUB_ASSIGN;
226 yylval->n = strtol(yytext, NULL, 10);
230 yylval->n = strtol(yytext + 2, NULL, 16);
234 yylval->n = strtol(yytext, NULL, 8);
238 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
239 yylval->real = strtod(yytext, NULL);
240 return FLOATCONSTANT;
242 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
243 yylval->real = strtod(yytext, NULL);
244 return FLOATCONSTANT;
246 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
247 yylval->real = strtod(yytext, NULL);
248 return FLOATCONSTANT;
250 [0-9]+[eE][+-]?[0-9]+[fF]? {
251 yylval->real = strtod(yytext, NULL);
252 return FLOATCONSTANT;
265 /* Reserved words in GLSL 1.10. */
270 typedef return TYPEDEF;
271 template return TEMPLATE;
273 packed return PACKED;
275 switch return SWITCH;
276 default return DEFAULT;
277 inline return INLINE_TOK;
278 noinline return NOINLINE;
279 volatile return VOLATILE;
280 public return PUBLIC_TOK;
281 static return STATIC;
282 extern return EXTERN;
283 external return EXTERNAL;
284 interface return INTERFACE;
287 double return DOUBLE;
290 unsigned return UNSIGNED;
292 output return OUTPUT;
302 sampler2DRect return SAMPLER2DRECT;
303 sampler3DRect return SAMPLER3DRECT;
304 sampler2DRectShadow return SAMPLER2DRECTSHADOW;
305 sizeof return SIZEOF;
307 namespace return NAMESPACE;
310 /* Additional reserved words in GLSL 1.20. */
312 mediump return MEDIUMP;
314 precision return PRECISION;
316 [_a-zA-Z][_a-zA-Z0-9]* {
317 struct _mesa_glsl_parse_state *state = yyextra;
319 yylval->identifier = talloc_strdup(ctx, yytext);
323 . { return yytext[0]; }
328 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string)
330 yylex_init_extra(state, & state->scanner);
331 yy_scan_string(string, state->scanner);
335 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
337 yylex_destroy(state->scanner);