blob: 2435f7cb12fb5c02ba9305ae8312c9795c994e54 [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)
31#pragma warning(disable: 4065)
apatrick@chromium.orga1d80592012-01-25 21:52:10 +000032#pragma warning(disable: 4189)
33#pragma warning(disable: 4505)
34#pragma warning(disable: 4701)
apatrick@chromium.org536888b2012-01-25 02:10:25 +000035#endif
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000036}
37
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038%{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000039#include "compiler/glslang.h"
daniel@transgaming.come6842292010-04-20 18:52:50 +000040#include "compiler/ParseHelper.h"
daniel@transgaming.comb401a922012-10-26 18:58:24 +000041#include "compiler/preprocessor/Token.h"
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000042#include "compiler/util.h"
alokp@chromium.orgeab1ef12010-04-23 17:33:49 +000043#include "glslang_tab.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000044
45/* windows only pragma */
46#ifdef _MSC_VER
47#pragma warning(disable : 4102)
48#endif
49
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000050#define YY_USER_ACTION yylval->lex.line = yylineno;
51#define YY_INPUT(buf, result, max_size) \
52 result = string_input(buf, max_size, yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000053
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000054static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000055static int check_type(yyscan_t yyscanner);
56static int reserved_word(yyscan_t yyscanner);
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000057static int ES2_reserved_ES3_keyword(TParseContext *context, int token);
58static int ES2_keyword_ES3_reserved(TParseContext *context, int token);
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +000059static int ES2_ident_ES3_keyword(TParseContext *context, int token);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000060%}
61
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000062%option noyywrap nounput never-interactive
63%option yylineno reentrant bison-bridge
64%option stack
65%option extra-type="TParseContext*"
66%x COMMENT FIELDS
alokp@chromium.org29d56fb2010-04-06 15:42:22 +000067
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000068D [0-9]
69L [a-zA-Z_]
70H [a-fA-F0-9]
71E [Ee][+-]?{D}+
72O [0-7]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000073
74%%
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000075
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000076%{
77 TParseContext* context = yyextra;
78%}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000079
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000080 /* Single-line comments */
81"//"[^\n]* ;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000082
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000083 /* Multi-line comments */
84"/*" { yy_push_state(COMMENT, yyscanner); }
85<COMMENT>. |
86<COMMENT>\n ;
87<COMMENT>"*/" { yy_pop_state(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000088
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000089"invariant" { return(INVARIANT); }
90"highp" { return(HIGH_PRECISION); }
91"mediump" { return(MEDIUM_PRECISION); }
92"lowp" { return(LOW_PRECISION); }
93"precision" { return(PRECISION); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000094
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000095"attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000096"const" { return(CONST_QUAL); }
97"uniform" { return(UNIFORM); }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000098"varying" { return ES2_keyword_ES3_reserved(context, VARYING); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000100"break" { return(BREAK); }
101"continue" { return(CONTINUE); }
102"do" { return(DO); }
103"for" { return(FOR); }
104"while" { return(WHILE); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000105
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000106"if" { return(IF); }
107"else" { return(ELSE); }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000108"switch" { return ES2_reserved_ES3_keyword(context, SWITCH); }
109"case" { return ES2_reserved_ES3_keyword(context, CASE); }
110"default" { return ES2_reserved_ES3_keyword(context, DEFAULT); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000111
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000112"centroid" { return ES2_reserved_ES3_keyword(context, CENTROID); }
113"flat" { return ES2_reserved_ES3_keyword(context, FLAT); }
114"smooth" { return ES2_reserved_ES3_keyword(context, SMOOTH); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000115
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000116"in" { return(IN_QUAL); }
117"out" { return(OUT_QUAL); }
118"inout" { return(INOUT_QUAL); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000119
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000120"float" { context->lexAfterType = true; return(FLOAT_TYPE); }
121"int" { context->lexAfterType = true; return(INT_TYPE); }
122"void" { context->lexAfterType = true; return(VOID_TYPE); }
123"bool" { context->lexAfterType = true; return(BOOL_TYPE); }
124"true" { yylval->lex.b = true; return(BOOLCONSTANT); }
125"false" { yylval->lex.b = false; return(BOOLCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000126
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000127"discard" { return(DISCARD); }
128"return" { return(RETURN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000129
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000130"mat2" { context->lexAfterType = true; return(MATRIX2); }
131"mat3" { context->lexAfterType = true; return(MATRIX3); }
132"mat4" { context->lexAfterType = true; return(MATRIX4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000133
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000134"vec2" { context->lexAfterType = true; return (VEC2); }
135"vec3" { context->lexAfterType = true; return (VEC3); }
136"vec4" { context->lexAfterType = true; return (VEC4); }
137"ivec2" { context->lexAfterType = true; return (IVEC2); }
138"ivec3" { context->lexAfterType = true; return (IVEC3); }
139"ivec4" { context->lexAfterType = true; return (IVEC4); }
140"bvec2" { context->lexAfterType = true; return (BVEC2); }
141"bvec3" { context->lexAfterType = true; return (BVEC3); }
142"bvec4" { context->lexAfterType = true; return (BVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000143
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000144"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
145"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
zmo@google.com09c323a2011-08-12 18:22:25 +0000146"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000147"sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
148"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
149"sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000150"sampler2DRect" { context->lexAfterType = true; return SAMPLER2DRECT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000151
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000152"struct" { context->lexAfterType = true; return(STRUCT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000153
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000154 /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
155"coherent" |
156"restrict" |
157"readonly" |
158"writeonly" |
159"resource" |
160"atomic_uint" |
161"noperspective" |
162"patch" |
163"sample" |
164"subroutine" |
165"common" |
166"partition" |
167"active" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000168
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000169"filter" |
170"image1D" |
171"image2D" |
172"image3D" |
173"imageCube" |
174"iimage1D" |
175"iimage2D" |
176"iimage3D" |
177"iimageCube" |
178"uimage1D" |
179"uimage2D" |
180"uimage3D" |
181"uimageCube" |
182"image1DArray" |
183"image2DArray" |
184"iimage1DArray" |
185"iimage2DArray" |
186"uimage1DArray" |
187"uimage2DArray" |
188"image1DShadow" |
189"image2DShadow" |
190"image1DArrayShadow" |
191"image2DArrayShadow" |
192"imageBuffer" |
193"iimageBuffer" |
194"uimageBuffer" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000195
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000196"sampler1DArray" |
197"sampler1DArrayShadow" |
198"isampler1D" |
199"isampler1DArray" |
200"usampler1D" |
201"usampler1DArray" |
202"isampler2DRect" |
203"usampler2DRect" |
204"samplerBuffer" |
205"isamplerBuffer" |
206"usamplerBuffer" |
207"sampler2DMS" |
208"isampler2DMS" |
209"usampler2DMS" |
210"sampler2DMSArray" |
211"isampler2DMSArray" |
212"usampler2DMSArray" {
213 if (context->shaderVersion < 300) {
214 yylval->lex.string = NewPoolTString(yytext);
215 return check_type(yyscanner);
216 }
217 return reserved_word(yyscanner);
218}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000219
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000220 /* Reserved keywords */
221"asm" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000222
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000223"class" |
224"union" |
225"enum" |
226"typedef" |
227"template" |
228"this" |
229"packed" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000230
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000231"goto" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000232
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000233"inline" |
234"noinline" |
235"volatile" |
236"public" |
237"static" |
238"extern" |
239"external" |
240"interface" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000241
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000242"long" |
243"short" |
244"double" |
245"half" |
246"fixed" |
247"unsigned" |
248"superp" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000249
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000250"input" |
251"output" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000252
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000253"hvec2" |
254"hvec3" |
255"hvec4" |
256"dvec2" |
257"dvec3" |
258"dvec4" |
259"fvec2" |
260"fvec3" |
261"fvec4" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000262
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000263"sampler1D" |
264"sampler1DShadow" |
265"sampler2DRectShadow" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000266
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000267"sizeof" |
268"cast" |
269
270"namespace" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000271"using" { return reserved_word(yyscanner); }
272
273{L}({L}|{D})* {
274 yylval->lex.string = NewPoolTString(yytext);
275 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276}
277
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +00002780[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
2790{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002800{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;}
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000281{D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000282
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000283{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
284{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
285"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000286
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000287"+=" { return(ADD_ASSIGN); }
288"-=" { return(SUB_ASSIGN); }
289"*=" { return(MUL_ASSIGN); }
290"/=" { return(DIV_ASSIGN); }
291"%=" { return(MOD_ASSIGN); }
292"<<=" { return(LEFT_ASSIGN); }
293">>=" { return(RIGHT_ASSIGN); }
294"&=" { return(AND_ASSIGN); }
295"^=" { return(XOR_ASSIGN); }
296"|=" { return(OR_ASSIGN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000297
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000298"++" { return(INC_OP); }
299"--" { return(DEC_OP); }
300"&&" { return(AND_OP); }
301"||" { return(OR_OP); }
302"^^" { return(XOR_OP); }
303"<=" { return(LE_OP); }
304">=" { return(GE_OP); }
305"==" { return(EQ_OP); }
306"!=" { return(NE_OP); }
307"<<" { return(LEFT_OP); }
308">>" { return(RIGHT_OP); }
309";" { context->lexAfterType = false; return(SEMICOLON); }
310("{"|"<%") { context->lexAfterType = false; return(LEFT_BRACE); }
311("}"|"%>") { return(RIGHT_BRACE); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000312"," { if (context->inTypeParen) context->lexAfterType = false; return(COMMA); }
313":" { return(COLON); }
314"=" { context->lexAfterType = false; return(EQUAL); }
315"(" { context->lexAfterType = false; context->inTypeParen = true; return(LEFT_PAREN); }
316")" { context->inTypeParen = false; return(RIGHT_PAREN); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000317("["|"<:") { return(LEFT_BRACKET); }
318("]"|":>") { return(RIGHT_BRACKET); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000319"." { BEGIN(FIELDS); return(DOT); }
320"!" { return(BANG); }
321"-" { return(DASH); }
322"~" { return(TILDE); }
323"+" { return(PLUS); }
324"*" { return(STAR); }
325"/" { return(SLASH); }
326"%" { return(PERCENT); }
327"<" { return(LEFT_ANGLE); }
328">" { return(RIGHT_ANGLE); }
329"|" { return(VERTICAL_BAR); }
330"^" { return(CARET); }
331"&" { return(AMPERSAND); }
332"?" { return(QUESTION); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000333
334<FIELDS>{L}({L}|{D})* {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000335 BEGIN(INITIAL);
336 yylval->lex.string = NewPoolTString(yytext);
337 return FIELD_SELECTION;
338}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000339<FIELDS>[ \t\v\f\r] {}
340
341[ \t\v\n\f\r] { }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000342<*><<EOF>> { context->AfterEOF = true; yyterminate(); }
343<*>. { context->warning(yylineno, "Unknown char", yytext, ""); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000344
345%%
346
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000347yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000348 pp::Token token;
349 yyget_extra(yyscanner)->preprocessor.lex(&token);
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000350 yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
351 if (len < max_size)
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000352 memcpy(buf, token.text.c_str(), len);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000353 yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000354
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000355 if (len >= max_size)
356 YY_FATAL_ERROR("Input buffer overflow");
357 else if (len > 0)
358 buf[len++] = ' ';
359 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000360}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000361
362int check_type(yyscan_t yyscanner) {
363 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
364
365 int token = IDENTIFIER;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000366 TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000367 if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
368 TVariable* variable = static_cast<TVariable*>(symbol);
369 if (variable->isUserType()) {
370 yyextra->lexAfterType = true;
371 token = TYPE_NAME;
372 }
373 }
374 yylval->lex.symbol = symbol;
375 return token;
376}
377
378int reserved_word(yyscan_t yyscanner) {
379 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
380
381 yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
382 yyextra->recover();
383 return 0;
384}
385
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000386int ES2_reserved_ES3_keyword(TParseContext *context, int token)
387{
388 yyscan_t yyscanner = (yyscan_t) context->scanner;
389
390 if (context->shaderVersion < 300)
391 {
392 return reserved_word(yyscanner);
393 }
394
395 return token;
396}
397
398int ES2_keyword_ES3_reserved(TParseContext *context, int token)
399{
400 yyscan_t yyscanner = (yyscan_t) context->scanner;
401
402 if (context->shaderVersion >= 300)
403 {
404 return reserved_word(yyscanner);
405 }
406
407 return token;
408}
409
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +0000410int ES2_ident_ES3_keyword(TParseContext *context, int token)
411{
412 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
413 yyscan_t yyscanner = (yyscan_t) context->scanner;
414
415 // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name
416 if (context->shaderVersion < 300)
417 {
418 yylval->lex.string = NewPoolTString(yytext);
419 return check_type(yyscanner);
420 }
421
422 return token;
423}
424
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000425void yyerror(TParseContext* context, const char* reason) {
426 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
427
428 if (context->AfterEOF) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000429 context->error(yylineno, reason, "unexpected EOF");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000430 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000431 context->error(yylineno, reason, yytext);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000432 }
433 context->recover();
434}
435
436int glslang_initialize(TParseContext* context) {
437 yyscan_t scanner = NULL;
438 if (yylex_init_extra(context, &scanner))
439 return 1;
440
441 context->scanner = scanner;
442 return 0;
443}
444
445int glslang_finalize(TParseContext* context) {
446 yyscan_t scanner = context->scanner;
447 if (scanner == NULL) return 0;
448
449 context->scanner = NULL;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000450 yylex_destroy(scanner);
451
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000452 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000453}
454
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000455int glslang_scan(size_t count, const char* const string[], const int length[],
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000456 TParseContext* context) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000457 yyrestart(NULL, context->scanner);
458 yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
459 context->AfterEOF = false;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000460
461 // Initialize preprocessor.
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000462 if (!context->preprocessor.init(count, string, length))
463 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000464
465 // Define extension macros.
466 const TExtensionBehavior& extBehavior = context->extensionBehavior();
467 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
468 iter != extBehavior.end(); ++iter) {
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000469 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000470 }
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000471 if (context->fragmentPrecisionHigh)
472 context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
473
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000474 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000475}
476