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