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