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 *"
49 HEX_INT 0[xX][0-9a-fA-F]+
51 INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
57 "/*" { yy_push_state(COMMENT, yyscanner); }
59 <COMMENT>[^*\n]*\n { yylineno++; yycolumn = 0; }
61 <COMMENT>"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; }
62 <COMMENT>"*"+"/" { yy_pop_state(yyscanner); }
64 \/\/.*\n { yylineno++; yycolumn = 0; }
67 /* Preprocessor tokens. */
69 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; }
70 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
71 {HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ {
72 /* Eat characters until the first digit is
76 while (!isdigit(*ptr))
79 /* Subtract one from the line number because
80 * yylineno is zero-based instead of
83 yylineno = strtol(ptr, &ptr, 0) - 1;
84 yylloc->source = strtol(ptr, NULL, 0);
86 {HASH}line{SPCP}{INT}{SPC}$ {
87 /* Eat characters until the first digit is
91 while (!isdigit(*ptr))
94 /* Subtract one from the line number because
95 * yylineno is zero-based instead of
98 yylineno = strtol(ptr, &ptr, 0) - 1;
100 ^[ \t]*#[ \t]*pragma { BEGIN PP; return PRAGMA; }
104 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
105 yylval->identifier = strdup(yytext);
109 yylval->n = strtol(yytext, NULL, 10);
112 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
114 \n { yylineno++; yycolumn = 0; }
116 attribute return ATTRIBUTE;
123 continue return CONTINUE;
129 discard return DISCARD;
130 return return RETURN;
144 mat2x2 return MAT2X2;
145 mat2x3 return MAT2X3;
146 mat2x4 return MAT2X4;
147 mat3x2 return MAT3X2;
148 mat3x3 return MAT3X3;
149 mat3x4 return MAT3X4;
150 mat4x2 return MAT4X2;
151 mat4x3 return MAT4X3;
152 mat4x4 return MAT4X4;
157 uniform return UNIFORM;
158 varying return VARYING;
160 if (yyextra->language_version >= 120) {
163 yylval->identifier = strdup(yytext);
168 if (yyextra->language_version >= 120) {
171 yylval->identifier = strdup(yytext);
177 if (yyextra->language_version >= 130) {
180 yylval->identifier = strdup(yytext);
185 if (yyextra->language_version >= 130) {
188 yylval->identifier = strdup(yytext);
193 if (yyextra->language_version >= 130) {
194 return NOPERSPECTIVE;
196 yylval->identifier = strdup(yytext);
201 sampler1D return SAMPLER1D;
202 sampler2D return SAMPLER2D;
203 sampler3D return SAMPLER3D;
204 samplerCube return SAMPLERCUBE;
205 sampler1DShadow return SAMPLER1DSHADOW;
206 sampler2DShadow return SAMPLER2DSHADOW;
208 struct return STRUCT;
221 \*= return MUL_ASSIGN;
222 \/= return DIV_ASSIGN;
223 \+= return ADD_ASSIGN;
224 \%= return MOD_ASSIGN;
225 \<\<= return LEFT_ASSIGN;
226 >>= return RIGHT_ASSIGN;
227 &= return AND_ASSIGN;
228 ^= return XOR_ASSIGN;
229 \|= return OR_ASSIGN;
230 -= return SUB_ASSIGN;
233 yylval->n = strtol(yytext, NULL, 10);
237 yylval->n = strtol(yytext + 2, NULL, 16);
241 yylval->n = strtol(yytext + 2, NULL, 8);
245 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
246 yylval->real = strtod(yytext, NULL);
247 return FLOATCONSTANT;
249 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
250 yylval->real = strtod(yytext, NULL);
251 return FLOATCONSTANT;
253 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
254 yylval->real = strtod(yytext, NULL);
255 return FLOATCONSTANT;
257 [0-9]+[eE][+-]?[0-9]+[fF]? {
258 yylval->real = strtod(yytext, NULL);
259 return FLOATCONSTANT;
272 /* Reserved words in GLSL 1.10. */
277 typedef return TYPEDEF;
278 template return TEMPLATE;
280 packed return PACKED;
282 switch return SWITCH;
283 default return DEFAULT;
284 inline return INLINE;
285 noinline return NOINLINE;
286 volatile return VOLATILE;
287 public return PUBLIC;
288 static return STATIC;
289 extern return EXTERN;
290 external return EXTERNAL;
291 interface return INTERFACE;
294 double return DOUBLE;
297 unsigned return UNSIGNED;
299 output return OUTPUT;
309 sampler2DRect return SAMPLER2DRECT;
310 sampler3DRect return SAMPLER3DRECT;
311 sampler2DRectShadow return SAMPLER2DRECTSHADOW;
312 sizeof return SIZEOF;
314 namespace return NAMESPACE;
317 /* Additional reserved words in GLSL 1.20. */
319 mediump return MEDIUMP;
321 precision return PRECISION;
323 [_a-zA-Z][_a-zA-Z0-9]* {
324 yylval->identifier = strdup(yytext);
328 . { return yytext[0]; }
333 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
334 const char *string, size_t len)
336 yylex_init_extra(state, & state->scanner);
337 yy_scan_bytes(string, len, state->scanner);
341 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
343 yylex_destroy(state->scanner);