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