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;
159 centroid return CENTROID;
160 invariant return INVARIANT;
162 sampler1D return SAMPLER1D;
163 sampler2D return SAMPLER2D;
164 sampler3D return SAMPLER3D;
165 samplerCube return SAMPLERCUBE;
166 sampler1DShadow return SAMPLER1DSHADOW;
167 sampler2DShadow return SAMPLER2DSHADOW;
169 struct return STRUCT;
182 \*= return MUL_ASSIGN;
183 \/= return DIV_ASSIGN;
184 \+= return ADD_ASSIGN;
185 \%= return MOD_ASSIGN;
186 \<\<= return LEFT_ASSIGN;
187 >>= return RIGHT_ASSIGN;
188 &= return AND_ASSIGN;
189 ^= return XOR_ASSIGN;
190 \|= return OR_ASSIGN;
191 -= return SUB_ASSIGN;
194 yylval->n = strtol(yytext, NULL, 10);
198 yylval->n = strtol(yytext + 2, NULL, 16);
202 yylval->n = strtol(yytext + 2, NULL, 8);
206 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
207 yylval->real = strtod(yytext, NULL);
208 return FLOATCONSTANT;
210 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
211 yylval->real = strtod(yytext, NULL);
212 return FLOATCONSTANT;
214 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
215 yylval->real = strtod(yytext, NULL);
216 return FLOATCONSTANT;
218 [0-9]+[eE][+-]?[0-9]+[fF]? {
219 yylval->real = strtod(yytext, NULL);
220 return FLOATCONSTANT;
233 /* Reserved words in GLSL 1.10. */
238 typedef return TYPEDEF;
239 template return TEMPLATE;
241 packed return PACKED;
243 switch return SWITCH;
244 default return DEFAULT;
245 inline return INLINE;
246 noinline return NOINLINE;
247 volatile return VOLATILE;
248 public return PUBLIC;
249 static return STATIC;
250 extern return EXTERN;
251 external return EXTERNAL;
252 interface return INTERFACE;
255 double return DOUBLE;
258 unsigned return UNSIGNED;
260 output return OUTPUT;
270 sampler2DRect return SAMPLER2DRECT;
271 sampler3DRect return SAMPLER3DRECT;
272 sampler2DRectShadow return SAMPLER2DRECTSHADOW;
273 sizeof return SIZEOF;
275 namespace return NAMESPACE;
278 /* Additional reserved words in GLSL 1.20. */
280 mediump return MEDIUMP;
282 precision return PRECISION;
284 [_a-zA-Z][_a-zA-Z0-9]* {
285 yylval->identifier = strdup(yytext);
289 . { return yytext[0]; }
294 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
295 const char *string, size_t len)
297 yylex_init_extra(state, & state->scanner);
298 yy_scan_bytes(string, len, state->scanner);
302 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
304 yylex_destroy(state->scanner);