daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | // |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 3 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 7 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 8 | This file contains the Lex specification for GLSL ES. |
| 9 | Based on ANSI C grammar, Lex specification: |
| 10 | http://www.lysator.liu.se/c/ANSI-C-grammar-l.html |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 11 | |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 12 | IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh, |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 13 | WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp). |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 16 | %top{ |
| 17 | // |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 18 | // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved. |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 19 | // Use of this source code is governed by a BSD-style license that can be |
| 20 | // found in the LICENSE file. |
| 21 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 22 | |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 23 | // This file is auto-generated by generate_parser.sh. DO NOT EDIT! |
apatrick@chromium.org | 536888b | 2012-01-25 02:10:25 +0000 | [diff] [blame] | 24 | |
| 25 | // Ignore errors in auto-generated code. |
| 26 | #if defined(__GNUC__) |
apatrick@chromium.org | a1d8059 | 2012-01-25 21:52:10 +0000 | [diff] [blame] | 27 | #pragma GCC diagnostic ignored "-Wunused-function" |
apatrick@chromium.org | 536888b | 2012-01-25 02:10:25 +0000 | [diff] [blame] | 28 | #pragma GCC diagnostic ignored "-Wunused-variable" |
apatrick@chromium.org | e057c5d | 2012-01-26 19:18:24 +0000 | [diff] [blame] | 29 | #pragma GCC diagnostic ignored "-Wswitch-enum" |
apatrick@chromium.org | 536888b | 2012-01-25 02:10:25 +0000 | [diff] [blame] | 30 | #elif defined(_MSC_VER) |
| 31 | #pragma warning(disable: 4065) |
apatrick@chromium.org | a1d8059 | 2012-01-25 21:52:10 +0000 | [diff] [blame] | 32 | #pragma warning(disable: 4189) |
| 33 | #pragma warning(disable: 4505) |
| 34 | #pragma warning(disable: 4701) |
apatrick@chromium.org | 536888b | 2012-01-25 02:10:25 +0000 | [diff] [blame] | 35 | #endif |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 36 | } |
| 37 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 38 | %{ |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 39 | #include "compiler/glslang.h" |
daniel@transgaming.com | e684229 | 2010-04-20 18:52:50 +0000 | [diff] [blame] | 40 | #include "compiler/ParseHelper.h" |
daniel@transgaming.com | b401a92 | 2012-10-26 18:58:24 +0000 | [diff] [blame] | 41 | #include "compiler/preprocessor/Token.h" |
daniel@transgaming.com | 91ed149 | 2010-10-29 03:11:43 +0000 | [diff] [blame] | 42 | #include "compiler/util.h" |
alokp@chromium.org | eab1ef1 | 2010-04-23 17:33:49 +0000 | [diff] [blame] | 43 | #include "glslang_tab.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 44 | |
| 45 | /* windows only pragma */ |
| 46 | #ifdef _MSC_VER |
| 47 | #pragma warning(disable : 4102) |
| 48 | #endif |
| 49 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 50 | #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.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 53 | |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 54 | static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner); |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 55 | static int check_type(yyscan_t yyscanner); |
| 56 | static int reserved_word(yyscan_t yyscanner); |
shannonwoods@chromium.org | 35f156d | 2013-05-30 00:18:04 +0000 | [diff] [blame] | 57 | static int ES2_reserved_ES3_keyword(TParseContext *context, int token); |
| 58 | static int ES2_keyword_ES3_reserved(TParseContext *context, int token); |
shannonwoods@chromium.org | 16242ef | 2013-05-30 00:18:11 +0000 | [diff] [blame] | 59 | static int ES2_ident_ES3_keyword(TParseContext *context, int token); |
shannonwoods@chromium.org | c8100b8 | 2013-05-30 00:20:34 +0000 | [diff] [blame] | 60 | static int uint_constant(TParseContext *context); |
shannonwoods@chromium.org | 4d20a84 | 2013-05-30 00:21:48 +0000 | [diff] [blame] | 61 | static int floatsuffix_check(TParseContext* context); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 62 | %} |
| 63 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 64 | %option noyywrap nounput never-interactive |
| 65 | %option yylineno reentrant bison-bridge |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 66 | %option extra-type="TParseContext*" |
Jamie Madill | 7eeb9b6 | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 67 | %x FIELDS |
alokp@chromium.org | 29d56fb | 2010-04-06 15:42:22 +0000 | [diff] [blame] | 68 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 69 | D [0-9] |
| 70 | L [a-zA-Z_] |
| 71 | H [a-fA-F0-9] |
| 72 | E [Ee][+-]?{D}+ |
| 73 | O [0-7] |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 74 | |
| 75 | %% |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 76 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 77 | %{ |
| 78 | TParseContext* context = yyextra; |
| 79 | %} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 80 | |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 81 | "invariant" { return INVARIANT; } |
| 82 | "highp" { return HIGH_PRECISION; } |
| 83 | "mediump" { return MEDIUM_PRECISION; } |
| 84 | "lowp" { return LOW_PRECISION; } |
| 85 | "precision" { return PRECISION; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 86 | |
shannonwoods@chromium.org | 35f156d | 2013-05-30 00:18:04 +0000 | [diff] [blame] | 87 | "attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); } |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 88 | "const" { return CONST_QUAL; } |
| 89 | "uniform" { return UNIFORM; } |
shannonwoods@chromium.org | 35f156d | 2013-05-30 00:18:04 +0000 | [diff] [blame] | 90 | "varying" { return ES2_keyword_ES3_reserved(context, VARYING); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 91 | |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 92 | "break" { return BREAK; } |
| 93 | "continue" { return CONTINUE; } |
| 94 | "do" { return DO; } |
| 95 | "for" { return FOR; } |
| 96 | "while" { return WHILE; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 97 | |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 98 | "if" { return IF; } |
| 99 | "else" { return ELSE; } |
shannonwoods@chromium.org | 35f156d | 2013-05-30 00:18:04 +0000 | [diff] [blame] | 100 | "switch" { return ES2_reserved_ES3_keyword(context, SWITCH); } |
| 101 | "case" { return ES2_reserved_ES3_keyword(context, CASE); } |
| 102 | "default" { return ES2_reserved_ES3_keyword(context, DEFAULT); } |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 103 | |
shannonwoods@chromium.org | 35f156d | 2013-05-30 00:18:04 +0000 | [diff] [blame] | 104 | "centroid" { return ES2_reserved_ES3_keyword(context, CENTROID); } |
| 105 | "flat" { return ES2_reserved_ES3_keyword(context, FLAT); } |
| 106 | "smooth" { return ES2_reserved_ES3_keyword(context, SMOOTH); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 107 | |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 108 | "in" { return IN_QUAL; } |
| 109 | "out" { return OUT_QUAL; } |
| 110 | "inout" { return INOUT_QUAL; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 111 | |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 112 | "float" { return FLOAT_TYPE; } |
| 113 | "int" { return INT_TYPE; } |
shannonwoods@chromium.org | 6b70991 | 2013-05-30 00:20:04 +0000 | [diff] [blame] | 114 | "uint" { return ES2_ident_ES3_keyword(context, UINT_TYPE); } |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 115 | "void" { return VOID_TYPE; } |
| 116 | "bool" { return BOOL_TYPE; } |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 117 | "true" { yylval->lex.b = true; return BOOLCONSTANT; } |
| 118 | "false" { yylval->lex.b = false; return BOOLCONSTANT; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 119 | |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 120 | "discard" { return DISCARD; } |
| 121 | "return" { return RETURN; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 122 | |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 123 | "mat2" { return MATRIX2; } |
| 124 | "mat3" { return MATRIX3; } |
| 125 | "mat4" { return MATRIX4; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 126 | |
shannonwoods@chromium.org | 9bd22fa | 2013-05-30 00:18:47 +0000 | [diff] [blame] | 127 | "mat2x2" { return ES2_ident_ES3_keyword(context, MATRIX2); } |
| 128 | "mat3x3" { return ES2_ident_ES3_keyword(context, MATRIX3); } |
| 129 | "mat4x4" { return ES2_ident_ES3_keyword(context, MATRIX4); } |
| 130 | |
| 131 | "mat2x3" { return ES2_ident_ES3_keyword(context, MATRIX2x3); } |
| 132 | "mat3x2" { return ES2_ident_ES3_keyword(context, MATRIX3x2); } |
| 133 | "mat2x4" { return ES2_ident_ES3_keyword(context, MATRIX2x4); } |
| 134 | "mat4x2" { return ES2_ident_ES3_keyword(context, MATRIX4x2); } |
| 135 | "mat3x4" { return ES2_ident_ES3_keyword(context, MATRIX3x4); } |
| 136 | "mat4x3" { return ES2_ident_ES3_keyword(context, MATRIX4x3); } |
| 137 | |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 138 | "vec2" { return VEC2; } |
| 139 | "vec3" { return VEC3; } |
| 140 | "vec4" { return VEC4; } |
| 141 | "ivec2" { return IVEC2; } |
| 142 | "ivec3" { return IVEC3; } |
| 143 | "ivec4" { return IVEC4; } |
| 144 | "bvec2" { return BVEC2; } |
| 145 | "bvec3" { return BVEC3; } |
| 146 | "bvec4" { return BVEC4; } |
shannonwoods@chromium.org | 8c788e8 | 2013-05-30 00:20:21 +0000 | [diff] [blame] | 147 | "uvec2" { return ES2_ident_ES3_keyword(context, UVEC2); } |
| 148 | "uvec3" { return ES2_ident_ES3_keyword(context, UVEC3); } |
| 149 | "uvec4" { return ES2_ident_ES3_keyword(context, UVEC4); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 150 | |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 151 | "sampler2D" { return SAMPLER2D; } |
| 152 | "samplerCube" { return SAMPLERCUBE; } |
| 153 | "samplerExternalOES" { return SAMPLER_EXTERNAL_OES; } |
shannonwoods@chromium.org | 35f156d | 2013-05-30 00:18:04 +0000 | [diff] [blame] | 154 | "sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); } |
| 155 | "sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); } |
| 156 | "sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); } |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 157 | "sampler2DRect" { return SAMPLER2DRECT; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 158 | |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 159 | "struct" { return STRUCT; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 160 | |
shannonwoods@chromium.org | 302adfe | 2013-05-30 00:21:06 +0000 | [diff] [blame] | 161 | "layout" { return ES2_ident_ES3_keyword(context, LAYOUT); } |
| 162 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 163 | /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */ |
| 164 | "coherent" | |
| 165 | "restrict" | |
| 166 | "readonly" | |
| 167 | "writeonly" | |
| 168 | "resource" | |
| 169 | "atomic_uint" | |
| 170 | "noperspective" | |
| 171 | "patch" | |
| 172 | "sample" | |
| 173 | "subroutine" | |
| 174 | "common" | |
| 175 | "partition" | |
| 176 | "active" | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 177 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 178 | "filter" | |
| 179 | "image1D" | |
| 180 | "image2D" | |
| 181 | "image3D" | |
| 182 | "imageCube" | |
| 183 | "iimage1D" | |
| 184 | "iimage2D" | |
| 185 | "iimage3D" | |
| 186 | "iimageCube" | |
| 187 | "uimage1D" | |
| 188 | "uimage2D" | |
| 189 | "uimage3D" | |
| 190 | "uimageCube" | |
| 191 | "image1DArray" | |
| 192 | "image2DArray" | |
| 193 | "iimage1DArray" | |
| 194 | "iimage2DArray" | |
| 195 | "uimage1DArray" | |
| 196 | "uimage2DArray" | |
| 197 | "image1DShadow" | |
| 198 | "image2DShadow" | |
| 199 | "image1DArrayShadow" | |
| 200 | "image2DArrayShadow" | |
| 201 | "imageBuffer" | |
| 202 | "iimageBuffer" | |
| 203 | "uimageBuffer" | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 204 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 205 | "sampler1DArray" | |
| 206 | "sampler1DArrayShadow" | |
| 207 | "isampler1D" | |
| 208 | "isampler1DArray" | |
| 209 | "usampler1D" | |
| 210 | "usampler1DArray" | |
| 211 | "isampler2DRect" | |
| 212 | "usampler2DRect" | |
| 213 | "samplerBuffer" | |
| 214 | "isamplerBuffer" | |
| 215 | "usamplerBuffer" | |
| 216 | "sampler2DMS" | |
| 217 | "isampler2DMS" | |
| 218 | "usampler2DMS" | |
| 219 | "sampler2DMSArray" | |
| 220 | "isampler2DMSArray" | |
| 221 | "usampler2DMSArray" { |
| 222 | if (context->shaderVersion < 300) { |
| 223 | yylval->lex.string = NewPoolTString(yytext); |
| 224 | return check_type(yyscanner); |
| 225 | } |
| 226 | return reserved_word(yyscanner); |
| 227 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 228 | |
shannonwoods@chromium.org | 302adfe | 2013-05-30 00:21:06 +0000 | [diff] [blame] | 229 | /* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */ |
| 230 | "packed" { |
| 231 | if (context->shaderVersion >= 300) |
| 232 | { |
| 233 | yylval->lex.string = NewPoolTString(yytext); |
| 234 | return check_type(yyscanner); |
| 235 | } |
| 236 | |
| 237 | return reserved_word(yyscanner); |
| 238 | } |
| 239 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 240 | /* Reserved keywords */ |
| 241 | "asm" | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 242 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 243 | "class" | |
| 244 | "union" | |
| 245 | "enum" | |
| 246 | "typedef" | |
| 247 | "template" | |
| 248 | "this" | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 249 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 250 | "goto" | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 251 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 252 | "inline" | |
| 253 | "noinline" | |
| 254 | "volatile" | |
| 255 | "public" | |
| 256 | "static" | |
| 257 | "extern" | |
| 258 | "external" | |
| 259 | "interface" | |
daniel@transgaming.com | beadd5d | 2012-04-12 02:35:31 +0000 | [diff] [blame] | 260 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 261 | "long" | |
| 262 | "short" | |
| 263 | "double" | |
| 264 | "half" | |
| 265 | "fixed" | |
| 266 | "unsigned" | |
| 267 | "superp" | |
daniel@transgaming.com | beadd5d | 2012-04-12 02:35:31 +0000 | [diff] [blame] | 268 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 269 | "input" | |
| 270 | "output" | |
daniel@transgaming.com | beadd5d | 2012-04-12 02:35:31 +0000 | [diff] [blame] | 271 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 272 | "hvec2" | |
| 273 | "hvec3" | |
| 274 | "hvec4" | |
| 275 | "dvec2" | |
| 276 | "dvec3" | |
| 277 | "dvec4" | |
| 278 | "fvec2" | |
| 279 | "fvec3" | |
| 280 | "fvec4" | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 281 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 282 | "sampler1D" | |
| 283 | "sampler1DShadow" | |
| 284 | "sampler2DRectShadow" | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 285 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 286 | "sizeof" | |
| 287 | "cast" | |
| 288 | |
| 289 | "namespace" | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 290 | "using" { return reserved_word(yyscanner); } |
| 291 | |
| 292 | {L}({L}|{D})* { |
| 293 | yylval->lex.string = NewPoolTString(yytext); |
| 294 | return check_type(yyscanner); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 297 | 0[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; } |
| 298 | 0{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; } |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 299 | {D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; } |
| 300 | |
shannonwoods@chromium.org | c8100b8 | 2013-05-30 00:20:34 +0000 | [diff] [blame] | 301 | 0[xX]{H}+[uU] { return uint_constant(context); } |
| 302 | 0{O}+[uU] { return uint_constant(context); } |
| 303 | {D}+[uU] { return uint_constant(context); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 304 | |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 305 | {D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; } |
| 306 | {D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; } |
| 307 | "."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; } |
| 308 | |
shannonwoods@chromium.org | 4d20a84 | 2013-05-30 00:21:48 +0000 | [diff] [blame] | 309 | {D}+{E}[fF] { return floatsuffix_check(context); } |
| 310 | {D}+"."{D}*({E})?[fF] { return floatsuffix_check(context); } |
| 311 | "."{D}+({E})?[fF] { return floatsuffix_check(context); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 312 | |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 313 | "+=" { return ADD_ASSIGN; } |
| 314 | "-=" { return SUB_ASSIGN; } |
| 315 | "*=" { return MUL_ASSIGN; } |
| 316 | "/=" { return DIV_ASSIGN; } |
| 317 | "%=" { return MOD_ASSIGN; } |
| 318 | "<<=" { return LEFT_ASSIGN; } |
| 319 | ">>=" { return RIGHT_ASSIGN; } |
| 320 | "&=" { return AND_ASSIGN; } |
| 321 | "^=" { return XOR_ASSIGN; } |
| 322 | "|=" { return OR_ASSIGN; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 323 | |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 324 | "++" { return INC_OP; } |
| 325 | "--" { return DEC_OP; } |
| 326 | "&&" { return AND_OP; } |
| 327 | "||" { return OR_OP; } |
| 328 | "^^" { return XOR_OP; } |
| 329 | "<=" { return LE_OP; } |
| 330 | ">=" { return GE_OP; } |
| 331 | "==" { return EQ_OP; } |
| 332 | "!=" { return NE_OP; } |
| 333 | "<<" { return LEFT_OP; } |
| 334 | ">>" { return RIGHT_OP; } |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 335 | ";" { return SEMICOLON; } |
| 336 | ("{"|"<%") { return LEFT_BRACE; } |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 337 | ("}"|"%>") { return RIGHT_BRACE; } |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 338 | "," { return COMMA; } |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 339 | ":" { return COLON; } |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 340 | "=" { return EQUAL; } |
| 341 | "(" { return LEFT_PAREN; } |
| 342 | ")" { return RIGHT_PAREN; } |
Jamie Madill | 56b0651 | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 343 | ("["|"<:") { return LEFT_BRACKET; } |
| 344 | ("]"|":>") { return RIGHT_BRACKET; } |
| 345 | "." { BEGIN(FIELDS); return DOT; } |
| 346 | "!" { return BANG; } |
| 347 | "-" { return DASH; } |
| 348 | "~" { return TILDE; } |
| 349 | "+" { return PLUS; } |
| 350 | "*" { return STAR; } |
| 351 | "/" { return SLASH; } |
| 352 | "%" { return PERCENT; } |
| 353 | "<" { return LEFT_ANGLE; } |
| 354 | ">" { return RIGHT_ANGLE; } |
| 355 | "|" { return VERTICAL_BAR; } |
| 356 | "^" { return CARET; } |
| 357 | "&" { return AMPERSAND; } |
| 358 | "?" { return QUESTION; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 359 | |
| 360 | <FIELDS>{L}({L}|{D})* { |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 361 | BEGIN(INITIAL); |
| 362 | yylval->lex.string = NewPoolTString(yytext); |
| 363 | return FIELD_SELECTION; |
| 364 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 365 | <FIELDS>[ \t\v\f\r] {} |
| 366 | |
Jamie Madill | 39a8ce6 | 2013-06-13 10:30:38 -0400 | [diff] [blame^] | 367 | [ \t\v\n\f\r] { } |
| 368 | <*><<EOF>> { yyterminate(); } |
| 369 | <*>. { assert(false); return 0; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 370 | |
| 371 | %% |
| 372 | |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 373 | yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) { |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 374 | pp::Token token; |
| 375 | yyget_extra(yyscanner)->preprocessor.lex(&token); |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 376 | yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size(); |
| 377 | if (len < max_size) |
alokp@chromium.org | 5b6a68e | 2012-06-28 20:29:13 +0000 | [diff] [blame] | 378 | memcpy(buf, token.text.c_str(), len); |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 379 | yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner); |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 380 | |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 381 | if (len >= max_size) |
| 382 | YY_FATAL_ERROR("Input buffer overflow"); |
| 383 | else if (len > 0) |
| 384 | buf[len++] = ' '; |
| 385 | return len; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 386 | } |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 387 | |
| 388 | int check_type(yyscan_t yyscanner) { |
| 389 | struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; |
| 390 | |
| 391 | int token = IDENTIFIER; |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 392 | TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion); |
Jamie Madill | 78eb5df | 2013-05-24 16:34:05 -0400 | [diff] [blame] | 393 | if (symbol && symbol->isVariable()) { |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 394 | TVariable* variable = static_cast<TVariable*>(symbol); |
| 395 | if (variable->isUserType()) { |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 396 | token = TYPE_NAME; |
| 397 | } |
| 398 | } |
| 399 | yylval->lex.symbol = symbol; |
| 400 | return token; |
| 401 | } |
| 402 | |
| 403 | int reserved_word(yyscan_t yyscanner) { |
| 404 | struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; |
| 405 | |
| 406 | yyextra->error(yylineno, "Illegal use of reserved word", yytext, ""); |
| 407 | yyextra->recover(); |
| 408 | return 0; |
| 409 | } |
| 410 | |
shannonwoods@chromium.org | 35f156d | 2013-05-30 00:18:04 +0000 | [diff] [blame] | 411 | int ES2_reserved_ES3_keyword(TParseContext *context, int token) |
| 412 | { |
| 413 | yyscan_t yyscanner = (yyscan_t) context->scanner; |
| 414 | |
| 415 | if (context->shaderVersion < 300) |
| 416 | { |
| 417 | return reserved_word(yyscanner); |
| 418 | } |
| 419 | |
| 420 | return token; |
| 421 | } |
| 422 | |
| 423 | int ES2_keyword_ES3_reserved(TParseContext *context, int token) |
| 424 | { |
| 425 | yyscan_t yyscanner = (yyscan_t) context->scanner; |
| 426 | |
| 427 | if (context->shaderVersion >= 300) |
| 428 | { |
| 429 | return reserved_word(yyscanner); |
| 430 | } |
| 431 | |
| 432 | return token; |
| 433 | } |
| 434 | |
shannonwoods@chromium.org | 16242ef | 2013-05-30 00:18:11 +0000 | [diff] [blame] | 435 | int ES2_ident_ES3_keyword(TParseContext *context, int token) |
| 436 | { |
| 437 | struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; |
| 438 | yyscan_t yyscanner = (yyscan_t) context->scanner; |
| 439 | |
| 440 | // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name |
| 441 | if (context->shaderVersion < 300) |
| 442 | { |
| 443 | yylval->lex.string = NewPoolTString(yytext); |
| 444 | return check_type(yyscanner); |
| 445 | } |
| 446 | |
| 447 | return token; |
| 448 | } |
| 449 | |
shannonwoods@chromium.org | c8100b8 | 2013-05-30 00:20:34 +0000 | [diff] [blame] | 450 | int uint_constant(TParseContext *context) |
| 451 | { |
| 452 | struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; |
| 453 | yyscan_t yyscanner = (yyscan_t) context->scanner; |
| 454 | |
shannonwoods@chromium.org | 4d20a84 | 2013-05-30 00:21:48 +0000 | [diff] [blame] | 455 | yylval->lex.u = static_cast<unsigned int>(strtol(yytext, 0, 0)); |
| 456 | |
shannonwoods@chromium.org | c8100b8 | 2013-05-30 00:20:34 +0000 | [diff] [blame] | 457 | if (context->shaderVersion < 300) |
| 458 | { |
| 459 | context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, ""); |
| 460 | context->recover(); |
| 461 | return 0; |
| 462 | } |
| 463 | |
shannonwoods@chromium.org | c8100b8 | 2013-05-30 00:20:34 +0000 | [diff] [blame] | 464 | return UINTCONSTANT; |
| 465 | } |
| 466 | |
shannonwoods@chromium.org | 4d20a84 | 2013-05-30 00:21:48 +0000 | [diff] [blame] | 467 | int floatsuffix_check(TParseContext* context) |
| 468 | { |
| 469 | struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; |
| 470 | |
| 471 | yylval->lex.f = static_cast<float>(atof_dot(yytext)); |
| 472 | |
| 473 | if (context->shaderVersion < 300) |
| 474 | { |
| 475 | context->error(yylineno, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext); |
| 476 | context->recover(); |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | return(FLOATCONSTANT); |
| 481 | } |
| 482 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 483 | void yyerror(TParseContext* context, const char* reason) { |
| 484 | struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; |
| 485 | |
Jamie Madill | fe345bf | 2013-05-24 16:34:04 -0400 | [diff] [blame] | 486 | context->error(yylineno, reason, yytext); |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 487 | context->recover(); |
| 488 | } |
| 489 | |
| 490 | int glslang_initialize(TParseContext* context) { |
| 491 | yyscan_t scanner = NULL; |
| 492 | if (yylex_init_extra(context, &scanner)) |
| 493 | return 1; |
| 494 | |
| 495 | context->scanner = scanner; |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | int glslang_finalize(TParseContext* context) { |
| 500 | yyscan_t scanner = context->scanner; |
| 501 | if (scanner == NULL) return 0; |
| 502 | |
| 503 | context->scanner = NULL; |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 504 | yylex_destroy(scanner); |
| 505 | |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 506 | return 0; |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 507 | } |
| 508 | |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 509 | int glslang_scan(size_t count, const char* const string[], const int length[], |
alokp@chromium.org | 408c45e | 2012-04-05 15:54:43 +0000 | [diff] [blame] | 510 | TParseContext* context) { |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 511 | yyrestart(NULL, context->scanner); |
| 512 | yyset_lineno(EncodeSourceLoc(0, 1), context->scanner); |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 513 | |
| 514 | // Initialize preprocessor. |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 515 | if (!context->preprocessor.init(count, string, length)) |
| 516 | return 1; |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 517 | |
| 518 | // Define extension macros. |
| 519 | const TExtensionBehavior& extBehavior = context->extensionBehavior(); |
| 520 | for (TExtensionBehavior::const_iterator iter = extBehavior.begin(); |
| 521 | iter != extBehavior.end(); ++iter) { |
alokp@chromium.org | e3043b1 | 2012-06-19 19:40:52 +0000 | [diff] [blame] | 522 | context->preprocessor.predefineMacro(iter->first.c_str(), 1); |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 523 | } |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 524 | if (context->fragmentPrecisionHigh) |
| 525 | context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1); |
| 526 | |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 527 | return 0; |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 528 | } |
| 529 | |