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