3 * Copyright © 2008, 2009 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
30 #include "glsl_parser_extras.h"
31 #include "glsl_types.h"
33 #define YYLEX_PARAM state->scanner
41 %lex-param {void *scanner}
42 %parse-param {struct _mesa_glsl_parse_state *state}
43 %name-prefix "_mesa_glsl_"
51 struct ast_type_qualifier q;
55 struct ast_node *node;
56 struct ast_type_specifier *type_specifier;
57 struct ast_fully_specified_type *fully_specified_type;
58 struct ast_function *function;
59 struct ast_parameter_declarator *parameter_declarator;
60 struct ast_function_definition *function_definition;
61 struct ast_compound_statement *compound_statement;
62 struct ast_expression *expression;
63 struct ast_declarator_list *declarator_list;
64 struct ast_struct_specifier *struct_specifier;
65 struct ast_declaration *declaration;
68 struct ast_node *cond;
69 struct ast_expression *rest;
73 %token ATTRIBUTE CONST BOOL FLOAT INT UINT
74 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
75 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
76 %token MAT2 MAT3 MAT4 CENTROID IN OUT INOUT UNIFORM VARYING
77 %token NOPERSPECTIVE FLAT SMOOTH
78 %token MAT2X2 MAT2X3 MAT2X4
79 %token MAT3X2 MAT3X3 MAT3X4
80 %token MAT4X2 MAT4X3 MAT4X4
81 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
82 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
83 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
84 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
85 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
86 %token STRUCT VOID WHILE
87 %token <identifier> IDENTIFIER TYPE_NAME
88 %token <real> FLOATCONSTANT
89 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
90 %token <identifier> FIELD_SELECTION
91 %token LEFT_OP RIGHT_OP
92 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
93 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
94 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
97 %token HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION
99 %token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
101 /* Reserved words that are not actually used in the grammar.
103 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED GOTO
104 %token INLINE NOINLINE VOLATILE PUBLIC STATIC EXTERN EXTERNAL
105 %token LONG SHORT DOUBLE HALF FIXED UNSIGNED INPUT OUPTUT
106 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
107 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
108 %token SIZEOF CAST NAMESPACE USING LOWP MEDIUMP HIGHP
110 %type <identifier> variable_identifier
111 %type <node> statement
112 %type <node> statement_list
113 %type <node> simple_statement
114 %type <node> statement_matched
115 %type <node> statement_unmatched
116 %type <n> precision_qualifier
117 %type <type_qualifier> type_qualifier
118 %type <type_qualifier> storage_qualifier
119 %type <type_qualifier> interpolation_qualifier
120 %type <type_specifier> type_specifier
121 %type <type_specifier> type_specifier_no_prec
122 %type <type_specifier> type_specifier_nonarray
123 %type <n> basic_type_specifier_nonarray
124 %type <fully_specified_type> fully_specified_type
125 %type <function> function_prototype
126 %type <function> function_header
127 %type <function> function_header_with_parameters
128 %type <function> function_declarator
129 %type <parameter_declarator> parameter_declarator
130 %type <parameter_declarator> parameter_declaration
131 %type <type_qualifier> parameter_qualifier
132 %type <type_qualifier> parameter_type_qualifier
133 %type <type_specifier> parameter_type_specifier
134 %type <function_definition> function_definition
135 %type <compound_statement> compound_statement_no_new_scope
136 %type <compound_statement> compound_statement
137 %type <node> statement_no_new_scope
138 %type <node> expression_statement
139 %type <expression> expression
140 %type <expression> primary_expression
141 %type <expression> assignment_expression
142 %type <expression> conditional_expression
143 %type <expression> logical_or_expression
144 %type <expression> logical_xor_expression
145 %type <expression> logical_and_expression
146 %type <expression> inclusive_or_expression
147 %type <expression> exclusive_or_expression
148 %type <expression> and_expression
149 %type <expression> equality_expression
150 %type <expression> relational_expression
151 %type <expression> shift_expression
152 %type <expression> additive_expression
153 %type <expression> multiplicative_expression
154 %type <expression> unary_expression
155 %type <expression> constant_expression
156 %type <expression> integer_expression
157 %type <expression> postfix_expression
158 %type <expression> function_call_header_with_parameters
159 %type <expression> function_call_header_no_parameters
160 %type <expression> function_call_header
161 %type <expression> function_call_generic
162 %type <expression> function_call_or_method
163 %type <expression> function_call
164 %type <n> assignment_operator
165 %type <n> unary_operator
166 %type <expression> function_identifier
167 %type <node> external_declaration
168 %type <declarator_list> init_declarator_list
169 %type <declarator_list> single_declaration
170 %type <expression> initializer
171 %type <node> declaration
172 %type <node> declaration_statement
173 %type <node> jump_statement
174 %type <struct_specifier> struct_specifier
175 %type <node> struct_declaration_list
176 %type <declarator_list> struct_declaration
177 %type <declaration> struct_declarator
178 %type <declaration> struct_declarator_list
179 %type <node> selection_statement_matched
180 %type <node> selection_statement_unmatched
181 %type <node> iteration_statement
182 %type <node> condition
183 %type <node> conditionopt
184 %type <node> for_init_statement
185 %type <for_rest_statement> for_rest_statement
191 _mesa_glsl_initialize_types(state);
193 external_declaration_list
196 state->language_version = 110;
197 _mesa_glsl_initialize_types(state);
199 external_declaration_list
203 VERSION INTCONSTANT EOL
209 /* FINISHME: Check against implementation support versions. */
210 state->language_version = $2;
213 _mesa_glsl_error(& @2, state, "Shading language version"
214 "%u is not supported\n", $2);
220 external_declaration_list:
223 insert_at_tail(& state->translation_unit,
224 (struct simple_node *) $1);
226 | external_declaration_list external_declaration
228 insert_at_tail(& state->translation_unit,
229 (struct simple_node *) $2);
240 $$ = new ast_expression(ast_identifier, NULL, NULL, NULL);
241 $$->primary_expression.identifier = $1;
245 $$ = new ast_expression(ast_int_constant, NULL, NULL, NULL);
246 $$->primary_expression.int_constant = $1;
250 $$ = new ast_expression(ast_uint_constant, NULL, NULL, NULL);
251 $$->primary_expression.uint_constant = $1;
255 $$ = new ast_expression(ast_float_constant, NULL, NULL, NULL);
256 $$->primary_expression.float_constant = $1;
260 $$ = new ast_expression(ast_bool_constant, NULL, NULL, NULL);
261 $$->primary_expression.bool_constant = $1;
271 | postfix_expression '[' integer_expression ']'
273 $$ = new ast_expression(ast_array_index, $1, $3, NULL);
279 | postfix_expression '.' IDENTIFIER
281 $$ = new ast_expression(ast_field_selection, $1, NULL, NULL);
282 $$->primary_expression.identifier = $3;
284 | postfix_expression INC_OP
286 $$ = new ast_expression(ast_post_inc, $1, NULL, NULL);
288 | postfix_expression DEC_OP
290 $$ = new ast_expression(ast_post_dec, $1, NULL, NULL);
299 function_call_or_method
302 function_call_or_method:
303 function_call_generic
304 | postfix_expression '.' function_call_generic
306 $$ = new ast_expression(ast_field_selection, $1, $3, NULL);
310 function_call_generic:
311 function_call_header_with_parameters ')'
312 | function_call_header_no_parameters ')'
315 function_call_header_no_parameters:
316 function_call_header VOID
317 | function_call_header
320 function_call_header_with_parameters:
321 function_call_header assignment_expression
324 $$->subexpressions[1] = $2;
326 | function_call_header_with_parameters ',' assignment_expression
329 insert_at_tail((struct simple_node *) $$->subexpressions[1],
330 (struct simple_node *) $3);
334 // Grammar Note: Constructors look like functions, but lexical
335 // analysis recognized most of them as keywords. They are now
336 // recognized through "type_specifier".
337 function_call_header:
338 function_identifier '('
344 $$ = new ast_function_expression($1);
348 ast_expression *callee = new ast_expression($1);
349 $$ = new ast_function_expression(callee);
353 ast_expression *callee = new ast_expression($1);
354 $$ = new ast_function_expression(callee);
358 // Grammar Note: No traditional style type casts.
361 | INC_OP unary_expression
363 $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
365 | DEC_OP unary_expression
367 $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
369 | unary_operator unary_expression
371 $$ = new ast_expression($1, $2, NULL, NULL);
375 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
377 '+' { $$ = ast_plus; }
378 | '-' { $$ = ast_neg; }
379 | '!' { $$ = ast_logic_not; }
380 | '~' { $$ = ast_bit_not; }
383 multiplicative_expression:
385 | multiplicative_expression '*' unary_expression
387 $$ = new ast_expression_bin(ast_mul, $1, $3);
389 | multiplicative_expression '/' unary_expression
391 $$ = new ast_expression_bin(ast_div, $1, $3);
393 | multiplicative_expression '%' unary_expression
395 $$ = new ast_expression_bin(ast_mod, $1, $3);
400 multiplicative_expression
401 | additive_expression '+' multiplicative_expression
403 $$ = new ast_expression_bin(ast_add, $1, $3);
405 | additive_expression '-' multiplicative_expression
407 $$ = new ast_expression_bin(ast_sub, $1, $3);
413 | shift_expression LEFT_OP additive_expression
415 $$ = new ast_expression_bin(ast_lshift, $1, $3);
417 | shift_expression RIGHT_OP additive_expression
419 $$ = new ast_expression_bin(ast_rshift, $1, $3);
423 relational_expression:
425 | relational_expression '<' shift_expression
427 $$ = new ast_expression_bin(ast_less, $1, $3);
429 | relational_expression '>' shift_expression
431 $$ = new ast_expression_bin(ast_greater, $1, $3);
433 | relational_expression LE_OP shift_expression
435 $$ = new ast_expression_bin(ast_lequal, $1, $3);
437 | relational_expression GE_OP shift_expression
439 $$ = new ast_expression_bin(ast_gequal, $1, $3);
444 relational_expression
445 | equality_expression EQ_OP relational_expression
447 $$ = new ast_expression_bin(ast_equal, $1, $3);
449 | equality_expression NE_OP relational_expression
451 $$ = new ast_expression_bin(ast_nequal, $1, $3);
457 | and_expression '&' equality_expression
459 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
463 exclusive_or_expression:
465 | exclusive_or_expression '^' and_expression
467 $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
471 inclusive_or_expression:
472 exclusive_or_expression
473 | inclusive_or_expression '|' exclusive_or_expression
475 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
479 logical_and_expression:
480 inclusive_or_expression
481 | logical_and_expression AND_OP inclusive_or_expression
483 $$ = new ast_expression_bin(ast_logic_and, $1, $3);
487 logical_xor_expression:
488 logical_and_expression
489 | logical_xor_expression XOR_OP logical_and_expression
491 $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
495 logical_or_expression:
496 logical_xor_expression
497 | logical_or_expression OR_OP logical_xor_expression
499 $$ = new ast_expression_bin(ast_logic_or, $1, $3);
503 conditional_expression:
504 logical_or_expression
505 | logical_or_expression '?' expression ':' assignment_expression
507 $$ = new ast_expression(ast_conditional, $1, $3, $5);
511 assignment_expression:
512 conditional_expression
513 | unary_expression assignment_operator assignment_expression
515 $$ = new ast_expression($2, $1, $3, NULL);
520 '=' { $$ = ast_assign; }
521 | MUL_ASSIGN { $$ = ast_mul_assign; }
522 | DIV_ASSIGN { $$ = ast_div_assign; }
523 | MOD_ASSIGN { $$ = ast_mod_assign; }
524 | ADD_ASSIGN { $$ = ast_add_assign; }
525 | SUB_ASSIGN { $$ = ast_sub_assign; }
526 | LEFT_ASSIGN { $$ = ast_ls_assign; }
527 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
528 | AND_ASSIGN { $$ = ast_and_assign; }
529 | XOR_ASSIGN { $$ = ast_xor_assign; }
530 | OR_ASSIGN { $$ = ast_or_assign; }
534 assignment_expression
538 | expression ',' assignment_expression
540 if ($1->oper != ast_sequence) {
541 $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
542 insert_at_tail(& $$->expressions, $1);
547 insert_at_tail(& $$->expressions, $3);
552 conditional_expression
556 function_prototype ';'
560 | init_declarator_list ';'
564 | PRECISION precision_qualifier type_specifier_no_prec ';'
566 $$ = NULL; /* FINISHME */
571 function_declarator ')'
576 | function_header_with_parameters
579 function_header_with_parameters:
580 function_header parameter_declaration
583 insert_at_tail(& $$->parameters,
584 (struct simple_node *) $2);
586 | function_header_with_parameters ',' parameter_declaration
589 insert_at_tail(& $$->parameters,
590 (struct simple_node *) $3);
595 fully_specified_type IDENTIFIER '('
597 $$ = new ast_function();
598 $$->return_type = $1;
603 parameter_declarator:
604 type_specifier IDENTIFIER
606 $$ = new ast_parameter_declarator();
607 $$->type = new ast_fully_specified_type();
608 $$->type->specifier = $1;
611 | type_specifier IDENTIFIER '[' constant_expression ']'
613 $$ = new ast_parameter_declarator();
614 $$->type = new ast_fully_specified_type();
615 $$->type->specifier = $1;
622 parameter_declaration:
623 parameter_type_qualifier parameter_qualifier parameter_declarator
628 $$->type->qualifier = $1.q;
630 | parameter_qualifier parameter_declarator
633 $$->type->qualifier = $1.q;
635 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
639 $$ = new ast_parameter_declarator();
640 $$->type = new ast_fully_specified_type();
641 $$->type->qualifier = $1.q;
642 $$->type->specifier = $3;
644 | parameter_qualifier parameter_type_specifier
646 $$ = new ast_parameter_declarator();
647 $$->type = new ast_fully_specified_type();
648 $$->type->qualifier = $1.q;
649 $$->type->specifier = $2;
654 /* empty */ { $$.i = 0; }
655 | IN { $$.i = 0; $$.q.in = 1; }
656 | OUT { $$.i = 0; $$.q.out = 1; }
657 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
660 parameter_type_specifier:
664 init_declarator_list:
666 | init_declarator_list ',' IDENTIFIER
668 ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
671 insert_at_tail(& $$->declarations,
672 (struct simple_node *) decl);
674 | init_declarator_list ',' IDENTIFIER '[' ']'
676 ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
679 insert_at_tail(& $$->declarations,
680 (struct simple_node *) decl);
682 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
684 ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
687 insert_at_tail(& $$->declarations,
688 (struct simple_node *) decl);
690 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
692 ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
695 insert_at_tail(& $$->declarations,
696 (struct simple_node *) decl);
698 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
700 ast_declaration *decl = new ast_declaration($3, true, $5, $8);
703 insert_at_tail(& $$->declarations,
704 (struct simple_node *) decl);
706 | init_declarator_list ',' IDENTIFIER '=' initializer
708 ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
711 insert_at_tail(& $$->declarations,
712 (struct simple_node *) decl);
716 // Grammar Note: No 'enum', or 'typedef'.
720 $$ = new ast_declarator_list($1);
722 | fully_specified_type IDENTIFIER
724 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
726 $$ = new ast_declarator_list($1);
727 insert_at_tail(& $$->declarations,
728 (struct simple_node *) decl);
730 | fully_specified_type IDENTIFIER '[' ']'
732 ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
734 $$ = new ast_declarator_list($1);
735 insert_at_tail(& $$->declarations,
736 (struct simple_node *) decl);
738 | fully_specified_type IDENTIFIER '[' constant_expression ']'
740 ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
742 $$ = new ast_declarator_list($1);
743 insert_at_tail(& $$->declarations,
744 (struct simple_node *) decl);
746 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
748 ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
750 $$ = new ast_declarator_list($1);
751 insert_at_tail(& $$->declarations,
752 (struct simple_node *) decl);
754 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
756 ast_declaration *decl = new ast_declaration($2, true, $4, $7);
758 $$ = new ast_declarator_list($1);
759 insert_at_tail(& $$->declarations,
760 (struct simple_node *) decl);
762 | fully_specified_type IDENTIFIER '=' initializer
764 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
766 $$ = new ast_declarator_list($1);
767 insert_at_tail(& $$->declarations,
768 (struct simple_node *) decl);
770 | INVARIANT IDENTIFIER // Vertex only.
772 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
774 $$ = new ast_declarator_list(NULL);
775 $$->invariant = true;
777 insert_at_tail(& $$->declarations,
778 (struct simple_node *) decl);
782 fully_specified_type:
785 $$ = new ast_fully_specified_type();
788 | type_qualifier type_specifier
790 $$ = new ast_fully_specified_type();
791 $$->qualifier = $1.q;
796 interpolation_qualifier:
797 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
798 | FLAT { $$.i = 0; $$.q.flat = 1; }
799 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
802 parameter_type_qualifier:
803 CONST { $$.i = 0; $$.q.constant = 1; }
808 | interpolation_qualifier type_qualifier
812 | INVARIANT type_qualifier
820 CONST { $$.i = 0; $$.q.constant = 1; }
821 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
822 | VARYING { $$.i = 0; $$.q.varying = 1; }
823 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
824 | IN { $$.i = 0; $$.q.in = 1; }
825 | OUT { $$.i = 0; $$.q.out = 1; }
826 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
827 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
828 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
832 type_specifier_no_prec
833 | precision_qualifier type_specifier_no_prec
840 type_specifier_no_prec:
841 type_specifier_nonarray
842 | type_specifier_nonarray '[' ']'
846 $$->array_size = NULL;
848 | type_specifier_nonarray '[' constant_expression ']'
856 type_specifier_nonarray:
857 basic_type_specifier_nonarray
859 $$ = new ast_type_specifier($1);
863 $$ = new ast_type_specifier($1);
867 $$ = new ast_type_specifier($1);
871 basic_type_specifier_nonarray:
872 VOID { $$ = ast_void; }
873 | FLOAT { $$ = ast_float; }
874 | INT { $$ = ast_int; }
875 | UINT { $$ = ast_uint; }
876 | BOOL { $$ = ast_bool; }
877 | VEC2 { $$ = ast_vec2; }
878 | VEC3 { $$ = ast_vec3; }
879 | VEC4 { $$ = ast_vec4; }
880 | BVEC2 { $$ = ast_bvec2; }
881 | BVEC3 { $$ = ast_bvec3; }
882 | BVEC4 { $$ = ast_bvec4; }
883 | IVEC2 { $$ = ast_ivec2; }
884 | IVEC3 { $$ = ast_ivec3; }
885 | IVEC4 { $$ = ast_ivec4; }
886 | UVEC2 { $$ = ast_uvec2; }
887 | UVEC3 { $$ = ast_uvec3; }
888 | UVEC4 { $$ = ast_uvec4; }
889 | MAT2 { $$ = ast_mat2; }
890 | MAT3 { $$ = ast_mat3; }
891 | MAT4 { $$ = ast_mat4; }
892 | MAT2X2 { $$ = ast_mat2; }
893 | MAT2X3 { $$ = ast_mat2x3; }
894 | MAT2X4 { $$ = ast_mat2x4; }
895 | MAT3X2 { $$ = ast_mat3x2; }
896 | MAT3X3 { $$ = ast_mat3; }
897 | MAT3X4 { $$ = ast_mat3x4; }
898 | MAT4X2 { $$ = ast_mat4x2; }
899 | MAT4X3 { $$ = ast_mat4x3; }
900 | MAT4X4 { $$ = ast_mat4; }
901 | SAMPLER1D { $$ = ast_sampler1d; }
902 | SAMPLER2D { $$ = ast_sampler2d; }
903 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
904 | SAMPLER3D { $$ = ast_sampler3d; }
905 | SAMPLERCUBE { $$ = ast_samplercube; }
906 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
907 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
908 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
909 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
910 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
911 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
912 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
913 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
914 | ISAMPLER1D { $$ = ast_isampler1d; }
915 | ISAMPLER2D { $$ = ast_isampler2d; }
916 | ISAMPLER3D { $$ = ast_isampler3d; }
917 | ISAMPLERCUBE { $$ = ast_isamplercube; }
918 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
919 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
920 | USAMPLER1D { $$ = ast_usampler1d; }
921 | USAMPLER2D { $$ = ast_usampler2d; }
922 | USAMPLER3D { $$ = ast_usampler3d; }
923 | USAMPLERCUBE { $$ = ast_usamplercube; }
924 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
925 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
929 HIGH_PRECISION { $$ = ast_precision_high; }
930 | MEDIUM_PRECISION { $$ = ast_precision_medium; }
931 | LOW_PRECISION { $$ = ast_precision_low; }
935 STRUCT IDENTIFIER '{' struct_declaration_list '}'
937 $$ = new ast_struct_specifier($2, $4);
939 | STRUCT '{' struct_declaration_list '}'
941 $$ = new ast_struct_specifier(NULL, $3);
945 struct_declaration_list:
948 $$ = (struct ast_node *) $1;
950 | struct_declaration_list struct_declaration
952 $$ = (struct ast_node *) $1;
953 insert_at_tail((struct simple_node *) $$,
954 (struct simple_node *) $2);
959 type_specifier struct_declarator_list ';'
961 ast_fully_specified_type *type = new ast_fully_specified_type();
963 type->specifier = $1;
964 $$ = new ast_declarator_list(type);
966 insert_at_tail((struct simple_node *) $2,
971 struct_declarator_list:
973 | struct_declarator_list ',' struct_declarator
976 insert_at_tail((struct simple_node *) $$,
977 (struct simple_node *) $3);
984 $$ = new ast_declaration($1, false, NULL, NULL);
986 | IDENTIFIER '[' constant_expression ']'
988 $$ = new ast_declaration($1, true, $3, NULL);
993 assignment_expression
996 declaration_statement:
1000 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1004 | statement_unmatched
1008 compound_statement { $$ = (struct ast_node *) $1; }
1012 statement_unmatched:
1013 selection_statement_unmatched
1017 declaration_statement
1018 | expression_statement
1019 | selection_statement_matched
1020 | switch_statement { $$ = NULL; }
1021 | case_label { $$ = NULL; }
1022 | iteration_statement
1029 $$ = new ast_compound_statement(true, NULL);
1031 | '{' statement_list '}'
1033 $$ = new ast_compound_statement(true, $2);
1037 statement_no_new_scope:
1038 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1042 compound_statement_no_new_scope:
1045 $$ = new ast_compound_statement(false, NULL);
1047 | '{' statement_list '}'
1049 $$ = new ast_compound_statement(false, $2);
1057 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1062 make_empty_list((struct simple_node *) $$);
1064 | statement_list statement
1067 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1071 insert_at_tail((struct simple_node *) $$,
1072 (struct simple_node *) $2);
1076 expression_statement:
1079 $$ = new ast_expression_statement(NULL);
1083 $$ = new ast_expression_statement($1);
1087 selection_statement_matched:
1088 IF '(' expression ')' statement_matched ELSE statement_matched
1090 $$ = new ast_selection_statement($3, $5, $7);
1094 selection_statement_unmatched:
1095 IF '(' expression ')' statement_matched
1097 $$ = new ast_selection_statement($3, $5, NULL);
1099 | IF '(' expression ')' statement_unmatched
1101 $$ = new ast_selection_statement($3, $5, NULL);
1103 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1105 $$ = new ast_selection_statement($3, $5, $7);
1112 $$ = (struct ast_node *) $1;
1114 | fully_specified_type IDENTIFIER '=' initializer
1116 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
1117 ast_declarator_list *declarator = new ast_declarator_list($1);
1119 insert_at_tail(& declarator->declarations,
1120 (struct simple_node *) decl);
1127 SWITCH '(' expression ')' compound_statement
1135 iteration_statement:
1136 WHILE '(' condition ')' statement_no_new_scope
1138 $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
1139 NULL, $3, NULL, $5);
1141 | DO statement WHILE '(' expression ')' ';'
1143 $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
1144 NULL, $5, NULL, $2);
1146 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1148 $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
1149 $3, $4.cond, $4.rest, $6);
1154 expression_statement
1155 | declaration_statement
1172 | conditionopt ';' expression
1179 // Grammar Note: No 'goto'. Gotos are not supported.
1183 $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1187 $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
1191 $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
1193 | RETURN expression ';'
1195 $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
1197 | DISCARD ';' // Fragment shader only.
1199 $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1203 external_declaration:
1204 function_definition { $$ = $1; }
1205 | declaration { $$ = $1; }
1208 function_definition:
1209 function_prototype compound_statement_no_new_scope
1211 $$ = new ast_function_definition();