Home | History | Annotate | Download | only in MachineIndependent
      1 //
      2 //Copyright (C) 2002-2005  3Dlabs Inc. Ltd.
      3 //Copyright (C) 2012-2013 LunarG, Inc.
      4 //
      5 //All rights reserved.
      6 //
      7 //Redistribution and use in source and binary forms, with or without
      8 //modification, are permitted provided that the following conditions
      9 //are met:
     10 //
     11 //    Redistributions of source code must retain the above copyright
     12 //    notice, this list of conditions and the following disclaimer.
     13 //
     14 //    Redistributions in binary form must reproduce the above
     15 //    copyright notice, this list of conditions and the following
     16 //    disclaimer in the documentation and/or other materials provided
     17 //    with the distribution.
     18 //
     19 //    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
     20 //    contributors may be used to endorse or promote products derived
     21 //    from this software without specific prior written permission.
     22 //
     23 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     24 //"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     25 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     26 //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     27 //COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     28 //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     29 //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     30 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     31 //CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     33 //ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34 //POSSIBILITY OF SUCH DAMAGE.
     35 //
     36 
     37 /**
     38  * This is bison grammar and productions for parsing all versions of the
     39  * GLSL shading languages.
     40  */
     41 %{
     42 
     43 /* Based on:
     44 ANSI C Yacc grammar
     45 
     46 In 1985, Jeff Lee published his Yacc grammar (which is accompanied by a
     47 matching Lex specification) for the April 30, 1985 draft version of the
     48 ANSI C standard.  Tom Stockfisch reposted it to net.sources in 1987; that
     49 original, as mentioned in the answer to question 17.25 of the comp.lang.c
     50 FAQ, can be ftp'ed from ftp.uu.net, file usenet/net.sources/ansi.c.grammar.Z.
     51 
     52 I intend to keep this version as close to the current C Standard grammar as
     53 possible; please let me know if you discover discrepancies.
     54 
     55 Jutta Degener, 1995
     56 */
     57 
     58 #include "SymbolTable.h"
     59 #include "ParseHelper.h"
     60 #include "../Public/ShaderLang.h"
     61 
     62 using namespace glslang;
     63 
     64 %}
     65 
     66 %union {
     67     struct {
     68         glslang::TSourceLoc loc;
     69         union {
     70             glslang::TString *string;
     71             int i;
     72             unsigned int u;
     73             long long i64;
     74             unsigned long long u64;
     75             bool b;
     76             double d;
     77         };
     78         glslang::TSymbol* symbol;
     79     } lex;
     80     struct {
     81         glslang::TSourceLoc loc;
     82         glslang::TOperator op;
     83         union {
     84             TIntermNode* intermNode;
     85             glslang::TIntermNodePair nodePair;
     86             glslang::TIntermTyped* intermTypedNode;
     87         };
     88         union {
     89             glslang::TPublicType type;
     90             glslang::TFunction* function;
     91             glslang::TParameter param;
     92             glslang::TTypeLoc typeLine;
     93             glslang::TTypeList* typeList;
     94             glslang::TArraySizes* arraySizes;
     95             glslang::TIdentifierList* identifierList;
     96         };
     97     } interm;
     98 }
     99 
    100 %{
    101 
    102 /* windows only pragma */
    103 #ifdef _MSC_VER
    104     #pragma warning(disable : 4065)
    105     #pragma warning(disable : 4127)
    106     #pragma warning(disable : 4244)
    107 #endif
    108 
    109 #define parseContext (*pParseContext)
    110 #define yyerror(context, msg) context->parserError(msg)
    111 
    112 extern int yylex(YYSTYPE*, TParseContext&);
    113 
    114 %}
    115 
    116 %parse-param {glslang::TParseContext* pParseContext}
    117 %lex-param {parseContext}
    118 %pure-parser  // enable thread safety
    119 %expect 1     // One shift reduce conflict because of if | else
    120 
    121 %token <lex> ATTRIBUTE VARYING
    122 %token <lex> CONST BOOL FLOAT DOUBLE INT UINT INT64_T UINT64_T
    123 %token <lex> BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT SUBROUTINE
    124 %token <lex> BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 I64VEC2 I64VEC3 I64VEC4 UVEC2 UVEC3 UVEC4 U64VEC2 U64VEC3 U64VEC4 VEC2 VEC3 VEC4
    125 %token <lex> MAT2 MAT3 MAT4 CENTROID IN OUT INOUT
    126 %token <lex> UNIFORM PATCH SAMPLE BUFFER SHARED
    127 %token <lex> COHERENT VOLATILE RESTRICT READONLY WRITEONLY
    128 %token <lex> DVEC2 DVEC3 DVEC4 DMAT2 DMAT3 DMAT4
    129 %token <lex> NOPERSPECTIVE FLAT SMOOTH LAYOUT
    130 
    131 %token <lex> MAT2X2 MAT2X3 MAT2X4
    132 %token <lex> MAT3X2 MAT3X3 MAT3X4
    133 %token <lex> MAT4X2 MAT4X3 MAT4X4
    134 %token <lex> DMAT2X2 DMAT2X3 DMAT2X4
    135 %token <lex> DMAT3X2 DMAT3X3 DMAT3X4
    136 %token <lex> DMAT4X2 DMAT4X3 DMAT4X4
    137 %token <lex> ATOMIC_UINT
    138 
    139 // combined image/sampler
    140 %token <lex> SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
    141 %token <lex> SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
    142 %token <lex> SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
    143 %token <lex> ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
    144 %token <lex> USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
    145 %token <lex> SAMPLER2DRECT SAMPLER2DRECTSHADOW ISAMPLER2DRECT USAMPLER2DRECT
    146 %token <lex> SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
    147 %token <lex> SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
    148 %token <lex> ISAMPLERCUBEARRAY USAMPLERCUBEARRAY
    149 %token <lex> SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
    150 %token <lex> SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
    151 %token <lex> SAMPLEREXTERNALOES
    152 
    153 // pure sampler
    154 %token <lex> SAMPLER SAMPLERSHADOW
    155 
    156 // texture without sampler
    157 %token <lex> TEXTURE1D TEXTURE2D TEXTURE3D TEXTURECUBE
    158 %token <lex> TEXTURE1DARRAY TEXTURE2DARRAY
    159 %token <lex> ITEXTURE1D ITEXTURE2D ITEXTURE3D ITEXTURECUBE
    160 %token <lex> ITEXTURE1DARRAY ITEXTURE2DARRAY UTEXTURE1D UTEXTURE2D UTEXTURE3D
    161 %token <lex> UTEXTURECUBE UTEXTURE1DARRAY UTEXTURE2DARRAY
    162 %token <lex> TEXTURE2DRECT ITEXTURE2DRECT UTEXTURE2DRECT
    163 %token <lex> TEXTUREBUFFER ITEXTUREBUFFER UTEXTUREBUFFER
    164 %token <lex> TEXTURECUBEARRAY ITEXTURECUBEARRAY UTEXTURECUBEARRAY
    165 %token <lex> TEXTURE2DMS ITEXTURE2DMS UTEXTURE2DMS
    166 %token <lex> TEXTURE2DMSARRAY ITEXTURE2DMSARRAY UTEXTURE2DMSARRAY
    167 
    168 // input attachments
    169 %token <lex> SUBPASSINPUT SUBPASSINPUTMS ISUBPASSINPUT ISUBPASSINPUTMS USUBPASSINPUT USUBPASSINPUTMS
    170 
    171 %token <lex> IMAGE1D IIMAGE1D UIMAGE1D IMAGE2D IIMAGE2D
    172 %token <lex> UIMAGE2D IMAGE3D IIMAGE3D UIMAGE3D
    173 %token <lex> IMAGE2DRECT IIMAGE2DRECT UIMAGE2DRECT
    174 %token <lex> IMAGECUBE IIMAGECUBE UIMAGECUBE
    175 %token <lex> IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
    176 %token <lex> IMAGE1DARRAY IIMAGE1DARRAY UIMAGE1DARRAY
    177 %token <lex> IMAGE2DARRAY IIMAGE2DARRAY UIMAGE2DARRAY
    178 %token <lex> IMAGECUBEARRAY IIMAGECUBEARRAY UIMAGECUBEARRAY
    179 %token <lex> IMAGE2DMS IIMAGE2DMS UIMAGE2DMS
    180 %token <lex> IMAGE2DMSARRAY IIMAGE2DMSARRAY UIMAGE2DMSARRAY
    181 
    182 %token <lex> STRUCT VOID WHILE
    183 
    184 %token <lex> IDENTIFIER TYPE_NAME
    185 %token <lex> FLOATCONSTANT DOUBLECONSTANT INTCONSTANT UINTCONSTANT INT64CONSTANT UINT64CONSTANT BOOLCONSTANT
    186 %token <lex> LEFT_OP RIGHT_OP
    187 %token <lex> INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
    188 %token <lex> AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
    189 %token <lex> MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
    190 %token <lex> SUB_ASSIGN
    191 
    192 %token <lex> LEFT_PAREN RIGHT_PAREN LEFT_BRACKET RIGHT_BRACKET LEFT_BRACE RIGHT_BRACE DOT
    193 %token <lex> COMMA COLON EQUAL SEMICOLON BANG DASH TILDE PLUS STAR SLASH PERCENT
    194 %token <lex> LEFT_ANGLE RIGHT_ANGLE VERTICAL_BAR CARET AMPERSAND QUESTION
    195 
    196 %token <lex> INVARIANT PRECISE
    197 %token <lex> HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION
    198 
    199 %token <lex> PACKED RESOURCE SUPERP
    200 
    201 %type <interm> assignment_operator unary_operator
    202 %type <interm.intermTypedNode> variable_identifier primary_expression postfix_expression
    203 %type <interm.intermTypedNode> expression integer_expression assignment_expression
    204 %type <interm.intermTypedNode> unary_expression multiplicative_expression additive_expression
    205 %type <interm.intermTypedNode> relational_expression equality_expression
    206 %type <interm.intermTypedNode> conditional_expression constant_expression
    207 %type <interm.intermTypedNode> logical_or_expression logical_xor_expression logical_and_expression
    208 %type <interm.intermTypedNode> shift_expression and_expression exclusive_or_expression inclusive_or_expression
    209 %type <interm.intermTypedNode> function_call initializer initializer_list condition conditionopt
    210 
    211 %type <interm.intermNode> translation_unit function_definition
    212 %type <interm.intermNode> statement simple_statement
    213 %type <interm.intermNode> statement_list switch_statement_list compound_statement
    214 %type <interm.intermNode> declaration_statement selection_statement expression_statement
    215 %type <interm.intermNode> switch_statement case_label
    216 %type <interm.intermNode> declaration external_declaration
    217 %type <interm.intermNode> for_init_statement compound_statement_no_new_scope
    218 %type <interm.nodePair> selection_rest_statement for_rest_statement
    219 %type <interm.intermNode> iteration_statement jump_statement statement_no_new_scope statement_scoped
    220 %type <interm> single_declaration init_declarator_list
    221 
    222 %type <interm> parameter_declaration parameter_declarator parameter_type_specifier
    223 
    224 %type <interm> array_specifier
    225 %type <interm.type> precise_qualifier invariant_qualifier interpolation_qualifier storage_qualifier precision_qualifier
    226 %type <interm.type> layout_qualifier layout_qualifier_id_list layout_qualifier_id
    227 
    228 %type <interm.type> type_qualifier fully_specified_type type_specifier
    229 %type <interm.type> single_type_qualifier
    230 %type <interm.type> type_specifier_nonarray
    231 %type <interm.type> struct_specifier
    232 %type <interm.typeLine> struct_declarator
    233 %type <interm.typeList> struct_declarator_list struct_declaration struct_declaration_list type_name_list
    234 %type <interm> block_structure
    235 %type <interm.function> function_header function_declarator
    236 %type <interm.function> function_header_with_parameters
    237 %type <interm> function_call_header_with_parameters function_call_header_no_parameters function_call_generic function_prototype
    238 %type <interm> function_call_or_method function_identifier function_call_header
    239 
    240 %type <interm.identifierList> identifier_list
    241 
    242 %start translation_unit
    243 %%
    244 
    245 variable_identifier
    246     : IDENTIFIER {
    247         $$ = parseContext.handleVariable($1.loc, $1.symbol, $1.string);
    248     }
    249     ;
    250 
    251 primary_expression
    252     : variable_identifier {
    253         $$ = $1;
    254     }
    255     | INTCONSTANT {
    256         $$ = parseContext.intermediate.addConstantUnion($1.i, $1.loc, true);
    257     }
    258     | UINTCONSTANT {
    259         parseContext.fullIntegerCheck($1.loc, "unsigned literal");
    260         $$ = parseContext.intermediate.addConstantUnion($1.u, $1.loc, true);
    261     }
    262     | INT64CONSTANT {
    263         parseContext.int64Check($1.loc, "64-bit integer literal");
    264         $$ = parseContext.intermediate.addConstantUnion($1.i64, $1.loc, true);
    265     }
    266     | UINT64CONSTANT {
    267         parseContext.int64Check($1.loc, "64-bit unsigned integer literal");
    268         $$ = parseContext.intermediate.addConstantUnion($1.u64, $1.loc, true);
    269     }
    270     | FLOATCONSTANT {
    271         $$ = parseContext.intermediate.addConstantUnion($1.d, EbtFloat, $1.loc, true);
    272     }
    273     | DOUBLECONSTANT {
    274         parseContext.doubleCheck($1.loc, "double literal");
    275         $$ = parseContext.intermediate.addConstantUnion($1.d, EbtDouble, $1.loc, true);
    276     }
    277     | BOOLCONSTANT {
    278         $$ = parseContext.intermediate.addConstantUnion($1.b, $1.loc, true);
    279     }
    280     | LEFT_PAREN expression RIGHT_PAREN {
    281         $$ = $2;
    282         if ($$->getAsConstantUnion())
    283             $$->getAsConstantUnion()->setExpression();
    284     }
    285     ;
    286 
    287 postfix_expression
    288     : primary_expression {
    289         $$ = $1;
    290     }
    291     | postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET {
    292         $$ = parseContext.handleBracketDereference($2.loc, $1, $3);
    293     }
    294     | function_call {
    295         $$ = $1;
    296     }
    297     | postfix_expression DOT IDENTIFIER {
    298         $$ = parseContext.handleDotDereference($3.loc, $1, *$3.string);
    299     }
    300     | postfix_expression INC_OP {
    301         parseContext.variableCheck($1);
    302         parseContext.lValueErrorCheck($2.loc, "++", $1);
    303         $$ = parseContext.handleUnaryMath($2.loc, "++", EOpPostIncrement, $1);
    304     }
    305     | postfix_expression DEC_OP {
    306         parseContext.variableCheck($1);
    307         parseContext.lValueErrorCheck($2.loc, "--", $1);
    308         $$ = parseContext.handleUnaryMath($2.loc, "--", EOpPostDecrement, $1);
    309     }
    310     ;
    311 
    312 integer_expression
    313     : expression {
    314         parseContext.integerCheck($1, "[]");
    315         $$ = $1;
    316     }
    317     ;
    318 
    319 function_call
    320     : function_call_or_method {
    321         $$ = parseContext.handleFunctionCall($1.loc, $1.function, $1.intermNode);
    322         delete $1.function;
    323     }
    324     ;
    325 
    326 function_call_or_method
    327     : function_call_generic {
    328         $$ = $1;
    329     }
    330     ;
    331 
    332 function_call_generic
    333     : function_call_header_with_parameters RIGHT_PAREN {
    334         $$ = $1;
    335         $$.loc = $2.loc;
    336     }
    337     | function_call_header_no_parameters RIGHT_PAREN {
    338         $$ = $1;
    339         $$.loc = $2.loc;
    340     }
    341     ;
    342 
    343 function_call_header_no_parameters
    344     : function_call_header VOID {
    345         $$ = $1;
    346     }
    347     | function_call_header {
    348         $$ = $1;
    349     }
    350     ;
    351 
    352 function_call_header_with_parameters
    353     : function_call_header assignment_expression {
    354         TParameter param = { 0, new TType };
    355         param.type->shallowCopy($2->getType());
    356         $1.function->addParameter(param);
    357         $$.function = $1.function;
    358         $$.intermNode = $2;
    359     }
    360     | function_call_header_with_parameters COMMA assignment_expression {
    361         TParameter param = { 0, new TType };
    362         param.type->shallowCopy($3->getType());
    363         $1.function->addParameter(param);
    364         $$.function = $1.function;
    365         $$.intermNode = parseContext.intermediate.growAggregate($1.intermNode, $3, $2.loc);
    366     }
    367     ;
    368 
    369 function_call_header
    370     : function_identifier LEFT_PAREN {
    371         $$ = $1;
    372     }
    373     ;
    374 
    375 // Grammar Note:  Constructors look like functions, but are recognized as types.
    376 
    377 function_identifier
    378     : type_specifier {
    379         // Constructor
    380         $$.intermNode = 0;
    381         $$.function = parseContext.handleConstructorCall($1.loc, $1);
    382     }
    383     | postfix_expression {
    384         //
    385         // Should be a method or subroutine call, but we haven't recognized the arguments yet.
    386         //
    387         $$.function = 0;
    388         $$.intermNode = 0;
    389 
    390         TIntermMethod* method = $1->getAsMethodNode();
    391         if (method) {
    392             $$.function = new TFunction(&method->getMethodName(), TType(EbtInt), EOpArrayLength);
    393             $$.intermNode = method->getObject();
    394         } else {
    395             TIntermSymbol* symbol = $1->getAsSymbolNode();
    396             if (symbol) {
    397                 parseContext.reservedErrorCheck(symbol->getLoc(), symbol->getName());
    398                 TFunction *function = new TFunction(&symbol->getName(), TType(EbtVoid));
    399                 $$.function = function;
    400             } else
    401                 parseContext.error($1->getLoc(), "function call, method, or subroutine call expected", "", "");
    402         }
    403 
    404         if ($$.function == 0) {
    405             // error recover
    406             TString empty("");
    407             $$.function = new TFunction(&empty, TType(EbtVoid), EOpNull);
    408         }
    409     }
    410     ;
    411 
    412 unary_expression
    413     : postfix_expression {
    414         parseContext.variableCheck($1);
    415         $$ = $1;
    416         if (TIntermMethod* method = $1->getAsMethodNode())
    417             parseContext.error($1->getLoc(), "incomplete method syntax", method->getMethodName().c_str(), "");
    418     }
    419     | INC_OP unary_expression {
    420         parseContext.lValueErrorCheck($1.loc, "++", $2);
    421         $$ = parseContext.handleUnaryMath($1.loc, "++", EOpPreIncrement, $2);
    422     }
    423     | DEC_OP unary_expression {
    424         parseContext.lValueErrorCheck($1.loc, "--", $2);
    425         $$ = parseContext.handleUnaryMath($1.loc, "--", EOpPreDecrement, $2);
    426     }
    427     | unary_operator unary_expression {
    428         if ($1.op != EOpNull) {
    429             char errorOp[2] = {0, 0};
    430             switch($1.op) {
    431             case EOpNegative:   errorOp[0] = '-'; break;
    432             case EOpLogicalNot: errorOp[0] = '!'; break;
    433             case EOpBitwiseNot: errorOp[0] = '~'; break;
    434             default: break; // some compilers want this
    435             }
    436             $$ = parseContext.handleUnaryMath($1.loc, errorOp, $1.op, $2);
    437         } else {
    438             $$ = $2;
    439             if ($$->getAsConstantUnion())
    440                 $$->getAsConstantUnion()->setExpression();
    441         }
    442     }
    443     ;
    444 // Grammar Note:  No traditional style type casts.
    445 
    446 unary_operator
    447     : PLUS  { $$.loc = $1.loc; $$.op = EOpNull; }
    448     | DASH  { $$.loc = $1.loc; $$.op = EOpNegative; }
    449     | BANG  { $$.loc = $1.loc; $$.op = EOpLogicalNot; }
    450     | TILDE { $$.loc = $1.loc; $$.op = EOpBitwiseNot;
    451               parseContext.fullIntegerCheck($1.loc, "bitwise not"); }
    452     ;
    453 // Grammar Note:  No '*' or '&' unary ops.  Pointers are not supported.
    454 
    455 multiplicative_expression
    456     : unary_expression { $$ = $1; }
    457     | multiplicative_expression STAR unary_expression {
    458         $$ = parseContext.handleBinaryMath($2.loc, "*", EOpMul, $1, $3);
    459         if ($$ == 0)
    460             $$ = $1;
    461     }
    462     | multiplicative_expression SLASH unary_expression {
    463         $$ = parseContext.handleBinaryMath($2.loc, "/", EOpDiv, $1, $3);
    464         if ($$ == 0)
    465             $$ = $1;
    466     }
    467     | multiplicative_expression PERCENT unary_expression {
    468         parseContext.fullIntegerCheck($2.loc, "%");
    469         $$ = parseContext.handleBinaryMath($2.loc, "%", EOpMod, $1, $3);
    470         if ($$ == 0)
    471             $$ = $1;
    472     }
    473     ;
    474 
    475 additive_expression
    476     : multiplicative_expression { $$ = $1; }
    477     | additive_expression PLUS multiplicative_expression {
    478         $$ = parseContext.handleBinaryMath($2.loc, "+", EOpAdd, $1, $3);
    479         if ($$ == 0)
    480             $$ = $1;
    481     }
    482     | additive_expression DASH multiplicative_expression {
    483         $$ = parseContext.handleBinaryMath($2.loc, "-", EOpSub, $1, $3);
    484         if ($$ == 0)
    485             $$ = $1;
    486     }
    487     ;
    488 
    489 shift_expression
    490     : additive_expression { $$ = $1; }
    491     | shift_expression LEFT_OP additive_expression {
    492         parseContext.fullIntegerCheck($2.loc, "bit shift left");
    493         $$ = parseContext.handleBinaryMath($2.loc, "<<", EOpLeftShift, $1, $3);
    494         if ($$ == 0)
    495             $$ = $1;
    496     }
    497     | shift_expression RIGHT_OP additive_expression {
    498         parseContext.fullIntegerCheck($2.loc, "bit shift right");
    499         $$ = parseContext.handleBinaryMath($2.loc, ">>", EOpRightShift, $1, $3);
    500         if ($$ == 0)
    501             $$ = $1;
    502     }
    503     ;
    504 
    505 relational_expression
    506     : shift_expression { $$ = $1; }
    507     | relational_expression LEFT_ANGLE shift_expression {
    508         $$ = parseContext.handleBinaryMath($2.loc, "<", EOpLessThan, $1, $3);
    509         if ($$ == 0)
    510             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    511     }
    512     | relational_expression RIGHT_ANGLE shift_expression  {
    513         $$ = parseContext.handleBinaryMath($2.loc, ">", EOpGreaterThan, $1, $3);
    514         if ($$ == 0)
    515             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    516     }
    517     | relational_expression LE_OP shift_expression  {
    518         $$ = parseContext.handleBinaryMath($2.loc, "<=", EOpLessThanEqual, $1, $3);
    519         if ($$ == 0)
    520             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    521     }
    522     | relational_expression GE_OP shift_expression  {
    523         $$ = parseContext.handleBinaryMath($2.loc, ">=", EOpGreaterThanEqual, $1, $3);
    524         if ($$ == 0)
    525             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    526     }
    527     ;
    528 
    529 equality_expression
    530     : relational_expression { $$ = $1; }
    531     | equality_expression EQ_OP relational_expression  {
    532         parseContext.arrayObjectCheck($2.loc, $1->getType(), "array comparison");
    533         parseContext.opaqueCheck($2.loc, $1->getType(), "==");
    534         parseContext.specializationCheck($2.loc, $1->getType(), "==");
    535         $$ = parseContext.handleBinaryMath($2.loc, "==", EOpEqual, $1, $3);
    536         if ($$ == 0)
    537             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    538     }
    539     | equality_expression NE_OP relational_expression {
    540         parseContext.arrayObjectCheck($2.loc, $1->getType(), "array comparison");
    541         parseContext.opaqueCheck($2.loc, $1->getType(), "!=");
    542         parseContext.specializationCheck($2.loc, $1->getType(), "!=");
    543         $$ = parseContext.handleBinaryMath($2.loc, "!=", EOpNotEqual, $1, $3);
    544         if ($$ == 0)
    545             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    546     }
    547     ;
    548 
    549 and_expression
    550     : equality_expression { $$ = $1; }
    551     | and_expression AMPERSAND equality_expression {
    552         parseContext.fullIntegerCheck($2.loc, "bitwise and");
    553         $$ = parseContext.handleBinaryMath($2.loc, "&", EOpAnd, $1, $3);
    554         if ($$ == 0)
    555             $$ = $1;
    556     }
    557     ;
    558 
    559 exclusive_or_expression
    560     : and_expression { $$ = $1; }
    561     | exclusive_or_expression CARET and_expression {
    562         parseContext.fullIntegerCheck($2.loc, "bitwise exclusive or");
    563         $$ = parseContext.handleBinaryMath($2.loc, "^", EOpExclusiveOr, $1, $3);
    564         if ($$ == 0)
    565             $$ = $1;
    566     }
    567     ;
    568 
    569 inclusive_or_expression
    570     : exclusive_or_expression { $$ = $1; }
    571     | inclusive_or_expression VERTICAL_BAR exclusive_or_expression {
    572         parseContext.fullIntegerCheck($2.loc, "bitwise inclusive or");
    573         $$ = parseContext.handleBinaryMath($2.loc, "|", EOpInclusiveOr, $1, $3);
    574         if ($$ == 0)
    575             $$ = $1;
    576     }
    577     ;
    578 
    579 logical_and_expression
    580     : inclusive_or_expression { $$ = $1; }
    581     | logical_and_expression AND_OP inclusive_or_expression {
    582         $$ = parseContext.handleBinaryMath($2.loc, "&&", EOpLogicalAnd, $1, $3);
    583         if ($$ == 0)
    584             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    585     }
    586     ;
    587 
    588 logical_xor_expression
    589     : logical_and_expression { $$ = $1; }
    590     | logical_xor_expression XOR_OP logical_and_expression  {
    591         $$ = parseContext.handleBinaryMath($2.loc, "^^", EOpLogicalXor, $1, $3);
    592         if ($$ == 0)
    593             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    594     }
    595     ;
    596 
    597 logical_or_expression
    598     : logical_xor_expression { $$ = $1; }
    599     | logical_or_expression OR_OP logical_xor_expression  {
    600         $$ = parseContext.handleBinaryMath($2.loc, "||", EOpLogicalOr, $1, $3);
    601         if ($$ == 0)
    602             $$ = parseContext.intermediate.addConstantUnion(false, $2.loc);
    603     }
    604     ;
    605 
    606 conditional_expression
    607     : logical_or_expression { $$ = $1; }
    608     | logical_or_expression QUESTION {
    609         ++parseContext.controlFlowNestingLevel;
    610     }
    611       expression COLON assignment_expression {
    612         --parseContext.controlFlowNestingLevel;
    613         parseContext.boolCheck($2.loc, $1);
    614         parseContext.rValueErrorCheck($2.loc, "?", $1);
    615         parseContext.rValueErrorCheck($5.loc, ":", $4);
    616         parseContext.rValueErrorCheck($5.loc, ":", $6);
    617         $$ = parseContext.intermediate.addSelection($1, $4, $6, $2.loc);
    618         if ($$ == 0) {
    619             parseContext.binaryOpError($2.loc, ":", $4->getCompleteString(), $6->getCompleteString());
    620             $$ = $6;
    621         }
    622     }
    623     ;
    624 
    625 assignment_expression
    626     : conditional_expression { $$ = $1; }
    627     | unary_expression assignment_operator assignment_expression {
    628         parseContext.arrayObjectCheck($2.loc, $1->getType(), "array assignment");
    629         parseContext.opaqueCheck($2.loc, $1->getType(), "=");
    630         parseContext.specializationCheck($2.loc, $1->getType(), "=");
    631         parseContext.lValueErrorCheck($2.loc, "assign", $1);
    632         parseContext.rValueErrorCheck($2.loc, "assign", $3);
    633         $$ = parseContext.intermediate.addAssign($2.op, $1, $3, $2.loc);
    634         if ($$ == 0) {
    635             parseContext.assignError($2.loc, "assign", $1->getCompleteString(), $3->getCompleteString());
    636             $$ = $1;
    637         }
    638     }
    639     ;
    640 
    641 assignment_operator
    642     : EQUAL {
    643         $$.loc = $1.loc;
    644         $$.op = EOpAssign;
    645     }
    646     | MUL_ASSIGN {
    647         $$.loc = $1.loc;
    648         $$.op = EOpMulAssign;
    649     }
    650     | DIV_ASSIGN {
    651         $$.loc = $1.loc;
    652         $$.op = EOpDivAssign;
    653     }
    654     | MOD_ASSIGN {
    655         parseContext.fullIntegerCheck($1.loc, "%=");
    656         $$.loc = $1.loc;
    657         $$.op = EOpModAssign;
    658     }
    659     | ADD_ASSIGN {
    660         $$.loc = $1.loc;
    661         $$.op = EOpAddAssign;
    662     }
    663     | SUB_ASSIGN {
    664         $$.loc = $1.loc;
    665         $$.op = EOpSubAssign;
    666     }
    667     | LEFT_ASSIGN {
    668         parseContext.fullIntegerCheck($1.loc, "bit-shift left assign");
    669         $$.loc = $1.loc; $$.op = EOpLeftShiftAssign;
    670     }
    671     | RIGHT_ASSIGN {
    672         parseContext.fullIntegerCheck($1.loc, "bit-shift right assign");
    673         $$.loc = $1.loc; $$.op = EOpRightShiftAssign;
    674     }
    675     | AND_ASSIGN {
    676         parseContext.fullIntegerCheck($1.loc, "bitwise-and assign");
    677         $$.loc = $1.loc; $$.op = EOpAndAssign;
    678     }
    679     | XOR_ASSIGN {
    680         parseContext.fullIntegerCheck($1.loc, "bitwise-xor assign");
    681         $$.loc = $1.loc; $$.op = EOpExclusiveOrAssign;
    682     }
    683     | OR_ASSIGN {
    684         parseContext.fullIntegerCheck($1.loc, "bitwise-or assign");
    685         $$.loc = $1.loc; $$.op = EOpInclusiveOrAssign;
    686     }
    687     ;
    688 
    689 expression
    690     : assignment_expression {
    691         $$ = $1;
    692     }
    693     | expression COMMA assignment_expression {
    694         $$ = parseContext.intermediate.addComma($1, $3, $2.loc);
    695         if ($$ == 0) {
    696             parseContext.binaryOpError($2.loc, ",", $1->getCompleteString(), $3->getCompleteString());
    697             $$ = $3;
    698         }
    699     }
    700     ;
    701 
    702 constant_expression
    703     : conditional_expression {
    704         parseContext.constantValueCheck($1, "");
    705         $$ = $1;
    706     }
    707     ;
    708 
    709 declaration
    710     : function_prototype SEMICOLON {
    711         parseContext.handleFunctionDeclarator($1.loc, *$1.function, true /* prototype */);
    712         $$ = 0;
    713         // TODO: 4.0 functionality: subroutines: make the identifier a user type for this signature
    714     }
    715     | init_declarator_list SEMICOLON {
    716         if ($1.intermNode && $1.intermNode->getAsAggregate())
    717             $1.intermNode->getAsAggregate()->setOperator(EOpSequence);
    718         $$ = $1.intermNode;
    719     }
    720     | PRECISION precision_qualifier type_specifier SEMICOLON {
    721         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "precision statement");
    722 
    723         // lazy setting of the previous scope's defaults, has effect only the first time it is called in a particular scope
    724         parseContext.symbolTable.setPreviousDefaultPrecisions(&parseContext.defaultPrecision[0]);
    725         parseContext.setDefaultPrecision($1.loc, $3, $2.qualifier.precision);
    726         $$ = 0;
    727     }
    728     | block_structure SEMICOLON {
    729         parseContext.declareBlock($1.loc, *$1.typeList);
    730         $$ = 0;
    731     }
    732     | block_structure IDENTIFIER SEMICOLON {
    733         parseContext.declareBlock($1.loc, *$1.typeList, $2.string);
    734         $$ = 0;
    735     }
    736     | block_structure IDENTIFIER array_specifier SEMICOLON {
    737         parseContext.declareBlock($1.loc, *$1.typeList, $2.string, $3.arraySizes);
    738         $$ = 0;
    739     }
    740     | type_qualifier SEMICOLON {
    741         parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
    742         parseContext.updateStandaloneQualifierDefaults($1.loc, $1);
    743         $$ = 0;
    744     }
    745     | type_qualifier IDENTIFIER SEMICOLON {
    746         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    747         parseContext.addQualifierToExisting($1.loc, $1.qualifier, *$2.string);
    748         $$ = 0;
    749     }
    750     | type_qualifier IDENTIFIER identifier_list SEMICOLON {
    751         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    752         $3->push_back($2.string);
    753         parseContext.addQualifierToExisting($1.loc, $1.qualifier, *$3);
    754         $$ = 0;
    755     }
    756     ;
    757 
    758 block_structure
    759     : type_qualifier IDENTIFIER LEFT_BRACE { parseContext.nestedBlockCheck($1.loc); } struct_declaration_list RIGHT_BRACE {
    760         --parseContext.structNestingLevel;
    761         parseContext.blockName = $2.string;
    762         parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
    763         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    764         parseContext.currentBlockQualifier = $1.qualifier;
    765         $$.loc = $1.loc;
    766         $$.typeList = $5;
    767     }
    768 
    769 identifier_list
    770     : COMMA IDENTIFIER {
    771         $$ = new TIdentifierList;
    772         $$->push_back($2.string);
    773     }
    774     | identifier_list COMMA IDENTIFIER {
    775         $$ = $1;
    776         $$->push_back($3.string);
    777     }
    778     ;
    779 
    780 function_prototype
    781     : function_declarator RIGHT_PAREN  {
    782         $$.function = $1;
    783         $$.loc = $2.loc;
    784     }
    785     ;
    786 
    787 function_declarator
    788     : function_header {
    789         $$ = $1;
    790     }
    791     | function_header_with_parameters {
    792         $$ = $1;
    793     }
    794     ;
    795 
    796 
    797 function_header_with_parameters
    798     : function_header parameter_declaration {
    799         // Add the parameter
    800         $$ = $1;
    801         if ($2.param.type->getBasicType() != EbtVoid)
    802             $1->addParameter($2.param);
    803         else
    804             delete $2.param.type;
    805     }
    806     | function_header_with_parameters COMMA parameter_declaration {
    807         //
    808         // Only first parameter of one-parameter functions can be void
    809         // The check for named parameters not being void is done in parameter_declarator
    810         //
    811         if ($3.param.type->getBasicType() == EbtVoid) {
    812             //
    813             // This parameter > first is void
    814             //
    815             parseContext.error($2.loc, "cannot be an argument type except for '(void)'", "void", "");
    816             delete $3.param.type;
    817         } else {
    818             // Add the parameter
    819             $$ = $1;
    820             $1->addParameter($3.param);
    821         }
    822     }
    823     ;
    824 
    825 function_header
    826     : fully_specified_type IDENTIFIER LEFT_PAREN {
    827         if ($1.qualifier.storage != EvqGlobal && $1.qualifier.storage != EvqTemporary) {
    828             parseContext.error($2.loc, "no qualifiers allowed for function return",
    829                                GetStorageQualifierString($1.qualifier.storage), "");
    830         }
    831         if ($1.arraySizes)
    832             parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
    833 
    834         // Add the function as a prototype after parsing it (we do not support recursion)
    835         TFunction *function;
    836         TType type($1);
    837         function = new TFunction($2.string, type);
    838         $$ = function;
    839     }
    840     ;
    841 
    842 parameter_declarator
    843     // Type + name
    844     : type_specifier IDENTIFIER {
    845         if ($1.arraySizes) {
    846             parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
    847             parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
    848             parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
    849         }
    850         if ($1.basicType == EbtVoid) {
    851             parseContext.error($2.loc, "illegal use of type 'void'", $2.string->c_str(), "");
    852         }
    853         parseContext.reservedErrorCheck($2.loc, *$2.string);
    854 
    855         TParameter param = {$2.string, new TType($1)};
    856         $$.loc = $2.loc;
    857         $$.param = param;
    858     }
    859     | type_specifier IDENTIFIER array_specifier {
    860         if ($1.arraySizes) {
    861             parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
    862             parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
    863             parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
    864         }
    865         parseContext.arrayDimCheck($2.loc, $1.arraySizes, $3.arraySizes);
    866 
    867         parseContext.arraySizeRequiredCheck($3.loc, *$3.arraySizes);
    868         parseContext.reservedErrorCheck($2.loc, *$2.string);
    869 
    870         $1.arraySizes = $3.arraySizes;
    871 
    872         TParameter param = { $2.string, new TType($1)};
    873         $$.loc = $2.loc;
    874         $$.param = param;
    875     }
    876     ;
    877 
    878 parameter_declaration
    879     //
    880     // With name
    881     //
    882     : type_qualifier parameter_declarator {
    883         $$ = $2;
    884         if ($1.qualifier.precision != EpqNone)
    885             $$.param.type->getQualifier().precision = $1.qualifier.precision;
    886         parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
    887 
    888         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    889         parseContext.parameterTypeCheck($2.loc, $1.qualifier.storage, *$$.param.type);
    890         parseContext.paramCheckFix($1.loc, $1.qualifier, *$$.param.type);
    891 
    892     }
    893     | parameter_declarator {
    894         $$ = $1;
    895 
    896         parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type);
    897         parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type);
    898         parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
    899     }
    900     //
    901     // Without name
    902     //
    903     | type_qualifier parameter_type_specifier {
    904         $$ = $2;
    905         if ($1.qualifier.precision != EpqNone)
    906             $$.param.type->getQualifier().precision = $1.qualifier.precision;
    907         parseContext.precisionQualifierCheck($1.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
    908 
    909         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
    910         parseContext.parameterTypeCheck($2.loc, $1.qualifier.storage, *$$.param.type);
    911         parseContext.paramCheckFix($1.loc, $1.qualifier, *$$.param.type);
    912     }
    913     | parameter_type_specifier {
    914         $$ = $1;
    915 
    916         parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type);
    917         parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type);
    918         parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
    919     }
    920     ;
    921 
    922 parameter_type_specifier
    923     : type_specifier {
    924         TParameter param = { 0, new TType($1) };
    925         $$.param = param;
    926         if ($1.arraySizes)
    927             parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
    928     }
    929     ;
    930 
    931 init_declarator_list
    932     : single_declaration {
    933         $$ = $1;
    934     }
    935     | init_declarator_list COMMA IDENTIFIER {
    936         $$ = $1;
    937         parseContext.declareVariable($3.loc, *$3.string, $1.type);
    938     }
    939     | init_declarator_list COMMA IDENTIFIER array_specifier {
    940         $$ = $1;
    941         parseContext.declareVariable($3.loc, *$3.string, $1.type, $4.arraySizes);
    942     }
    943     | init_declarator_list COMMA IDENTIFIER array_specifier EQUAL initializer {
    944         $$.type = $1.type;
    945         TIntermNode* initNode = parseContext.declareVariable($3.loc, *$3.string, $1.type, $4.arraySizes, $6);
    946         $$.intermNode = parseContext.intermediate.growAggregate($1.intermNode, initNode, $5.loc);
    947     }
    948     | init_declarator_list COMMA IDENTIFIER EQUAL initializer {
    949         $$.type = $1.type;
    950         TIntermNode* initNode = parseContext.declareVariable($3.loc, *$3.string, $1.type, 0, $5);
    951         $$.intermNode = parseContext.intermediate.growAggregate($1.intermNode, initNode, $4.loc);
    952     }
    953     ;
    954 
    955 single_declaration
    956     : fully_specified_type {
    957         $$.type = $1;
    958         $$.intermNode = 0;
    959         parseContext.declareTypeDefaults($$.loc, $$.type);
    960     }
    961     | fully_specified_type IDENTIFIER {
    962         $$.type = $1;
    963         $$.intermNode = 0;
    964         parseContext.declareVariable($2.loc, *$2.string, $1);
    965     }
    966     | fully_specified_type IDENTIFIER array_specifier {
    967         $$.type = $1;
    968         $$.intermNode = 0;
    969         parseContext.declareVariable($2.loc, *$2.string, $1, $3.arraySizes);
    970     }
    971     | fully_specified_type IDENTIFIER array_specifier EQUAL initializer {
    972         $$.type = $1;
    973         TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, $3.arraySizes, $5);
    974         $$.intermNode = parseContext.intermediate.growAggregate(0, initNode, $4.loc);
    975     }
    976     | fully_specified_type IDENTIFIER EQUAL initializer {
    977         $$.type = $1;
    978         TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, 0, $4);
    979         $$.intermNode = parseContext.intermediate.growAggregate(0, initNode, $3.loc);
    980     }
    981 
    982 // Grammar Note:  No 'enum', or 'typedef'.
    983 
    984 fully_specified_type
    985     : type_specifier {
    986         $$ = $1;
    987 
    988         parseContext.globalQualifierTypeCheck($1.loc, $1.qualifier, $$);
    989         if ($1.arraySizes) {
    990             parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
    991             parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
    992         }
    993 
    994         parseContext.precisionQualifierCheck($$.loc, $$.basicType, $$.qualifier);
    995     }
    996     | type_qualifier type_specifier  {
    997         parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
    998         parseContext.globalQualifierTypeCheck($1.loc, $1.qualifier, $2);
    999 
   1000         if ($2.arraySizes) {
   1001             parseContext.profileRequires($2.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
   1002             parseContext.profileRequires($2.loc, EEsProfile, 300, 0, "arrayed type");
   1003         }
   1004 
   1005         if ($2.arraySizes && parseContext.arrayQualifierError($2.loc, $1.qualifier))
   1006             $2.arraySizes = 0;
   1007 
   1008         parseContext.checkNoShaderLayouts($2.loc, $1.shaderQualifiers);
   1009         $2.shaderQualifiers.merge($1.shaderQualifiers);
   1010         parseContext.mergeQualifiers($2.loc, $2.qualifier, $1.qualifier, true);
   1011         parseContext.precisionQualifierCheck($2.loc, $2.basicType, $2.qualifier);
   1012 
   1013         $$ = $2;
   1014 
   1015         if (! $$.qualifier.isInterpolation() &&
   1016             ((parseContext.language == EShLangVertex   && $$.qualifier.storage == EvqVaryingOut) ||
   1017              (parseContext.language == EShLangFragment && $$.qualifier.storage == EvqVaryingIn)))
   1018             $$.qualifier.smooth = true;
   1019     }
   1020     ;
   1021 
   1022 invariant_qualifier
   1023     : INVARIANT {
   1024         parseContext.globalCheck($1.loc, "invariant");
   1025         parseContext.profileRequires($$.loc, ENoProfile, 120, 0, "invariant");
   1026         $$.init($1.loc);
   1027         $$.qualifier.invariant = true;
   1028     }
   1029     ;
   1030 
   1031 interpolation_qualifier
   1032     : SMOOTH {
   1033         parseContext.globalCheck($1.loc, "smooth");
   1034         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "smooth");
   1035         parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "smooth");
   1036         $$.init($1.loc);
   1037         $$.qualifier.smooth = true;
   1038     }
   1039     | FLAT {
   1040         parseContext.globalCheck($1.loc, "flat");
   1041         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "flat");
   1042         parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "flat");
   1043         $$.init($1.loc);
   1044         $$.qualifier.flat = true;
   1045     }
   1046     | NOPERSPECTIVE {
   1047         parseContext.globalCheck($1.loc, "noperspective");
   1048         parseContext.requireProfile($1.loc, ~EEsProfile, "noperspective");
   1049         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "noperspective");
   1050         $$.init($1.loc);
   1051         $$.qualifier.nopersp = true;
   1052     }
   1053     ;
   1054 
   1055 layout_qualifier
   1056     : LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN {
   1057         $$ = $3;
   1058     }
   1059     ;
   1060 
   1061 layout_qualifier_id_list
   1062     : layout_qualifier_id {
   1063         $$ = $1;
   1064     }
   1065     | layout_qualifier_id_list COMMA layout_qualifier_id {
   1066         $$ = $1;
   1067         $$.shaderQualifiers.merge($3.shaderQualifiers);
   1068         parseContext.mergeObjectLayoutQualifiers($$.qualifier, $3.qualifier, false);
   1069     }
   1070 
   1071 layout_qualifier_id
   1072     : IDENTIFIER {
   1073         $$.init($1.loc);
   1074         parseContext.setLayoutQualifier($1.loc, $$, *$1.string);
   1075     }
   1076     | IDENTIFIER EQUAL constant_expression {
   1077         $$.init($1.loc);
   1078         parseContext.setLayoutQualifier($1.loc, $$, *$1.string, $3);
   1079     }
   1080     | SHARED { // because "shared" is both an identifier and a keyword
   1081         $$.init($1.loc);
   1082         TString strShared("shared");
   1083         parseContext.setLayoutQualifier($1.loc, $$, strShared);
   1084     }
   1085     ;
   1086 
   1087 precise_qualifier
   1088     : PRECISE {
   1089         parseContext.profileRequires($$.loc, ECoreProfile | ECompatibilityProfile, 400, E_GL_ARB_gpu_shader5, "precise");
   1090         parseContext.profileRequires($1.loc, EEsProfile, 320, Num_AEP_gpu_shader5, AEP_gpu_shader5, "precise");
   1091         $$.init($1.loc);
   1092         $$.qualifier.noContraction = true;
   1093     }
   1094     ;
   1095 
   1096 type_qualifier
   1097     : single_type_qualifier {
   1098         $$ = $1;
   1099     }
   1100     | type_qualifier single_type_qualifier {
   1101         $$ = $1;
   1102         if ($$.basicType == EbtVoid)
   1103             $$.basicType = $2.basicType;
   1104 
   1105         $$.shaderQualifiers.merge($2.shaderQualifiers);
   1106         parseContext.mergeQualifiers($$.loc, $$.qualifier, $2.qualifier, false);
   1107     }
   1108     ;
   1109 
   1110 single_type_qualifier
   1111     : storage_qualifier {
   1112         $$ = $1;
   1113     }
   1114     | layout_qualifier {
   1115         $$ = $1;
   1116     }
   1117     | precision_qualifier {
   1118         $$ = $1;
   1119     }
   1120     | interpolation_qualifier {
   1121         // allow inheritance of storage qualifier from block declaration
   1122         $$ = $1;
   1123     }
   1124     | invariant_qualifier {
   1125         // allow inheritance of storage qualifier from block declaration
   1126         $$ = $1;
   1127     }
   1128     | precise_qualifier {
   1129         // allow inheritance of storage qualifier from block declaration
   1130         $$ = $1;
   1131     }
   1132     ;
   1133 
   1134 storage_qualifier
   1135     : CONST {
   1136         $$.init($1.loc);
   1137         $$.qualifier.storage = EvqConst;  // will later turn into EvqConstReadOnly, if the initializer is not constant
   1138     }
   1139     | ATTRIBUTE {
   1140         parseContext.requireStage($1.loc, EShLangVertex, "attribute");
   1141         parseContext.checkDeprecated($1.loc, ECoreProfile, 130, "attribute");
   1142         parseContext.checkDeprecated($1.loc, ENoProfile, 130, "attribute");
   1143         parseContext.requireNotRemoved($1.loc, ECoreProfile, 420, "attribute");
   1144         parseContext.requireNotRemoved($1.loc, EEsProfile, 300, "attribute");
   1145 
   1146         parseContext.globalCheck($1.loc, "attribute");
   1147 
   1148         $$.init($1.loc);
   1149         $$.qualifier.storage = EvqVaryingIn;
   1150     }
   1151     | VARYING {
   1152         parseContext.checkDeprecated($1.loc, ENoProfile, 130, "varying");
   1153         parseContext.checkDeprecated($1.loc, ECoreProfile, 130, "varying");
   1154         parseContext.requireNotRemoved($1.loc, ECoreProfile, 420, "varying");
   1155         parseContext.requireNotRemoved($1.loc, EEsProfile, 300, "varying");
   1156 
   1157         parseContext.globalCheck($1.loc, "varying");
   1158 
   1159         $$.init($1.loc);
   1160         if (parseContext.language == EShLangVertex)
   1161             $$.qualifier.storage = EvqVaryingOut;
   1162         else
   1163             $$.qualifier.storage = EvqVaryingIn;
   1164     }
   1165     | INOUT {
   1166         parseContext.globalCheck($1.loc, "inout");
   1167         $$.init($1.loc);
   1168         $$.qualifier.storage = EvqInOut;
   1169     }
   1170     | IN {
   1171         parseContext.globalCheck($1.loc, "in");
   1172         $$.init($1.loc);
   1173         // whether this is a parameter "in" or a pipeline "in" will get sorted out a bit later
   1174         $$.qualifier.storage = EvqIn;
   1175     }
   1176     | OUT {
   1177         parseContext.globalCheck($1.loc, "out");
   1178         $$.init($1.loc);
   1179         // whether this is a parameter "out" or a pipeline "out" will get sorted out a bit later
   1180         $$.qualifier.storage = EvqOut;
   1181     }
   1182     | CENTROID {
   1183         parseContext.profileRequires($1.loc, ENoProfile, 120, 0, "centroid");
   1184         parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "centroid");
   1185         parseContext.globalCheck($1.loc, "centroid");
   1186         $$.init($1.loc);
   1187         $$.qualifier.centroid = true;
   1188     }
   1189     | PATCH {
   1190         parseContext.globalCheck($1.loc, "patch");
   1191         parseContext.requireStage($1.loc, (EShLanguageMask)(EShLangTessControlMask | EShLangTessEvaluationMask), "patch");
   1192         $$.init($1.loc);
   1193         $$.qualifier.patch = true;
   1194     }
   1195     | SAMPLE {
   1196         parseContext.globalCheck($1.loc, "sample");
   1197         $$.init($1.loc);
   1198         $$.qualifier.sample = true;
   1199     }
   1200     | UNIFORM {
   1201         parseContext.globalCheck($1.loc, "uniform");
   1202         $$.init($1.loc);
   1203         $$.qualifier.storage = EvqUniform;
   1204     }
   1205     | BUFFER {
   1206         parseContext.globalCheck($1.loc, "buffer");
   1207         $$.init($1.loc);
   1208         $$.qualifier.storage = EvqBuffer;
   1209     }
   1210     | SHARED {
   1211         parseContext.profileRequires($1.loc, ECoreProfile | ECompatibilityProfile, 430, E_GL_ARB_compute_shader, "shared");
   1212         parseContext.profileRequires($1.loc, EEsProfile, 310, 0, "shared");
   1213         parseContext.requireStage($1.loc, EShLangCompute, "shared");
   1214         $$.init($1.loc);
   1215         $$.qualifier.storage = EvqShared;
   1216     }
   1217     | COHERENT {
   1218         $$.init($1.loc);
   1219         $$.qualifier.coherent = true;
   1220     }
   1221     | VOLATILE {
   1222         $$.init($1.loc);
   1223         $$.qualifier.volatil = true;
   1224     }
   1225     | RESTRICT {
   1226         $$.init($1.loc);
   1227         $$.qualifier.restrict = true;
   1228     }
   1229     | READONLY {
   1230         $$.init($1.loc);
   1231         $$.qualifier.readonly = true;
   1232     }
   1233     | WRITEONLY {
   1234         $$.init($1.loc);
   1235         $$.qualifier.writeonly = true;
   1236     }
   1237     | SUBROUTINE {
   1238         parseContext.spvRemoved($1.loc, "subroutine");
   1239         parseContext.globalCheck($1.loc, "subroutine");
   1240         $$.init($1.loc);
   1241         $$.qualifier.storage = EvqUniform;
   1242     }
   1243     | SUBROUTINE LEFT_PAREN type_name_list RIGHT_PAREN {
   1244         parseContext.spvRemoved($1.loc, "subroutine");
   1245         parseContext.globalCheck($1.loc, "subroutine");
   1246         $$.init($1.loc);
   1247         $$.qualifier.storage = EvqUniform;
   1248         // TODO: 4.0 semantics: subroutines
   1249         // 1) make sure each identifier is a type declared earlier with SUBROUTINE
   1250         // 2) save all of the identifiers for future comparison with the declared function
   1251     }
   1252     ;
   1253 
   1254 type_name_list
   1255     : TYPE_NAME {
   1256         // TODO: 4.0 functionality: subroutine type to list
   1257     }
   1258     | type_name_list COMMA TYPE_NAME {
   1259     }
   1260     ;
   1261 
   1262 type_specifier
   1263     : type_specifier_nonarray {
   1264         $$ = $1;
   1265         $$.qualifier.precision = parseContext.getDefaultPrecision($$);
   1266     }
   1267     | type_specifier_nonarray array_specifier {
   1268         parseContext.arrayDimCheck($2.loc, $2.arraySizes, 0);
   1269         $$ = $1;
   1270         $$.qualifier.precision = parseContext.getDefaultPrecision($$);
   1271         $$.arraySizes = $2.arraySizes;
   1272     }
   1273     ;
   1274 
   1275 array_specifier
   1276     : LEFT_BRACKET RIGHT_BRACKET {
   1277         $$.loc = $1.loc;
   1278         $$.arraySizes = new TArraySizes;
   1279         $$.arraySizes->addInnerSize();
   1280     }
   1281     | LEFT_BRACKET conditional_expression RIGHT_BRACKET {
   1282         $$.loc = $1.loc;
   1283         $$.arraySizes = new TArraySizes;
   1284 
   1285         TArraySize size;
   1286         parseContext.arraySizeCheck($2->getLoc(), $2, size);
   1287         $$.arraySizes->addInnerSize(size);
   1288     }
   1289     | array_specifier LEFT_BRACKET RIGHT_BRACKET {
   1290         $$ = $1;
   1291         $$.arraySizes->addInnerSize();
   1292     }
   1293     | array_specifier LEFT_BRACKET conditional_expression RIGHT_BRACKET {
   1294         $$ = $1;
   1295 
   1296         TArraySize size;
   1297         parseContext.arraySizeCheck($3->getLoc(), $3, size);
   1298         $$.arraySizes->addInnerSize(size);
   1299     }
   1300     ;
   1301 
   1302 type_specifier_nonarray
   1303     : VOID {
   1304         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1305         $$.basicType = EbtVoid;
   1306     }
   1307     | FLOAT {
   1308         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1309         $$.basicType = EbtFloat;
   1310     }
   1311     | DOUBLE {
   1312         parseContext.doubleCheck($1.loc, "double");
   1313         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1314         $$.basicType = EbtDouble;
   1315     }
   1316     | INT {
   1317         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1318         $$.basicType = EbtInt;
   1319     }
   1320     | UINT {
   1321         parseContext.fullIntegerCheck($1.loc, "unsigned integer");
   1322         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1323         $$.basicType = EbtUint;
   1324     }
   1325     | INT64_T {
   1326         parseContext.int64Check($1.loc, "64-bit integer", parseContext.symbolTable.atBuiltInLevel());
   1327         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1328         $$.basicType = EbtInt64;
   1329     }
   1330     | UINT64_T {
   1331         parseContext.int64Check($1.loc, "64-bit unsigned integer", parseContext.symbolTable.atBuiltInLevel());
   1332         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1333         $$.basicType = EbtUint64;
   1334     }
   1335     | BOOL {
   1336         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1337         $$.basicType = EbtBool;
   1338     }
   1339     | VEC2 {
   1340         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1341         $$.basicType = EbtFloat;
   1342         $$.setVector(2);
   1343     }
   1344     | VEC3 {
   1345         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1346         $$.basicType = EbtFloat;
   1347         $$.setVector(3);
   1348     }
   1349     | VEC4 {
   1350         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1351         $$.basicType = EbtFloat;
   1352         $$.setVector(4);
   1353     }
   1354     | DVEC2 {
   1355         parseContext.doubleCheck($1.loc, "double vector");
   1356         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1357         $$.basicType = EbtDouble;
   1358         $$.setVector(2);
   1359     }
   1360     | DVEC3 {
   1361         parseContext.doubleCheck($1.loc, "double vector");
   1362         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1363         $$.basicType = EbtDouble;
   1364         $$.setVector(3);
   1365     }
   1366     | DVEC4 {
   1367         parseContext.doubleCheck($1.loc, "double vector");
   1368         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1369         $$.basicType = EbtDouble;
   1370         $$.setVector(4);
   1371     }
   1372     | BVEC2 {
   1373         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1374         $$.basicType = EbtBool;
   1375         $$.setVector(2);
   1376     }
   1377     | BVEC3 {
   1378         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1379         $$.basicType = EbtBool;
   1380         $$.setVector(3);
   1381     }
   1382     | BVEC4 {
   1383         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1384         $$.basicType = EbtBool;
   1385         $$.setVector(4);
   1386     }
   1387     | IVEC2 {
   1388         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1389         $$.basicType = EbtInt;
   1390         $$.setVector(2);
   1391     }
   1392     | IVEC3 {
   1393         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1394         $$.basicType = EbtInt;
   1395         $$.setVector(3);
   1396     }
   1397     | IVEC4 {
   1398         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1399         $$.basicType = EbtInt;
   1400         $$.setVector(4);
   1401     }
   1402     | I64VEC2 {
   1403         parseContext.int64Check($1.loc, "64-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
   1404         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1405         $$.basicType = EbtInt64;
   1406         $$.setVector(2);
   1407     }
   1408     | I64VEC3 {
   1409         parseContext.int64Check($1.loc, "64-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
   1410         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1411         $$.basicType = EbtInt64;
   1412         $$.setVector(3);
   1413     }
   1414     | I64VEC4 {
   1415         parseContext.int64Check($1.loc, "64-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
   1416         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1417         $$.basicType = EbtInt64;
   1418         $$.setVector(4);
   1419     }
   1420     | UVEC2 {
   1421         parseContext.fullIntegerCheck($1.loc, "unsigned integer vector");
   1422         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1423         $$.basicType = EbtUint;
   1424         $$.setVector(2);
   1425     }
   1426     | UVEC3 {
   1427         parseContext.fullIntegerCheck($1.loc, "unsigned integer vector");
   1428         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1429         $$.basicType = EbtUint;
   1430         $$.setVector(3);
   1431     }
   1432     | UVEC4 {
   1433         parseContext.fullIntegerCheck($1.loc, "unsigned integer vector");
   1434         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1435         $$.basicType = EbtUint;
   1436         $$.setVector(4);
   1437     }
   1438     | U64VEC2 {
   1439         parseContext.int64Check($1.loc, "64-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
   1440         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1441         $$.basicType = EbtUint64;
   1442         $$.setVector(2);
   1443     }
   1444     | U64VEC3 {
   1445         parseContext.int64Check($1.loc, "64-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
   1446         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1447         $$.basicType = EbtUint64;
   1448         $$.setVector(3);
   1449     }
   1450     | U64VEC4 {
   1451         parseContext.int64Check($1.loc, "64-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
   1452         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1453         $$.basicType = EbtUint64;
   1454         $$.setVector(4);
   1455     }
   1456     | MAT2 {
   1457         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1458         $$.basicType = EbtFloat;
   1459         $$.setMatrix(2, 2);
   1460     }
   1461     | MAT3 {
   1462         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1463         $$.basicType = EbtFloat;
   1464         $$.setMatrix(3, 3);
   1465     }
   1466     | MAT4 {
   1467         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1468         $$.basicType = EbtFloat;
   1469         $$.setMatrix(4, 4);
   1470     }
   1471     | MAT2X2 {
   1472         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1473         $$.basicType = EbtFloat;
   1474         $$.setMatrix(2, 2);
   1475     }
   1476     | MAT2X3 {
   1477         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1478         $$.basicType = EbtFloat;
   1479         $$.setMatrix(2, 3);
   1480     }
   1481     | MAT2X4 {
   1482         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1483         $$.basicType = EbtFloat;
   1484         $$.setMatrix(2, 4);
   1485     }
   1486     | MAT3X2 {
   1487         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1488         $$.basicType = EbtFloat;
   1489         $$.setMatrix(3, 2);
   1490     }
   1491     | MAT3X3 {
   1492         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1493         $$.basicType = EbtFloat;
   1494         $$.setMatrix(3, 3);
   1495     }
   1496     | MAT3X4 {
   1497         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1498         $$.basicType = EbtFloat;
   1499         $$.setMatrix(3, 4);
   1500     }
   1501     | MAT4X2 {
   1502         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1503         $$.basicType = EbtFloat;
   1504         $$.setMatrix(4, 2);
   1505     }
   1506     | MAT4X3 {
   1507         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1508         $$.basicType = EbtFloat;
   1509         $$.setMatrix(4, 3);
   1510     }
   1511     | MAT4X4 {
   1512         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1513         $$.basicType = EbtFloat;
   1514         $$.setMatrix(4, 4);
   1515     }
   1516     | DMAT2 {
   1517         parseContext.doubleCheck($1.loc, "double matrix");
   1518         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1519         $$.basicType = EbtDouble;
   1520         $$.setMatrix(2, 2);
   1521     }
   1522     | DMAT3 {
   1523         parseContext.doubleCheck($1.loc, "double matrix");
   1524         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1525         $$.basicType = EbtDouble;
   1526         $$.setMatrix(3, 3);
   1527     }
   1528     | DMAT4 {
   1529         parseContext.doubleCheck($1.loc, "double matrix");
   1530         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1531         $$.basicType = EbtDouble;
   1532         $$.setMatrix(4, 4);
   1533     }
   1534     | DMAT2X2 {
   1535         parseContext.doubleCheck($1.loc, "double matrix");
   1536         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1537         $$.basicType = EbtDouble;
   1538         $$.setMatrix(2, 2);
   1539     }
   1540     | DMAT2X3 {
   1541         parseContext.doubleCheck($1.loc, "double matrix");
   1542         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1543         $$.basicType = EbtDouble;
   1544         $$.setMatrix(2, 3);
   1545     }
   1546     | DMAT2X4 {
   1547         parseContext.doubleCheck($1.loc, "double matrix");
   1548         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1549         $$.basicType = EbtDouble;
   1550         $$.setMatrix(2, 4);
   1551     }
   1552     | DMAT3X2 {
   1553         parseContext.doubleCheck($1.loc, "double matrix");
   1554         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1555         $$.basicType = EbtDouble;
   1556         $$.setMatrix(3, 2);
   1557     }
   1558     | DMAT3X3 {
   1559         parseContext.doubleCheck($1.loc, "double matrix");
   1560         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1561         $$.basicType = EbtDouble;
   1562         $$.setMatrix(3, 3);
   1563     }
   1564     | DMAT3X4 {
   1565         parseContext.doubleCheck($1.loc, "double matrix");
   1566         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1567         $$.basicType = EbtDouble;
   1568         $$.setMatrix(3, 4);
   1569     }
   1570     | DMAT4X2 {
   1571         parseContext.doubleCheck($1.loc, "double matrix");
   1572         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1573         $$.basicType = EbtDouble;
   1574         $$.setMatrix(4, 2);
   1575     }
   1576     | DMAT4X3 {
   1577         parseContext.doubleCheck($1.loc, "double matrix");
   1578         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1579         $$.basicType = EbtDouble;
   1580         $$.setMatrix(4, 3);
   1581     }
   1582     | DMAT4X4 {
   1583         parseContext.doubleCheck($1.loc, "double matrix");
   1584         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1585         $$.basicType = EbtDouble;
   1586         $$.setMatrix(4, 4);
   1587     }
   1588     | ATOMIC_UINT {
   1589         parseContext.vulkanRemoved($1.loc, "atomic counter types");
   1590         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1591         $$.basicType = EbtAtomicUint;
   1592     }
   1593     | SAMPLER1D {
   1594         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1595         $$.basicType = EbtSampler;
   1596         $$.sampler.set(EbtFloat, Esd1D);
   1597     }
   1598     | SAMPLER2D {
   1599         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1600         $$.basicType = EbtSampler;
   1601         $$.sampler.set(EbtFloat, Esd2D);
   1602     }
   1603     | SAMPLER3D {
   1604         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1605         $$.basicType = EbtSampler;
   1606         $$.sampler.set(EbtFloat, Esd3D);
   1607     }
   1608     | SAMPLERCUBE {
   1609         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1610         $$.basicType = EbtSampler;
   1611         $$.sampler.set(EbtFloat, EsdCube);
   1612     }
   1613     | SAMPLER1DSHADOW {
   1614         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1615         $$.basicType = EbtSampler;
   1616         $$.sampler.set(EbtFloat, Esd1D, false, true);
   1617     }
   1618     | SAMPLER2DSHADOW {
   1619         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1620         $$.basicType = EbtSampler;
   1621         $$.sampler.set(EbtFloat, Esd2D, false, true);
   1622     }
   1623     | SAMPLERCUBESHADOW {
   1624         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1625         $$.basicType = EbtSampler;
   1626         $$.sampler.set(EbtFloat, EsdCube, false, true);
   1627     }
   1628     | SAMPLER1DARRAY {
   1629         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1630         $$.basicType = EbtSampler;
   1631         $$.sampler.set(EbtFloat, Esd1D, true);
   1632     }
   1633     | SAMPLER2DARRAY {
   1634         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1635         $$.basicType = EbtSampler;
   1636         $$.sampler.set(EbtFloat, Esd2D, true);
   1637     }
   1638     | SAMPLER1DARRAYSHADOW {
   1639         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1640         $$.basicType = EbtSampler;
   1641         $$.sampler.set(EbtFloat, Esd1D, true, true);
   1642     }
   1643     | SAMPLER2DARRAYSHADOW {
   1644         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1645         $$.basicType = EbtSampler;
   1646         $$.sampler.set(EbtFloat, Esd2D, true, true);
   1647     }
   1648     | SAMPLERCUBEARRAY {
   1649         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1650         $$.basicType = EbtSampler;
   1651         $$.sampler.set(EbtFloat, EsdCube, true);
   1652     }
   1653     | SAMPLERCUBEARRAYSHADOW {
   1654         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1655         $$.basicType = EbtSampler;
   1656         $$.sampler.set(EbtFloat, EsdCube, true, true);
   1657     }
   1658     | ISAMPLER1D {
   1659         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1660         $$.basicType = EbtSampler;
   1661         $$.sampler.set(EbtInt, Esd1D);
   1662     }
   1663     | ISAMPLER2D {
   1664         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1665         $$.basicType = EbtSampler;
   1666         $$.sampler.set(EbtInt, Esd2D);
   1667     }
   1668     | ISAMPLER3D {
   1669         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1670         $$.basicType = EbtSampler;
   1671         $$.sampler.set(EbtInt, Esd3D);
   1672     }
   1673     | ISAMPLERCUBE {
   1674         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1675         $$.basicType = EbtSampler;
   1676         $$.sampler.set(EbtInt, EsdCube);
   1677     }
   1678     | ISAMPLER1DARRAY {
   1679         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1680         $$.basicType = EbtSampler;
   1681         $$.sampler.set(EbtInt, Esd1D, true);
   1682     }
   1683     | ISAMPLER2DARRAY {
   1684         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1685         $$.basicType = EbtSampler;
   1686         $$.sampler.set(EbtInt, Esd2D, true);
   1687     }
   1688     | ISAMPLERCUBEARRAY {
   1689         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1690         $$.basicType = EbtSampler;
   1691         $$.sampler.set(EbtInt, EsdCube, true);
   1692     }
   1693     | USAMPLER1D {
   1694         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1695         $$.basicType = EbtSampler;
   1696         $$.sampler.set(EbtUint, Esd1D);
   1697     }
   1698     | USAMPLER2D {
   1699         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1700         $$.basicType = EbtSampler;
   1701         $$.sampler.set(EbtUint, Esd2D);
   1702     }
   1703     | USAMPLER3D {
   1704         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1705         $$.basicType = EbtSampler;
   1706         $$.sampler.set(EbtUint, Esd3D);
   1707     }
   1708     | USAMPLERCUBE {
   1709         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1710         $$.basicType = EbtSampler;
   1711         $$.sampler.set(EbtUint, EsdCube);
   1712     }
   1713     | USAMPLER1DARRAY {
   1714         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1715         $$.basicType = EbtSampler;
   1716         $$.sampler.set(EbtUint, Esd1D, true);
   1717     }
   1718     | USAMPLER2DARRAY {
   1719         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1720         $$.basicType = EbtSampler;
   1721         $$.sampler.set(EbtUint, Esd2D, true);
   1722     }
   1723     | USAMPLERCUBEARRAY {
   1724         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1725         $$.basicType = EbtSampler;
   1726         $$.sampler.set(EbtUint, EsdCube, true);
   1727     }
   1728     | SAMPLER2DRECT {
   1729         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1730         $$.basicType = EbtSampler;
   1731         $$.sampler.set(EbtFloat, EsdRect);
   1732     }
   1733     | SAMPLER2DRECTSHADOW {
   1734         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1735         $$.basicType = EbtSampler;
   1736         $$.sampler.set(EbtFloat, EsdRect, false, true);
   1737     }
   1738     | ISAMPLER2DRECT {
   1739         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1740         $$.basicType = EbtSampler;
   1741         $$.sampler.set(EbtInt, EsdRect);
   1742     }
   1743     | USAMPLER2DRECT {
   1744         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1745         $$.basicType = EbtSampler;
   1746         $$.sampler.set(EbtUint, EsdRect);
   1747     }
   1748     | SAMPLERBUFFER {
   1749         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1750         $$.basicType = EbtSampler;
   1751         $$.sampler.set(EbtFloat, EsdBuffer);
   1752     }
   1753     | ISAMPLERBUFFER {
   1754         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1755         $$.basicType = EbtSampler;
   1756         $$.sampler.set(EbtInt, EsdBuffer);
   1757     }
   1758     | USAMPLERBUFFER {
   1759         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1760         $$.basicType = EbtSampler;
   1761         $$.sampler.set(EbtUint, EsdBuffer);
   1762     }
   1763     | SAMPLER2DMS {
   1764         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1765         $$.basicType = EbtSampler;
   1766         $$.sampler.set(EbtFloat, Esd2D, false, false, true);
   1767     }
   1768     | ISAMPLER2DMS {
   1769         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1770         $$.basicType = EbtSampler;
   1771         $$.sampler.set(EbtInt, Esd2D, false, false, true);
   1772     }
   1773     | USAMPLER2DMS {
   1774         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1775         $$.basicType = EbtSampler;
   1776         $$.sampler.set(EbtUint, Esd2D, false, false, true);
   1777     }
   1778     | SAMPLER2DMSARRAY {
   1779         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1780         $$.basicType = EbtSampler;
   1781         $$.sampler.set(EbtFloat, Esd2D, true, false, true);
   1782     }
   1783     | ISAMPLER2DMSARRAY {
   1784         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1785         $$.basicType = EbtSampler;
   1786         $$.sampler.set(EbtInt, Esd2D, true, false, true);
   1787     }
   1788     | USAMPLER2DMSARRAY {
   1789         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1790         $$.basicType = EbtSampler;
   1791         $$.sampler.set(EbtUint, Esd2D, true, false, true);
   1792     }
   1793     | SAMPLER {
   1794         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1795         $$.basicType = EbtSampler;
   1796         $$.sampler.setPureSampler(false);
   1797     }
   1798     | SAMPLERSHADOW {
   1799         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1800         $$.basicType = EbtSampler;
   1801         $$.sampler.setPureSampler(true);
   1802     }
   1803     | TEXTURE1D {
   1804         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1805         $$.basicType = EbtSampler;
   1806         $$.sampler.setTexture(EbtFloat, Esd1D);
   1807     }
   1808     | TEXTURE2D {
   1809         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1810         $$.basicType = EbtSampler;
   1811         $$.sampler.setTexture(EbtFloat, Esd2D);
   1812     }
   1813     | TEXTURE3D {
   1814         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1815         $$.basicType = EbtSampler;
   1816         $$.sampler.setTexture(EbtFloat, Esd3D);
   1817     }
   1818     | TEXTURECUBE {
   1819         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1820         $$.basicType = EbtSampler;
   1821         $$.sampler.setTexture(EbtFloat, EsdCube);
   1822     }
   1823     | TEXTURE1DARRAY {
   1824         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1825         $$.basicType = EbtSampler;
   1826         $$.sampler.setTexture(EbtFloat, Esd1D, true);
   1827     }
   1828     | TEXTURE2DARRAY {
   1829         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1830         $$.basicType = EbtSampler;
   1831         $$.sampler.setTexture(EbtFloat, Esd2D, true);
   1832     }
   1833     | TEXTURECUBEARRAY {
   1834         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1835         $$.basicType = EbtSampler;
   1836         $$.sampler.setTexture(EbtFloat, EsdCube, true);
   1837     }
   1838     | ITEXTURE1D {
   1839         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1840         $$.basicType = EbtSampler;
   1841         $$.sampler.setTexture(EbtInt, Esd1D);
   1842     }
   1843     | ITEXTURE2D {
   1844         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1845         $$.basicType = EbtSampler;
   1846         $$.sampler.setTexture(EbtInt, Esd2D);
   1847     }
   1848     | ITEXTURE3D {
   1849         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1850         $$.basicType = EbtSampler;
   1851         $$.sampler.setTexture(EbtInt, Esd3D);
   1852     }
   1853     | ITEXTURECUBE {
   1854         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1855         $$.basicType = EbtSampler;
   1856         $$.sampler.setTexture(EbtInt, EsdCube);
   1857     }
   1858     | ITEXTURE1DARRAY {
   1859         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1860         $$.basicType = EbtSampler;
   1861         $$.sampler.setTexture(EbtInt, Esd1D, true);
   1862     }
   1863     | ITEXTURE2DARRAY {
   1864         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1865         $$.basicType = EbtSampler;
   1866         $$.sampler.setTexture(EbtInt, Esd2D, true);
   1867     }
   1868     | ITEXTURECUBEARRAY {
   1869         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1870         $$.basicType = EbtSampler;
   1871         $$.sampler.setTexture(EbtInt, EsdCube, true);
   1872     }
   1873     | UTEXTURE1D {
   1874         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1875         $$.basicType = EbtSampler;
   1876         $$.sampler.setTexture(EbtUint, Esd1D);
   1877     }
   1878     | UTEXTURE2D {
   1879         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1880         $$.basicType = EbtSampler;
   1881         $$.sampler.setTexture(EbtUint, Esd2D);
   1882     }
   1883     | UTEXTURE3D {
   1884         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1885         $$.basicType = EbtSampler;
   1886         $$.sampler.setTexture(EbtUint, Esd3D);
   1887     }
   1888     | UTEXTURECUBE {
   1889         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1890         $$.basicType = EbtSampler;
   1891         $$.sampler.setTexture(EbtUint, EsdCube);
   1892     }
   1893     | UTEXTURE1DARRAY {
   1894         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1895         $$.basicType = EbtSampler;
   1896         $$.sampler.setTexture(EbtUint, Esd1D, true);
   1897     }
   1898     | UTEXTURE2DARRAY {
   1899         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1900         $$.basicType = EbtSampler;
   1901         $$.sampler.setTexture(EbtUint, Esd2D, true);
   1902     }
   1903     | UTEXTURECUBEARRAY {
   1904         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1905         $$.basicType = EbtSampler;
   1906         $$.sampler.setTexture(EbtUint, EsdCube, true);
   1907     }
   1908     | TEXTURE2DRECT {
   1909         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1910         $$.basicType = EbtSampler;
   1911         $$.sampler.setTexture(EbtFloat, EsdRect);
   1912     }
   1913     | ITEXTURE2DRECT {
   1914         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1915         $$.basicType = EbtSampler;
   1916         $$.sampler.setTexture(EbtInt, EsdRect);
   1917     }
   1918     | UTEXTURE2DRECT {
   1919         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1920         $$.basicType = EbtSampler;
   1921         $$.sampler.setTexture(EbtUint, EsdRect);
   1922     }
   1923     | TEXTUREBUFFER {
   1924         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1925         $$.basicType = EbtSampler;
   1926         $$.sampler.setTexture(EbtFloat, EsdBuffer);
   1927     }
   1928     | ITEXTUREBUFFER {
   1929         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1930         $$.basicType = EbtSampler;
   1931         $$.sampler.setTexture(EbtInt, EsdBuffer);
   1932     }
   1933     | UTEXTUREBUFFER {
   1934         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1935         $$.basicType = EbtSampler;
   1936         $$.sampler.setTexture(EbtUint, EsdBuffer);
   1937     }
   1938     | TEXTURE2DMS {
   1939         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1940         $$.basicType = EbtSampler;
   1941         $$.sampler.setTexture(EbtFloat, Esd2D, false, false, true);
   1942     }
   1943     | ITEXTURE2DMS {
   1944         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1945         $$.basicType = EbtSampler;
   1946         $$.sampler.setTexture(EbtInt, Esd2D, false, false, true);
   1947     }
   1948     | UTEXTURE2DMS {
   1949         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1950         $$.basicType = EbtSampler;
   1951         $$.sampler.setTexture(EbtUint, Esd2D, false, false, true);
   1952     }
   1953     | TEXTURE2DMSARRAY {
   1954         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1955         $$.basicType = EbtSampler;
   1956         $$.sampler.setTexture(EbtFloat, Esd2D, true, false, true);
   1957     }
   1958     | ITEXTURE2DMSARRAY {
   1959         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1960         $$.basicType = EbtSampler;
   1961         $$.sampler.setTexture(EbtInt, Esd2D, true, false, true);
   1962     }
   1963     | UTEXTURE2DMSARRAY {
   1964         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1965         $$.basicType = EbtSampler;
   1966         $$.sampler.setTexture(EbtUint, Esd2D, true, false, true);
   1967     }
   1968     | IMAGE1D {
   1969         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1970         $$.basicType = EbtSampler;
   1971         $$.sampler.setImage(EbtFloat, Esd1D);
   1972     }
   1973     | IIMAGE1D {
   1974         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1975         $$.basicType = EbtSampler;
   1976         $$.sampler.setImage(EbtInt, Esd1D);
   1977     }
   1978     | UIMAGE1D {
   1979         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1980         $$.basicType = EbtSampler;
   1981         $$.sampler.setImage(EbtUint, Esd1D);
   1982     }
   1983     | IMAGE2D {
   1984         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1985         $$.basicType = EbtSampler;
   1986         $$.sampler.setImage(EbtFloat, Esd2D);
   1987     }
   1988     | IIMAGE2D {
   1989         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1990         $$.basicType = EbtSampler;
   1991         $$.sampler.setImage(EbtInt, Esd2D);
   1992     }
   1993     | UIMAGE2D {
   1994         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   1995         $$.basicType = EbtSampler;
   1996         $$.sampler.setImage(EbtUint, Esd2D);
   1997     }
   1998     | IMAGE3D {
   1999         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2000         $$.basicType = EbtSampler;
   2001         $$.sampler.setImage(EbtFloat, Esd3D);
   2002     }
   2003     | IIMAGE3D {
   2004         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2005         $$.basicType = EbtSampler;
   2006         $$.sampler.setImage(EbtInt, Esd3D);
   2007     }
   2008     | UIMAGE3D {
   2009         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2010         $$.basicType = EbtSampler;
   2011         $$.sampler.setImage(EbtUint, Esd3D);
   2012     }
   2013     | IMAGE2DRECT {
   2014         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2015         $$.basicType = EbtSampler;
   2016         $$.sampler.setImage(EbtFloat, EsdRect);
   2017     }
   2018     | IIMAGE2DRECT {
   2019         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2020         $$.basicType = EbtSampler;
   2021         $$.sampler.setImage(EbtInt, EsdRect);
   2022     }
   2023     | UIMAGE2DRECT {
   2024         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2025         $$.basicType = EbtSampler;
   2026         $$.sampler.setImage(EbtUint, EsdRect);
   2027     }
   2028     | IMAGECUBE {
   2029         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2030         $$.basicType = EbtSampler;
   2031         $$.sampler.setImage(EbtFloat, EsdCube);
   2032     }
   2033     | IIMAGECUBE {
   2034         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2035         $$.basicType = EbtSampler;
   2036         $$.sampler.setImage(EbtInt, EsdCube);
   2037     }
   2038     | UIMAGECUBE {
   2039         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2040         $$.basicType = EbtSampler;
   2041         $$.sampler.setImage(EbtUint, EsdCube);
   2042     }
   2043     | IMAGEBUFFER {
   2044         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2045         $$.basicType = EbtSampler;
   2046         $$.sampler.setImage(EbtFloat, EsdBuffer);
   2047     }
   2048     | IIMAGEBUFFER {
   2049         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2050         $$.basicType = EbtSampler;
   2051         $$.sampler.setImage(EbtInt, EsdBuffer);
   2052     }
   2053     | UIMAGEBUFFER {
   2054         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2055         $$.basicType = EbtSampler;
   2056         $$.sampler.setImage(EbtUint, EsdBuffer);
   2057     }
   2058     | IMAGE1DARRAY {
   2059         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2060         $$.basicType = EbtSampler;
   2061         $$.sampler.setImage(EbtFloat, Esd1D, true);
   2062     }
   2063     | IIMAGE1DARRAY {
   2064         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2065         $$.basicType = EbtSampler;
   2066         $$.sampler.setImage(EbtInt, Esd1D, true);
   2067     }
   2068     | UIMAGE1DARRAY {
   2069         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2070         $$.basicType = EbtSampler;
   2071         $$.sampler.setImage(EbtUint, Esd1D, true);
   2072     }
   2073     | IMAGE2DARRAY {
   2074         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2075         $$.basicType = EbtSampler;
   2076         $$.sampler.setImage(EbtFloat, Esd2D, true);
   2077     }
   2078     | IIMAGE2DARRAY {
   2079         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2080         $$.basicType = EbtSampler;
   2081         $$.sampler.setImage(EbtInt, Esd2D, true);
   2082     }
   2083     | UIMAGE2DARRAY {
   2084         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2085         $$.basicType = EbtSampler;
   2086         $$.sampler.setImage(EbtUint, Esd2D, true);
   2087     }
   2088     | IMAGECUBEARRAY {
   2089         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2090         $$.basicType = EbtSampler;
   2091         $$.sampler.setImage(EbtFloat, EsdCube, true);
   2092     }
   2093     | IIMAGECUBEARRAY {
   2094         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2095         $$.basicType = EbtSampler;
   2096         $$.sampler.setImage(EbtInt, EsdCube, true);
   2097     }
   2098     | UIMAGECUBEARRAY {
   2099         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2100         $$.basicType = EbtSampler;
   2101         $$.sampler.setImage(EbtUint, EsdCube, true);
   2102     }
   2103     | IMAGE2DMS {
   2104         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2105         $$.basicType = EbtSampler;
   2106         $$.sampler.setImage(EbtFloat, Esd2D, false, false, true);
   2107     }
   2108     | IIMAGE2DMS {
   2109         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2110         $$.basicType = EbtSampler;
   2111         $$.sampler.setImage(EbtInt, Esd2D, false, false, true);
   2112     }
   2113     | UIMAGE2DMS {
   2114         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2115         $$.basicType = EbtSampler;
   2116         $$.sampler.setImage(EbtUint, Esd2D, false, false, true);
   2117     }
   2118     | IMAGE2DMSARRAY {
   2119         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2120         $$.basicType = EbtSampler;
   2121         $$.sampler.setImage(EbtFloat, Esd2D, true, false, true);
   2122     }
   2123     | IIMAGE2DMSARRAY {
   2124         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2125         $$.basicType = EbtSampler;
   2126         $$.sampler.setImage(EbtInt, Esd2D, true, false, true);
   2127     }
   2128     | UIMAGE2DMSARRAY {
   2129         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2130         $$.basicType = EbtSampler;
   2131         $$.sampler.setImage(EbtUint, Esd2D, true, false, true);
   2132     }
   2133     | SAMPLEREXTERNALOES {  // GL_OES_EGL_image_external
   2134         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2135         $$.basicType = EbtSampler;
   2136         $$.sampler.set(EbtFloat, Esd2D);
   2137         $$.sampler.external = true;
   2138     }
   2139     | SUBPASSINPUT {
   2140         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2141         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2142         $$.basicType = EbtSampler;
   2143         $$.sampler.setSubpass(EbtFloat);
   2144     }
   2145     | SUBPASSINPUTMS {
   2146         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2147         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2148         $$.basicType = EbtSampler;
   2149         $$.sampler.setSubpass(EbtFloat, true);
   2150     }
   2151     | ISUBPASSINPUT {
   2152         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2153         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2154         $$.basicType = EbtSampler;
   2155         $$.sampler.setSubpass(EbtInt);
   2156     }
   2157     | ISUBPASSINPUTMS {
   2158         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2159         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2160         $$.basicType = EbtSampler;
   2161         $$.sampler.setSubpass(EbtInt, true);
   2162     }
   2163     | USUBPASSINPUT {
   2164         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2165         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2166         $$.basicType = EbtSampler;
   2167         $$.sampler.setSubpass(EbtUint);
   2168     }
   2169     | USUBPASSINPUTMS {
   2170         parseContext.requireStage($1.loc, EShLangFragment, "subpass input");
   2171         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2172         $$.basicType = EbtSampler;
   2173         $$.sampler.setSubpass(EbtUint, true);
   2174     }
   2175     | struct_specifier {
   2176         $$ = $1;
   2177         $$.qualifier.storage = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
   2178         parseContext.structTypeCheck($$.loc, $$);
   2179     }
   2180     | TYPE_NAME {
   2181         //
   2182         // This is for user defined type names.  The lexical phase looked up the
   2183         // type.
   2184         //
   2185         if (const TVariable* variable = ($1.symbol)->getAsVariable()) {
   2186             const TType& structure = variable->getType();
   2187             $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2188             $$.basicType = EbtStruct;
   2189             $$.userDef = &structure;
   2190         } else
   2191             parseContext.error($1.loc, "expected type name", $1.string->c_str(), "");
   2192     }
   2193     ;
   2194 
   2195 precision_qualifier
   2196     : HIGH_PRECISION {
   2197         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "highp precision qualifier");
   2198         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2199         if (parseContext.profile == EEsProfile)
   2200             $$.qualifier.precision = EpqHigh;
   2201     }
   2202     | MEDIUM_PRECISION {
   2203         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "mediump precision qualifier");
   2204         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2205         if (parseContext.profile == EEsProfile)
   2206             $$.qualifier.precision = EpqMedium;
   2207     }
   2208     | LOW_PRECISION {
   2209         parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "lowp precision qualifier");
   2210         $$.init($1.loc, parseContext.symbolTable.atGlobalLevel());
   2211         if (parseContext.profile == EEsProfile)
   2212             $$.qualifier.precision = EpqLow;
   2213     }
   2214     ;
   2215 
   2216 struct_specifier
   2217     : STRUCT IDENTIFIER LEFT_BRACE { parseContext.nestedStructCheck($1.loc); } struct_declaration_list RIGHT_BRACE {
   2218         TType* structure = new TType($5, *$2.string);
   2219         parseContext.structArrayCheck($2.loc, *structure);
   2220         TVariable* userTypeDef = new TVariable($2.string, *structure, true);
   2221         if (! parseContext.symbolTable.insert(*userTypeDef))
   2222             parseContext.error($2.loc, "redefinition", $2.string->c_str(), "struct");
   2223         $$.init($1.loc);
   2224         $$.basicType = EbtStruct;
   2225         $$.userDef = structure;
   2226         --parseContext.structNestingLevel;
   2227     }
   2228     | STRUCT LEFT_BRACE { parseContext.nestedStructCheck($1.loc); } struct_declaration_list RIGHT_BRACE {
   2229         TType* structure = new TType($4, TString(""));
   2230         $$.init($1.loc);
   2231         $$.basicType = EbtStruct;
   2232         $$.userDef = structure;
   2233         --parseContext.structNestingLevel;
   2234     }
   2235     ;
   2236 
   2237 struct_declaration_list
   2238     : struct_declaration {
   2239         $$ = $1;
   2240     }
   2241     | struct_declaration_list struct_declaration {
   2242         $$ = $1;
   2243         for (unsigned int i = 0; i < $2->size(); ++i) {
   2244             for (unsigned int j = 0; j < $$->size(); ++j) {
   2245                 if ((*$$)[j].type->getFieldName() == (*$2)[i].type->getFieldName())
   2246                     parseContext.error((*$2)[i].loc, "duplicate member name:", "", (*$2)[i].type->getFieldName().c_str());
   2247             }
   2248             $$->push_back((*$2)[i]);
   2249         }
   2250     }
   2251     ;
   2252 
   2253 struct_declaration
   2254     : type_specifier struct_declarator_list SEMICOLON {
   2255         if ($1.arraySizes) {
   2256             parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
   2257             parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
   2258             if (parseContext.profile == EEsProfile)
   2259                 parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
   2260         }
   2261 
   2262         $$ = $2;
   2263 
   2264         parseContext.voidErrorCheck($1.loc, (*$2)[0].type->getFieldName(), $1.basicType);
   2265         parseContext.precisionQualifierCheck($1.loc, $1.basicType, $1.qualifier);
   2266 
   2267         for (unsigned int i = 0; i < $$->size(); ++i) {
   2268             parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $1.arraySizes);
   2269             (*$$)[i].type->mergeType($1);
   2270         }
   2271     }
   2272     | type_qualifier type_specifier struct_declarator_list SEMICOLON {
   2273         parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
   2274         if ($2.arraySizes) {
   2275             parseContext.profileRequires($2.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
   2276             parseContext.profileRequires($2.loc, EEsProfile, 300, 0, "arrayed type");
   2277             if (parseContext.profile == EEsProfile)
   2278                 parseContext.arraySizeRequiredCheck($2.loc, *$2.arraySizes);
   2279         }
   2280 
   2281         $$ = $3;
   2282 
   2283         parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
   2284         parseContext.voidErrorCheck($2.loc, (*$3)[0].type->getFieldName(), $2.basicType);
   2285         parseContext.mergeQualifiers($2.loc, $2.qualifier, $1.qualifier, true);
   2286         parseContext.precisionQualifierCheck($2.loc, $2.basicType, $2.qualifier);
   2287 
   2288         for (unsigned int i = 0; i < $$->size(); ++i) {
   2289             parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $2.arraySizes);
   2290             (*$$)[i].type->mergeType($2);
   2291         }
   2292     }
   2293     ;
   2294 
   2295 struct_declarator_list
   2296     : struct_declarator {
   2297         $$ = new TTypeList;
   2298         $$->push_back($1);
   2299     }
   2300     | struct_declarator_list COMMA struct_declarator {
   2301         $$->push_back($3);
   2302     }
   2303     ;
   2304 
   2305 struct_declarator
   2306     : IDENTIFIER {
   2307         $$.type = new TType(EbtVoid);
   2308         $$.loc = $1.loc;
   2309         $$.type->setFieldName(*$1.string);
   2310     }
   2311     | IDENTIFIER array_specifier {
   2312         parseContext.arrayDimCheck($1.loc, $2.arraySizes, 0);
   2313 
   2314         $$.type = new TType(EbtVoid);
   2315         $$.loc = $1.loc;
   2316         $$.type->setFieldName(*$1.string);
   2317         $$.type->newArraySizes(*$2.arraySizes);
   2318     }
   2319     ;
   2320 
   2321 initializer
   2322     : assignment_expression {
   2323         $$ = $1;
   2324     }
   2325     | LEFT_BRACE initializer_list RIGHT_BRACE {
   2326         const char* initFeature = "{ } style initializers";
   2327         parseContext.requireProfile($1.loc, ~EEsProfile, initFeature);
   2328         parseContext.profileRequires($1.loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature);
   2329         $$ = $2;
   2330     }
   2331     | LEFT_BRACE initializer_list COMMA RIGHT_BRACE {
   2332         const char* initFeature = "{ } style initializers";
   2333         parseContext.requireProfile($1.loc, ~EEsProfile, initFeature);
   2334         parseContext.profileRequires($1.loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature);
   2335         $$ = $2;
   2336     }
   2337     ;
   2338 
   2339 initializer_list
   2340     : initializer {
   2341         $$ = parseContext.intermediate.growAggregate(0, $1, $1->getLoc());
   2342     }
   2343     | initializer_list COMMA initializer {
   2344         $$ = parseContext.intermediate.growAggregate($1, $3);
   2345     }
   2346     ;
   2347 
   2348 declaration_statement
   2349     : declaration { $$ = $1; }
   2350     ;
   2351 
   2352 statement
   2353     : compound_statement  { $$ = $1; }
   2354     | simple_statement    { $$ = $1; }
   2355     ;
   2356 
   2357 // Grammar Note:  labeled statements for switch statements only; 'goto' is not supported.
   2358 
   2359 simple_statement
   2360     : declaration_statement { $$ = $1; }
   2361     | expression_statement  { $$ = $1; }
   2362     | selection_statement   { $$ = $1; }
   2363     | switch_statement      { $$ = $1; }
   2364     | case_label            { $$ = $1; }
   2365     | iteration_statement   { $$ = $1; }
   2366     | jump_statement        { $$ = $1; }
   2367     ;
   2368 
   2369 compound_statement
   2370     : LEFT_BRACE RIGHT_BRACE { $$ = 0; }
   2371     | LEFT_BRACE {
   2372         parseContext.symbolTable.push();
   2373         ++parseContext.statementNestingLevel;
   2374     }
   2375       statement_list {
   2376         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2377         --parseContext.statementNestingLevel;
   2378     }
   2379       RIGHT_BRACE {
   2380         if ($3 && $3->getAsAggregate())
   2381             $3->getAsAggregate()->setOperator(EOpSequence);
   2382         $$ = $3;
   2383     }
   2384     ;
   2385 
   2386 statement_no_new_scope
   2387     : compound_statement_no_new_scope { $$ = $1; }
   2388     | simple_statement                { $$ = $1; }
   2389     ;
   2390 
   2391 statement_scoped
   2392     : {
   2393         ++parseContext.controlFlowNestingLevel;
   2394     }
   2395       compound_statement  {
   2396         --parseContext.controlFlowNestingLevel;
   2397         $$ = $2;
   2398     }
   2399     | {
   2400         parseContext.symbolTable.push();
   2401         ++parseContext.statementNestingLevel;
   2402         ++parseContext.controlFlowNestingLevel;
   2403     }
   2404       simple_statement {
   2405         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2406         --parseContext.statementNestingLevel;
   2407         --parseContext.controlFlowNestingLevel;
   2408         $$ = $2;
   2409     }
   2410 
   2411 compound_statement_no_new_scope
   2412     // Statement that doesn't create a new scope, for selection_statement, iteration_statement
   2413     : LEFT_BRACE RIGHT_BRACE {
   2414         $$ = 0;
   2415     }
   2416     | LEFT_BRACE statement_list RIGHT_BRACE {
   2417         if ($2 && $2->getAsAggregate())
   2418             $2->getAsAggregate()->setOperator(EOpSequence);
   2419         $$ = $2;
   2420     }
   2421     ;
   2422 
   2423 statement_list
   2424     : statement {
   2425         $$ = parseContext.intermediate.makeAggregate($1);
   2426         if ($1 && $1->getAsBranchNode() && ($1->getAsBranchNode()->getFlowOp() == EOpCase ||
   2427                                             $1->getAsBranchNode()->getFlowOp() == EOpDefault)) {
   2428             parseContext.wrapupSwitchSubsequence(0, $1);
   2429             $$ = 0;  // start a fresh subsequence for what's after this case
   2430         }
   2431     }
   2432     | statement_list statement {
   2433         if ($2 && $2->getAsBranchNode() && ($2->getAsBranchNode()->getFlowOp() == EOpCase ||
   2434                                             $2->getAsBranchNode()->getFlowOp() == EOpDefault)) {
   2435             parseContext.wrapupSwitchSubsequence($1 ? $1->getAsAggregate() : 0, $2);
   2436             $$ = 0;  // start a fresh subsequence for what's after this case
   2437         } else
   2438             $$ = parseContext.intermediate.growAggregate($1, $2);
   2439     }
   2440     ;
   2441 
   2442 expression_statement
   2443     : SEMICOLON  { $$ = 0; }
   2444     | expression SEMICOLON  { $$ = static_cast<TIntermNode*>($1); }
   2445     ;
   2446 
   2447 selection_statement
   2448     : IF LEFT_PAREN expression RIGHT_PAREN selection_rest_statement {
   2449         parseContext.boolCheck($1.loc, $3);
   2450         $$ = parseContext.intermediate.addSelection($3, $5, $1.loc);
   2451     }
   2452     ;
   2453 
   2454 selection_rest_statement
   2455     : statement_scoped ELSE statement_scoped {
   2456         $$.node1 = $1;
   2457         $$.node2 = $3;
   2458     }
   2459     | statement_scoped {
   2460         $$.node1 = $1;
   2461         $$.node2 = 0;
   2462     }
   2463     ;
   2464 
   2465 condition
   2466     // In 1996 c++ draft, conditions can include single declarations
   2467     : expression {
   2468         $$ = $1;
   2469         parseContext.boolCheck($1->getLoc(), $1);
   2470     }
   2471     | fully_specified_type IDENTIFIER EQUAL initializer {
   2472         parseContext.boolCheck($2.loc, $1);
   2473 
   2474         TType type($1);
   2475         TIntermNode* initNode = parseContext.declareVariable($2.loc, *$2.string, $1, 0, $4);
   2476         if (initNode)
   2477             $$ = initNode->getAsTyped();
   2478         else
   2479             $$ = 0;
   2480     }
   2481     ;
   2482 
   2483 switch_statement
   2484     : SWITCH LEFT_PAREN expression RIGHT_PAREN {
   2485         // start new switch sequence on the switch stack
   2486         ++parseContext.controlFlowNestingLevel;
   2487         ++parseContext.statementNestingLevel;
   2488         parseContext.switchSequenceStack.push_back(new TIntermSequence);
   2489         parseContext.switchLevel.push_back(parseContext.statementNestingLevel);
   2490         parseContext.symbolTable.push();
   2491     }
   2492     LEFT_BRACE switch_statement_list RIGHT_BRACE {
   2493         $$ = parseContext.addSwitch($1.loc, $3, $7 ? $7->getAsAggregate() : 0);
   2494         delete parseContext.switchSequenceStack.back();
   2495         parseContext.switchSequenceStack.pop_back();
   2496         parseContext.switchLevel.pop_back();
   2497         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2498         --parseContext.statementNestingLevel;
   2499         --parseContext.controlFlowNestingLevel;
   2500     }
   2501     ;
   2502 
   2503 switch_statement_list
   2504     : /* nothing */ {
   2505         $$ = 0;
   2506     }
   2507     | statement_list {
   2508         $$ = $1;
   2509     }
   2510     ;
   2511 
   2512 case_label
   2513     : CASE expression COLON {
   2514         $$ = 0;
   2515         if (parseContext.switchLevel.size() == 0)
   2516             parseContext.error($1.loc, "cannot appear outside switch statement", "case", "");
   2517         else if (parseContext.switchLevel.back() != parseContext.statementNestingLevel)
   2518             parseContext.error($1.loc, "cannot be nested inside control flow", "case", "");
   2519         else {
   2520             parseContext.constantValueCheck($2, "case");
   2521             parseContext.integerCheck($2, "case");
   2522             $$ = parseContext.intermediate.addBranch(EOpCase, $2, $1.loc);
   2523         }
   2524     }
   2525     | DEFAULT COLON {
   2526         $$ = 0;
   2527         if (parseContext.switchLevel.size() == 0)
   2528             parseContext.error($1.loc, "cannot appear outside switch statement", "default", "");
   2529         else if (parseContext.switchLevel.back() != parseContext.statementNestingLevel)
   2530             parseContext.error($1.loc, "cannot be nested inside control flow", "default", "");
   2531         else
   2532             $$ = parseContext.intermediate.addBranch(EOpDefault, $1.loc);
   2533     }
   2534     ;
   2535 
   2536 iteration_statement
   2537     : WHILE LEFT_PAREN {
   2538         if (! parseContext.limits.whileLoops)
   2539             parseContext.error($1.loc, "while loops not available", "limitation", "");
   2540         parseContext.symbolTable.push();
   2541         ++parseContext.loopNestingLevel;
   2542         ++parseContext.statementNestingLevel;
   2543         ++parseContext.controlFlowNestingLevel;
   2544     }
   2545       condition RIGHT_PAREN statement_no_new_scope {
   2546         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2547         $$ = parseContext.intermediate.addLoop($6, $4, 0, true, $1.loc);
   2548         --parseContext.loopNestingLevel;
   2549         --parseContext.statementNestingLevel;
   2550         --parseContext.controlFlowNestingLevel;
   2551     }
   2552     | DO {
   2553         ++parseContext.loopNestingLevel;
   2554         ++parseContext.statementNestingLevel;
   2555         ++parseContext.controlFlowNestingLevel;
   2556     }
   2557       statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON {
   2558         if (! parseContext.limits.whileLoops)
   2559             parseContext.error($1.loc, "do-while loops not available", "limitation", "");
   2560 
   2561         parseContext.boolCheck($8.loc, $6);
   2562 
   2563         $$ = parseContext.intermediate.addLoop($3, $6, 0, false, $4.loc);
   2564         --parseContext.loopNestingLevel;
   2565         --parseContext.statementNestingLevel;
   2566         --parseContext.controlFlowNestingLevel;
   2567     }
   2568     | FOR LEFT_PAREN {
   2569         parseContext.symbolTable.push();
   2570         ++parseContext.loopNestingLevel;
   2571         ++parseContext.statementNestingLevel;
   2572         ++parseContext.controlFlowNestingLevel;
   2573     }
   2574       for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope {
   2575         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2576         $$ = parseContext.intermediate.makeAggregate($4, $2.loc);
   2577         TIntermLoop* forLoop = parseContext.intermediate.addLoop($7, reinterpret_cast<TIntermTyped*>($5.node1), reinterpret_cast<TIntermTyped*>($5.node2), true, $1.loc);
   2578         if (! parseContext.limits.nonInductiveForLoops)
   2579             parseContext.inductiveLoopCheck($1.loc, $4, forLoop);
   2580         $$ = parseContext.intermediate.growAggregate($$, forLoop, $1.loc);
   2581         $$->getAsAggregate()->setOperator(EOpSequence);
   2582         --parseContext.loopNestingLevel;
   2583         --parseContext.statementNestingLevel;
   2584         --parseContext.controlFlowNestingLevel;
   2585     }
   2586     ;
   2587 
   2588 for_init_statement
   2589     : expression_statement {
   2590         $$ = $1;
   2591     }
   2592     | declaration_statement {
   2593         $$ = $1;
   2594     }
   2595     ;
   2596 
   2597 conditionopt
   2598     : condition {
   2599         $$ = $1;
   2600     }
   2601     | /* May be null */ {
   2602         $$ = 0;
   2603     }
   2604     ;
   2605 
   2606 for_rest_statement
   2607     : conditionopt SEMICOLON {
   2608         $$.node1 = $1;
   2609         $$.node2 = 0;
   2610     }
   2611     | conditionopt SEMICOLON expression  {
   2612         $$.node1 = $1;
   2613         $$.node2 = $3;
   2614     }
   2615     ;
   2616 
   2617 jump_statement
   2618     : CONTINUE SEMICOLON {
   2619         if (parseContext.loopNestingLevel <= 0)
   2620             parseContext.error($1.loc, "continue statement only allowed in loops", "", "");
   2621         $$ = parseContext.intermediate.addBranch(EOpContinue, $1.loc);
   2622     }
   2623     | BREAK SEMICOLON {
   2624         if (parseContext.loopNestingLevel + parseContext.switchSequenceStack.size() <= 0)
   2625             parseContext.error($1.loc, "break statement only allowed in switch and loops", "", "");
   2626         $$ = parseContext.intermediate.addBranch(EOpBreak, $1.loc);
   2627     }
   2628     | RETURN SEMICOLON {
   2629         $$ = parseContext.intermediate.addBranch(EOpReturn, $1.loc);
   2630         if (parseContext.currentFunctionType->getBasicType() != EbtVoid)
   2631             parseContext.error($1.loc, "non-void function must return a value", "return", "");
   2632         if (parseContext.inMain)
   2633             parseContext.postMainReturn = true;
   2634     }
   2635     | RETURN expression SEMICOLON {
   2636         $$ = parseContext.handleReturnValue($1.loc, $2);
   2637     }
   2638     | DISCARD SEMICOLON {
   2639         parseContext.requireStage($1.loc, EShLangFragment, "discard");
   2640         $$ = parseContext.intermediate.addBranch(EOpKill, $1.loc);
   2641     }
   2642     ;
   2643 
   2644 // Grammar Note:  No 'goto'.  Gotos are not supported.
   2645 
   2646 translation_unit
   2647     : external_declaration {
   2648         $$ = $1;
   2649         parseContext.intermediate.setTreeRoot($$);
   2650     }
   2651     | translation_unit external_declaration {
   2652         $$ = parseContext.intermediate.growAggregate($1, $2);
   2653         parseContext.intermediate.setTreeRoot($$);
   2654     }
   2655     ;
   2656 
   2657 external_declaration
   2658     : function_definition {
   2659         $$ = $1;
   2660     }
   2661     | declaration {
   2662         $$ = $1;
   2663     }
   2664     ;
   2665 
   2666 function_definition
   2667     : function_prototype {
   2668         $1.function = parseContext.handleFunctionDeclarator($1.loc, *$1.function, false /* not prototype */);
   2669         $1.intermNode = parseContext.handleFunctionDefinition($1.loc, *$1.function);
   2670     }
   2671     compound_statement_no_new_scope {
   2672         //   May be best done as post process phase on intermediate code
   2673         if (parseContext.currentFunctionType->getBasicType() != EbtVoid && ! parseContext.functionReturnsValue)
   2674             parseContext.error($1.loc, "function does not return a value:", "", $1.function->getName().c_str());
   2675         parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
   2676         $$ = parseContext.intermediate.growAggregate($1.intermNode, $3);
   2677         parseContext.intermediate.setAggregateOperator($$, EOpFunction, $1.function->getType(), $1.loc);
   2678         $$->getAsAggregate()->setName($1.function->getMangledName().c_str());
   2679 
   2680         // store the pragma information for debug and optimize and other vendor specific
   2681         // information. This information can be queried from the parse tree
   2682         $$->getAsAggregate()->setOptimize(parseContext.contextPragma.optimize);
   2683         $$->getAsAggregate()->setDebug(parseContext.contextPragma.debug);
   2684         $$->getAsAggregate()->addToPragmaTable(parseContext.contextPragma.pragmaTable);
   2685     }
   2686     ;
   2687 
   2688 %%
   2689