blob: c0d92b36545fb5e4203ae6679e95df296ac25721 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001/*
2//
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +00003// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00008This file contains the Lex specification for GLSL ES.
9Based on ANSI C grammar, Lex specification:
10http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011
alokp@chromium.org75fe6b72011-08-14 05:31:22 +000012IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh,
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000013WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000014*/
15
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000016%top{
17//
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +000018// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000019// Use of this source code is governed by a BSD-style license that can be
20// found in the LICENSE file.
21//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000022
alokp@chromium.org75fe6b72011-08-14 05:31:22 +000023// This file is auto-generated by generate_parser.sh. DO NOT EDIT!
apatrick@chromium.org536888b2012-01-25 02:10:25 +000024
25// Ignore errors in auto-generated code.
26#if defined(__GNUC__)
apatrick@chromium.orga1d80592012-01-25 21:52:10 +000027#pragma GCC diagnostic ignored "-Wunused-function"
apatrick@chromium.org536888b2012-01-25 02:10:25 +000028#pragma GCC diagnostic ignored "-Wunused-variable"
apatrick@chromium.orge057c5d2012-01-26 19:18:24 +000029#pragma GCC diagnostic ignored "-Wswitch-enum"
apatrick@chromium.org536888b2012-01-25 02:10:25 +000030#elif defined(_MSC_VER)
Scott Grahama825fdc2015-04-14 16:05:47 -070031#pragma warning(disable: 4005)
apatrick@chromium.org536888b2012-01-25 02:10:25 +000032#pragma warning(disable: 4065)
apatrick@chromium.orga1d80592012-01-25 21:52:10 +000033#pragma warning(disable: 4189)
Minmin Gong794e0002015-04-07 18:31:54 -070034#pragma warning(disable: 4244)
apatrick@chromium.orga1d80592012-01-25 21:52:10 +000035#pragma warning(disable: 4505)
36#pragma warning(disable: 4701)
Austin Kinrossc8ef69d2015-03-18 16:43:22 -070037#pragma warning(disable: 4702)
apatrick@chromium.org536888b2012-01-25 02:10:25 +000038#endif
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000039}
40
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000041%{
Geoff Lang17732822013-08-29 13:46:49 -040042#include "compiler/translator/glslang.h"
Jamie Madill6b9cb252013-10-17 10:45:47 -040043#include "compiler/translator/ParseContext.h"
daniel@transgaming.comb401a922012-10-26 18:58:24 +000044#include "compiler/preprocessor/Token.h"
Geoff Lang17732822013-08-29 13:46:49 -040045#include "compiler/translator/util.h"
Jamie Madill5508f392014-02-20 13:31:36 -050046#include "compiler/translator/length_limits.h"
alokp@chromium.orgeab1ef12010-04-23 17:33:49 +000047#include "glslang_tab.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000048
49/* windows only pragma */
50#ifdef _MSC_VER
51#pragma warning(disable : 4102)
52#endif
53
Jamie Madill2dc8bf82015-04-30 15:56:52 -040054// Workaround for flex using the register keyword, deprecated in C++11.
55#ifdef __cplusplus
56#if __cplusplus > 199711L
57#define register
58#endif
59#endif
60
Jamie Madill075edd82013-07-08 13:30:19 -040061#define YY_USER_ACTION \
62 yylloc->first_file = yylloc->last_file = yycolumn; \
63 yylloc->first_line = yylloc->last_line = yylineno;
64
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000065#define YY_INPUT(buf, result, max_size) \
66 result = string_input(buf, max_size, yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000067
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000068static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000069static int check_type(yyscan_t yyscanner);
70static int reserved_word(yyscan_t yyscanner);
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000071static int ES2_reserved_ES3_keyword(TParseContext *context, int token);
72static int ES2_keyword_ES3_reserved(TParseContext *context, int token);
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +000073static int ES2_ident_ES3_keyword(TParseContext *context, int token);
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +000074static int uint_constant(TParseContext *context);
Zhenyao Mof1d723c2013-09-23 14:57:07 -040075static int int_constant(yyscan_t yyscanner);
76static int float_constant(yyscan_t yyscanner);
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +000077static int floatsuffix_check(TParseContext* context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000078%}
79
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000080%option noyywrap nounput never-interactive
Jamie Madill075edd82013-07-08 13:30:19 -040081%option yylineno reentrant bison-bridge bison-locations
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000082%option extra-type="TParseContext*"
Olli Etuaho2728eda2015-03-16 10:23:50 +020083%x FIELDS
alokp@chromium.org29d56fb2010-04-06 15:42:22 +000084
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000085D [0-9]
86L [a-zA-Z_]
87H [a-fA-F0-9]
88E [Ee][+-]?{D}+
89O [0-7]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000090
91%%
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000092
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000093%{
94 TParseContext* context = yyextra;
95%}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000096
Jamie Madill56b06512013-05-24 16:34:04 -040097"invariant" { return INVARIANT; }
98"highp" { return HIGH_PRECISION; }
99"mediump" { return MEDIUM_PRECISION; }
100"lowp" { return LOW_PRECISION; }
101"precision" { return PRECISION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000102
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000103"attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
Jamie Madill56b06512013-05-24 16:34:04 -0400104"const" { return CONST_QUAL; }
105"uniform" { return UNIFORM; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000106"varying" { return ES2_keyword_ES3_reserved(context, VARYING); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000107
Jamie Madill56b06512013-05-24 16:34:04 -0400108"break" { return BREAK; }
109"continue" { return CONTINUE; }
110"do" { return DO; }
111"for" { return FOR; }
112"while" { return WHILE; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000113
Jamie Madill56b06512013-05-24 16:34:04 -0400114"if" { return IF; }
115"else" { return ELSE; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000116"switch" { return ES2_reserved_ES3_keyword(context, SWITCH); }
Jamie Madill5c55caf2014-02-18 15:27:18 -0500117"case" { return ES2_ident_ES3_keyword(context, CASE); }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000118"default" { return ES2_reserved_ES3_keyword(context, DEFAULT); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000119
Jamie Madill5c55caf2014-02-18 15:27:18 -0500120"centroid" { return ES2_ident_ES3_keyword(context, CENTROID); }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000121"flat" { return ES2_reserved_ES3_keyword(context, FLAT); }
Jamie Madill5c55caf2014-02-18 15:27:18 -0500122"smooth" { return ES2_ident_ES3_keyword(context, SMOOTH); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123
Jamie Madill56b06512013-05-24 16:34:04 -0400124"in" { return IN_QUAL; }
125"out" { return OUT_QUAL; }
126"inout" { return INOUT_QUAL; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000127
Jamie Madill78eb5df2013-05-24 16:34:05 -0400128"float" { return FLOAT_TYPE; }
129"int" { return INT_TYPE; }
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000130"uint" { return ES2_ident_ES3_keyword(context, UINT_TYPE); }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400131"void" { return VOID_TYPE; }
132"bool" { return BOOL_TYPE; }
Jamie Madill56b06512013-05-24 16:34:04 -0400133"true" { yylval->lex.b = true; return BOOLCONSTANT; }
134"false" { yylval->lex.b = false; return BOOLCONSTANT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135
Jamie Madill56b06512013-05-24 16:34:04 -0400136"discard" { return DISCARD; }
137"return" { return RETURN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000138
Jamie Madill78eb5df2013-05-24 16:34:05 -0400139"mat2" { return MATRIX2; }
140"mat3" { return MATRIX3; }
141"mat4" { return MATRIX4; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000142
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000143"mat2x2" { return ES2_ident_ES3_keyword(context, MATRIX2); }
144"mat3x3" { return ES2_ident_ES3_keyword(context, MATRIX3); }
145"mat4x4" { return ES2_ident_ES3_keyword(context, MATRIX4); }
146
147"mat2x3" { return ES2_ident_ES3_keyword(context, MATRIX2x3); }
148"mat3x2" { return ES2_ident_ES3_keyword(context, MATRIX3x2); }
149"mat2x4" { return ES2_ident_ES3_keyword(context, MATRIX2x4); }
150"mat4x2" { return ES2_ident_ES3_keyword(context, MATRIX4x2); }
151"mat3x4" { return ES2_ident_ES3_keyword(context, MATRIX3x4); }
152"mat4x3" { return ES2_ident_ES3_keyword(context, MATRIX4x3); }
153
Jamie Madill78eb5df2013-05-24 16:34:05 -0400154"vec2" { return VEC2; }
155"vec3" { return VEC3; }
156"vec4" { return VEC4; }
157"ivec2" { return IVEC2; }
158"ivec3" { return IVEC3; }
159"ivec4" { return IVEC4; }
160"bvec2" { return BVEC2; }
161"bvec3" { return BVEC3; }
162"bvec4" { return BVEC4; }
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000163"uvec2" { return ES2_ident_ES3_keyword(context, UVEC2); }
164"uvec3" { return ES2_ident_ES3_keyword(context, UVEC3); }
165"uvec4" { return ES2_ident_ES3_keyword(context, UVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000166
Nicolas Capens2a1d8a32013-07-18 11:49:40 -0400167"sampler2D" { return SAMPLER2D; }
168"samplerCube" { return SAMPLERCUBE; }
169"samplerExternalOES" { return SAMPLER_EXTERNAL_OES; }
170"sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
171"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
172"sampler2DRect" { return SAMPLER2DRECT; }
173"sampler2DArray" { return ES2_ident_ES3_keyword(context, SAMPLER2DARRAY); }
174"isampler2D" { return ES2_ident_ES3_keyword(context, ISAMPLER2D); }
175"isampler3D" { return ES2_ident_ES3_keyword(context, ISAMPLER3D); }
176"isamplerCube" { return ES2_ident_ES3_keyword(context, ISAMPLERCUBE); }
177"isampler2DArray" { return ES2_ident_ES3_keyword(context, ISAMPLER2DARRAY); }
178"usampler2D" { return ES2_ident_ES3_keyword(context, USAMPLER2D); }
179"usampler3D" { return ES2_ident_ES3_keyword(context, USAMPLER3D); }
180"usamplerCube" { return ES2_ident_ES3_keyword(context, USAMPLERCUBE); }
181"usampler2DArray" { return ES2_ident_ES3_keyword(context, USAMPLER2DARRAY); }
Jamie Madill5c55caf2014-02-18 15:27:18 -0500182"sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
Nicolas Capens2a1d8a32013-07-18 11:49:40 -0400183"samplerCubeShadow" { return ES2_ident_ES3_keyword(context, SAMPLERCUBESHADOW); }
184"sampler2DArrayShadow" { return ES2_ident_ES3_keyword(context, SAMPLER2DARRAYSHADOW); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000185
Jamie Madill78eb5df2013-05-24 16:34:05 -0400186"struct" { return STRUCT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000187
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000188"layout" { return ES2_ident_ES3_keyword(context, LAYOUT); }
189
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000190 /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
191"coherent" |
192"restrict" |
193"readonly" |
194"writeonly" |
195"resource" |
196"atomic_uint" |
197"noperspective" |
198"patch" |
199"sample" |
200"subroutine" |
201"common" |
202"partition" |
203"active" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000204
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000205"filter" |
206"image1D" |
207"image2D" |
208"image3D" |
209"imageCube" |
210"iimage1D" |
211"iimage2D" |
212"iimage3D" |
213"iimageCube" |
214"uimage1D" |
215"uimage2D" |
216"uimage3D" |
217"uimageCube" |
218"image1DArray" |
219"image2DArray" |
220"iimage1DArray" |
221"iimage2DArray" |
222"uimage1DArray" |
223"uimage2DArray" |
224"image1DShadow" |
225"image2DShadow" |
226"image1DArrayShadow" |
227"image2DArrayShadow" |
228"imageBuffer" |
229"iimageBuffer" |
230"uimageBuffer" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000231
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000232"sampler1DArray" |
233"sampler1DArrayShadow" |
234"isampler1D" |
235"isampler1DArray" |
236"usampler1D" |
237"usampler1DArray" |
238"isampler2DRect" |
239"usampler2DRect" |
240"samplerBuffer" |
241"isamplerBuffer" |
242"usamplerBuffer" |
243"sampler2DMS" |
244"isampler2DMS" |
245"usampler2DMS" |
246"sampler2DMSArray" |
247"isampler2DMSArray" |
248"usampler2DMSArray" {
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400249 if (context->getShaderVersion() < 300) {
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000250 yylval->lex.string = NewPoolTString(yytext);
251 return check_type(yyscanner);
252 }
253 return reserved_word(yyscanner);
254}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000255
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000256 /* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */
257"packed" {
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400258 if (context->getShaderVersion() >= 300)
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000259 {
260 yylval->lex.string = NewPoolTString(yytext);
261 return check_type(yyscanner);
262 }
263
264 return reserved_word(yyscanner);
265}
266
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000267 /* Reserved keywords */
268"asm" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000269
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000270"class" |
271"union" |
272"enum" |
273"typedef" |
274"template" |
275"this" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000277"goto" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000278
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000279"inline" |
280"noinline" |
281"volatile" |
282"public" |
283"static" |
284"extern" |
285"external" |
286"interface" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000287
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000288"long" |
289"short" |
290"double" |
291"half" |
292"fixed" |
293"unsigned" |
294"superp" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000295
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000296"input" |
297"output" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000298
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000299"hvec2" |
300"hvec3" |
301"hvec4" |
302"dvec2" |
303"dvec3" |
304"dvec4" |
305"fvec2" |
306"fvec3" |
307"fvec4" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000308
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000309"sampler1D" |
310"sampler1DShadow" |
311"sampler2DRectShadow" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000312
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000313"sizeof" |
314"cast" |
315
316"namespace" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000317"using" { return reserved_word(yyscanner); }
318
319{L}({L}|{D})* {
320 yylval->lex.string = NewPoolTString(yytext);
321 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000322}
323
Zhenyao Mof1d723c2013-09-23 14:57:07 -04003240[xX]{H}+ { return int_constant(yyscanner); }
3250{O}+ { return int_constant(yyscanner); }
326{D}+ { return int_constant(yyscanner); }
Jamie Madill56b06512013-05-24 16:34:04 -0400327
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +00003280[xX]{H}+[uU] { return uint_constant(context); }
3290{O}+[uU] { return uint_constant(context); }
330{D}+[uU] { return uint_constant(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000331
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400332{D}+{E} { return float_constant(yyscanner); }
333{D}+"."{D}*({E})? { return float_constant(yyscanner); }
334"."{D}+({E})? { return float_constant(yyscanner); }
Jamie Madill56b06512013-05-24 16:34:04 -0400335
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000336{D}+{E}[fF] { return floatsuffix_check(context); }
337{D}+"."{D}*({E})?[fF] { return floatsuffix_check(context); }
338"."{D}+({E})?[fF] { return floatsuffix_check(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000339
Jamie Madill56b06512013-05-24 16:34:04 -0400340"+=" { return ADD_ASSIGN; }
341"-=" { return SUB_ASSIGN; }
342"*=" { return MUL_ASSIGN; }
343"/=" { return DIV_ASSIGN; }
344"%=" { return MOD_ASSIGN; }
345"<<=" { return LEFT_ASSIGN; }
346">>=" { return RIGHT_ASSIGN; }
347"&=" { return AND_ASSIGN; }
348"^=" { return XOR_ASSIGN; }
349"|=" { return OR_ASSIGN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000350
Jamie Madill56b06512013-05-24 16:34:04 -0400351"++" { return INC_OP; }
352"--" { return DEC_OP; }
353"&&" { return AND_OP; }
354"||" { return OR_OP; }
355"^^" { return XOR_OP; }
356"<=" { return LE_OP; }
357">=" { return GE_OP; }
358"==" { return EQ_OP; }
359"!=" { return NE_OP; }
360"<<" { return LEFT_OP; }
361">>" { return RIGHT_OP; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400362";" { return SEMICOLON; }
363("{"|"<%") { return LEFT_BRACE; }
Jamie Madill56b06512013-05-24 16:34:04 -0400364("}"|"%>") { return RIGHT_BRACE; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400365"," { return COMMA; }
Jamie Madill56b06512013-05-24 16:34:04 -0400366":" { return COLON; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400367"=" { return EQUAL; }
368"(" { return LEFT_PAREN; }
369")" { return RIGHT_PAREN; }
Jamie Madill56b06512013-05-24 16:34:04 -0400370("["|"<:") { return LEFT_BRACKET; }
371("]"|":>") { return RIGHT_BRACKET; }
Olli Etuaho2728eda2015-03-16 10:23:50 +0200372"." { BEGIN(FIELDS); return DOT; }
Jamie Madill56b06512013-05-24 16:34:04 -0400373"!" { return BANG; }
374"-" { return DASH; }
375"~" { return TILDE; }
376"+" { return PLUS; }
377"*" { return STAR; }
378"/" { return SLASH; }
379"%" { return PERCENT; }
380"<" { return LEFT_ANGLE; }
381">" { return RIGHT_ANGLE; }
382"|" { return VERTICAL_BAR; }
383"^" { return CARET; }
384"&" { return AMPERSAND; }
385"?" { return QUESTION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000386
Olli Etuaho2728eda2015-03-16 10:23:50 +0200387<FIELDS>{L}({L}|{D})* {
388 BEGIN(INITIAL);
389 yylval->lex.string = NewPoolTString(yytext);
390 return FIELD_SELECTION;
391}
392<FIELDS>[ \t\v\f\r] {}
393
Jamie Madill39a8ce62013-06-13 10:30:38 -0400394[ \t\v\n\f\r] { }
Olli Etuaho2728eda2015-03-16 10:23:50 +0200395<*><<EOF>> { yyterminate(); }
396<*>. { assert(false); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000397
398%%
399
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000400yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000401 pp::Token token;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400402 yyget_extra(yyscanner)->getPreprocessor().lex(&token);
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000403 yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
404 if (len < max_size)
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000405 memcpy(buf, token.text.c_str(), len);
Jamie Madill075edd82013-07-08 13:30:19 -0400406 yyset_column(token.location.file, yyscanner);
407 yyset_lineno(token.location.line, yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000408
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000409 if (len >= max_size)
410 YY_FATAL_ERROR("Input buffer overflow");
411 else if (len > 0)
412 buf[len++] = ' ';
413 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000414}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000415
416int check_type(yyscan_t yyscanner) {
417 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
418
419 int token = IDENTIFIER;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400420 TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->getShaderVersion());
Jamie Madill78eb5df2013-05-24 16:34:05 -0400421 if (symbol && symbol->isVariable()) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000422 TVariable* variable = static_cast<TVariable*>(symbol);
423 if (variable->isUserType()) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000424 token = TYPE_NAME;
425 }
426 }
427 yylval->lex.symbol = symbol;
428 return token;
429}
430
431int reserved_word(yyscan_t yyscanner) {
432 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
433
Jamie Madill075edd82013-07-08 13:30:19 -0400434 yyextra->error(*yylloc, "Illegal use of reserved word", yytext, "");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000435 yyextra->recover();
436 return 0;
437}
438
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000439int ES2_reserved_ES3_keyword(TParseContext *context, int token)
440{
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400441 yyscan_t yyscanner = (yyscan_t) context->getScanner();
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000442
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400443 if (context->getShaderVersion() < 300)
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000444 {
445 return reserved_word(yyscanner);
446 }
447
448 return token;
449}
450
451int ES2_keyword_ES3_reserved(TParseContext *context, int token)
452{
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400453 yyscan_t yyscanner = (yyscan_t) context->getScanner();
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000454
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400455 if (context->getShaderVersion() >= 300)
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000456 {
457 return reserved_word(yyscanner);
458 }
459
460 return token;
461}
462
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +0000463int ES2_ident_ES3_keyword(TParseContext *context, int token)
464{
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400465 struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
466 yyscan_t yyscanner = (yyscan_t) context->getScanner();
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +0000467
468 // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400469 if (context->getShaderVersion() < 300)
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +0000470 {
471 yylval->lex.string = NewPoolTString(yytext);
472 return check_type(yyscanner);
473 }
474
475 return token;
476}
477
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000478int uint_constant(TParseContext *context)
479{
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400480 struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
481 yyscan_t yyscanner = (yyscan_t) context->getScanner();
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000482
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400483 if (context->getShaderVersion() < 300)
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000484 {
Jamie Madill075edd82013-07-08 13:30:19 -0400485 context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000486 context->recover();
487 return 0;
488 }
489
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400490 if (!atoi_clamp(yytext, &(yylval->lex.i)))
491 yyextra->warning(*yylloc, "Integer overflow", yytext, "");
492
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000493 return UINTCONSTANT;
494}
495
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000496int floatsuffix_check(TParseContext* context)
497{
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400498 struct yyguts_t* yyg = (struct yyguts_t*) context->getScanner();
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000499
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400500 if (context->getShaderVersion() < 300)
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000501 {
Jamie Madill075edd82013-07-08 13:30:19 -0400502 context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000503 context->recover();
504 return 0;
505 }
506
Corentin Walleze2adce12015-06-19 23:06:32 +0200507 std::string text = yytext;
508 text.resize(text.size() - 1);
509 if (!strtof_clamp(text, &(yylval->lex.f)))
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400510 yyextra->warning(*yylloc, "Float overflow", yytext, "");
511
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000512 return(FLOATCONSTANT);
513}
514
Jamie Madill185de882014-12-22 15:17:52 -0500515void yyerror(YYLTYPE* lloc, TParseContext* context, void *scanner, const char* reason) {
516 context->error(*lloc, reason, yyget_text(scanner));
Alok Priyadarshi0b67bfb2013-09-23 14:56:59 -0400517 context->recover();
518}
519
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400520int int_constant(yyscan_t yyscanner) {
521 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
522
523 if (!atoi_clamp(yytext, &(yylval->lex.i)))
524 yyextra->warning(*yylloc, "Integer overflow", yytext, "");
525 return INTCONSTANT;
526}
527
528int float_constant(yyscan_t yyscanner) {
529 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
530
Corentin Walleze2adce12015-06-19 23:06:32 +0200531 if (!strtof_clamp(yytext, &(yylval->lex.f)))
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400532 yyextra->warning(*yylloc, "Float overflow", yytext, "");
533 return FLOATCONSTANT;
534}
535
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000536int glslang_initialize(TParseContext* context) {
537 yyscan_t scanner = NULL;
538 if (yylex_init_extra(context, &scanner))
539 return 1;
540
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400541 context->setScanner(scanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000542 return 0;
543}
544
545int glslang_finalize(TParseContext* context) {
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400546 yyscan_t scanner = context->getScanner();
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000547 if (scanner == NULL) return 0;
548
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400549 context->setScanner(NULL);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000550 yylex_destroy(scanner);
551
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000552 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000553}
554
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000555int glslang_scan(size_t count, const char* const string[], const int length[],
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000556 TParseContext* context) {
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400557 yyrestart(NULL, context->getScanner());
558 yyset_column(0, context->getScanner());
559 yyset_lineno(1, context->getScanner());
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000560
561 // Initialize preprocessor.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400562 pp::Preprocessor *preprocessor = &context->getPreprocessor();
563
564 if (!preprocessor->init(count, string, length))
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000565 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000566
567 // Define extension macros.
568 const TExtensionBehavior& extBehavior = context->extensionBehavior();
569 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
570 iter != extBehavior.end(); ++iter) {
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400571 preprocessor->predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000572 }
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400573 if (context->getFragmentPrecisionHigh())
574 preprocessor->predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000575
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400576 preprocessor->setMaxTokenSize(GetGlobalMaxTokenSize(context->getShaderSpec()));
Jamie Madill5508f392014-02-20 13:31:36 -0500577
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000578 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000579}
580