Start trying to fill in a few bits of ir_constant_expression.cpp
[mesa.git] / glsl_lexer.lpp
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 "ast.h"
25 #include "glsl_parser_extras.h"
26 #include "glsl_parser.h"
27
28 #define YY_USER_ACTION \
29 do { \
30 yylloc->source = 0; \
31 yylloc->first_column = yycolumn + 1; \
32 yylloc->first_line = yylineno + 1; \
33 yycolumn += yyleng; \
34 } while(0);
35
36 %}
37
38 %option bison-bridge bison-locations reentrant noyywrap
39 %option never-interactive
40 %option prefix="_mesa_glsl_"
41 %option extra-type="struct _mesa_glsl_parse_state *"
42 %option stack
43
44 %x PP COMMENT
45
46 %%
47
48 "/*" { yy_push_state(COMMENT, yyscanner); }
49 <COMMENT>[^*\n]*
50 <COMMENT>[^*\n]*\n { yylineno++; yycolumn = 0; }
51 <COMMENT>"*"+[^*/\n]*
52 <COMMENT>"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; }
53 <COMMENT>"*"+"/" { yy_pop_state(yyscanner); }
54
55 \/\/.*\n { yylineno++; yycolumn = 0; }
56 [ \r\t]+ ;
57
58 /* Preprocessor tokens. */
59 ^[ \t]*#[ \t]*$ ;
60 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; }
61 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
62 ^[ \t]*#[ \t]*line { BEGIN PP; return LINE; }
63 ^[ \t]*#[ \t]*pragma { BEGIN PP; return PRAGMA; }
64 <PP>: return COLON;
65 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
66 yylval->identifier = strdup(yytext);
67 return IDENTIFIER;
68 }
69 <PP>[1-9][0-9]* {
70 yylval->n = strtol(yytext, NULL, 10);
71 return INTCONSTANT;
72 }
73 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
74
75 \n { yylineno++; yycolumn = 0; }
76
77 attribute return ATTRIBUTE;
78 const return CONST;
79 bool return BOOL;
80 float return FLOAT;
81 int return INT;
82
83 break return BREAK;
84 continue return CONTINUE;
85 do return DO;
86 while return WHILE;
87 else return ELSE;
88 for return FOR;
89 if return IF;
90 discard return DISCARD;
91 return return RETURN;
92
93 bvec2 return BVEC2;
94 bvec3 return BVEC3;
95 bvec4 return BVEC4;
96 ivec2 return IVEC2;
97 ivec3 return IVEC3;
98 ivec4 return IVEC4;
99 vec2 return VEC2;
100 vec3 return VEC3;
101 vec4 return VEC4;
102 mat2 return MAT2;
103 mat3 return MAT3;
104 mat4 return MAT4;
105 mat2x2 return MAT2X2;
106 mat2x3 return MAT2X3;
107 mat2x4 return MAT2X4;
108 mat3x2 return MAT3X2;
109 mat3x3 return MAT3X3;
110 mat3x4 return MAT3X4;
111 mat4x2 return MAT4X2;
112 mat4x3 return MAT4X3;
113 mat4x4 return MAT4X4;
114
115 in return IN;
116 out return OUT;
117 inout return INOUT;
118 uniform return UNIFORM;
119 varying return VARYING;
120 centroid return CENTROID;
121 invariant return INVARIANT;
122
123 sampler1D return SAMPLER1D;
124 sampler2D return SAMPLER2D;
125 sampler3D return SAMPLER3D;
126 samplerCube return SAMPLERCUBE;
127 sampler1DShadow return SAMPLER1DSHADOW;
128 sampler2DShadow return SAMPLER2DSHADOW;
129
130 struct return STRUCT;
131 void return VOID;
132
133 \+\+ return INC_OP;
134 -- return DEC_OP;
135 \<= return LE_OP;
136 >= return GE_OP;
137 == return EQ_OP;
138 != return NE_OP;
139 && return AND_OP;
140 \|\| return OR_OP;
141 "^^" return XOR_OP;
142
143 \*= return MUL_ASSIGN;
144 \/= return DIV_ASSIGN;
145 \+= return ADD_ASSIGN;
146 \%= return MOD_ASSIGN;
147 \<\<= return LEFT_ASSIGN;
148 >>= return RIGHT_ASSIGN;
149 &= return AND_ASSIGN;
150 ^= return XOR_ASSIGN;
151 \|= return OR_ASSIGN;
152 -= return SUB_ASSIGN;
153
154 [1-9][0-9]* {
155 yylval->n = strtol(yytext, NULL, 10);
156 return INTCONSTANT;
157 }
158 0[xX][0-9a-fA-F]+ {
159 yylval->n = strtol(yytext + 2, NULL, 16);
160 return INTCONSTANT;
161 }
162 0[0-7]* {
163 yylval->n = strtol(yytext + 2, NULL, 8);
164 return INTCONSTANT;
165 }
166
167 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
168 yylval->real = strtod(yytext, NULL);
169 return FLOATCONSTANT;
170 }
171 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
172 yylval->real = strtod(yytext, NULL);
173 return FLOATCONSTANT;
174 }
175 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
176 yylval->real = strtod(yytext, NULL);
177 return FLOATCONSTANT;
178 }
179 [0-9]+[eE][+-]?[0-9]+[fF]? {
180 yylval->real = strtod(yytext, NULL);
181 return FLOATCONSTANT;
182 }
183
184 true {
185 yylval->n = 1;
186 return BOOLCONSTANT;
187 }
188 false {
189 yylval->n = 0;
190 return BOOLCONSTANT;
191 }
192
193
194 /* Reserved words in GLSL 1.10. */
195 asm return ASM;
196 class return CLASS;
197 union return UNION;
198 enum return ENUM;
199 typedef return TYPEDEF;
200 template return TEMPLATE;
201 this return THIS;
202 packed return PACKED;
203 goto return GOTO;
204 switch return SWITCH;
205 default return DEFAULT;
206 inline return INLINE;
207 noinline return NOINLINE;
208 volatile return VOLATILE;
209 public return PUBLIC;
210 static return STATIC;
211 extern return EXTERN;
212 external return EXTERNAL;
213 interface return INTERFACE;
214 long return LONG;
215 short return SHORT;
216 double return DOUBLE;
217 half return HALF;
218 fixed return FIXED;
219 unsigned return UNSIGNED;
220 input return INPUT;
221 output return OUTPUT;
222 hvec2 return HVEC2;
223 hvec3 return HVEC3;
224 hvec4 return HVEC4;
225 dvec2 return DVEC2;
226 dvec3 return DVEC3;
227 dvec4 return DVEC4;
228 fvec2 return FVEC2;
229 fvec3 return FVEC3;
230 fvec4 return FVEC4;
231 sampler2DRect return SAMPLER2DRECT;
232 sampler3DRect return SAMPLER3DRECT;
233 sampler2DRectShadow return SAMPLER2DRECTSHADOW;
234 sizeof return SIZEOF;
235 cast return CAST;
236 namespace return NAMESPACE;
237 using return USING;
238
239 /* Additional reserved words in GLSL 1.20. */
240 lowp return LOWP;
241 mediump return MEDIUMP;
242 highp return HIGHP;
243 precision return PRECISION;
244
245 [_a-zA-Z][_a-zA-Z0-9]* {
246 yylval->identifier = strdup(yytext);
247 return IDENTIFIER;
248 }
249
250 . { return yytext[0]; }
251
252 %%
253
254 void
255 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
256 const char *string, size_t len)
257 {
258 yylex_init_extra(state, & state->scanner);
259 yy_scan_bytes(string, len, state->scanner);
260 }
261
262 void
263 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
264 {
265 yylex_destroy(state->scanner);
266 }