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