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 "symbol_table.h"
32 #include "glsl_types.h"
34 #define YYLEX_PARAM state->scanner
42 %lex-param {void *scanner}
43 %parse-param {struct _mesa_glsl_parse_state *state}
44 %name-prefix "_mesa_glsl_"
52 struct ast_type_qualifier q;
56 struct ast_node *node;
57 struct ast_type_specifier *type_specifier;
58 struct ast_fully_specified_type *fully_specified_type;
59 struct ast_function *function;
60 struct ast_parameter_declarator *parameter_declarator;
61 struct ast_function_definition *function_definition;
62 struct ast_compound_statement *compound_statement;
63 struct ast_expression *expression;
64 struct ast_declarator_list *declarator_list;
65 struct ast_struct_specifier *struct_specifier;
66 struct ast_declaration *declaration;
69 struct ast_node *cond;
70 struct ast_expression *rest;
74 %token ATTRIBUTE CONST BOOL FLOAT INT UINT
75 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
76 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
77 %token MAT2 MAT3 MAT4 CENTROID IN OUT INOUT UNIFORM VARYING
78 %token NOPERSPECTIVE FLAT SMOOTH
79 %token MAT2X2 MAT2X3 MAT2X4
80 %token MAT3X2 MAT3X3 MAT3X4
81 %token MAT4X2 MAT4X3 MAT4X4
82 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
83 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
84 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
85 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
86 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
87 %token STRUCT VOID WHILE
88 %token <identifier> IDENTIFIER TYPE_NAME
89 %token <real> FLOATCONSTANT
90 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
91 %token <identifier> FIELD_SELECTION
92 %token LEFT_OP RIGHT_OP
93 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
94 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
95 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
98 %token HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION
100 %token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
102 /* Reserved words that are not actually used in the grammar.
104 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED GOTO
105 %token INLINE NOINLINE VOLATILE PUBLIC STATIC EXTERN EXTERNAL
106 %token LONG SHORT DOUBLE HALF FIXED UNSIGNED INPUT OUPTUT
107 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
108 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
109 %token SIZEOF CAST NAMESPACE USING LOWP MEDIUMP HIGHP
111 %type <identifier> variable_identifier
112 %type <node> statement
113 %type <node> statement_list
114 %type <node> simple_statement
115 %type <node> statement_matched
116 %type <node> statement_unmatched
117 %type <n> precision_qualifier
118 %type <type_qualifier> type_qualifier
119 %type <type_qualifier> storage_qualifier
120 %type <type_qualifier> interpolation_qualifier
121 %type <type_specifier> type_specifier
122 %type <type_specifier> type_specifier_no_prec
123 %type <type_specifier> type_specifier_nonarray
124 %type <n> basic_type_specifier_nonarray
125 %type <fully_specified_type> fully_specified_type
126 %type <function> function_prototype
127 %type <function> function_header
128 %type <function> function_header_with_parameters
129 %type <function> function_declarator
130 %type <parameter_declarator> parameter_declarator
131 %type <parameter_declarator> parameter_declaration
132 %type <type_qualifier> parameter_qualifier
133 %type <type_qualifier> parameter_type_qualifier
134 %type <type_specifier> parameter_type_specifier
135 %type <function_definition> function_definition
136 %type <compound_statement> compound_statement_no_new_scope
137 %type <compound_statement> compound_statement
138 %type <node> statement_no_new_scope
139 %type <node> expression_statement
140 %type <expression> expression
141 %type <expression> primary_expression
142 %type <expression> assignment_expression
143 %type <expression> conditional_expression
144 %type <expression> logical_or_expression
145 %type <expression> logical_xor_expression
146 %type <expression> logical_and_expression
147 %type <expression> inclusive_or_expression
148 %type <expression> exclusive_or_expression
149 %type <expression> and_expression
150 %type <expression> equality_expression
151 %type <expression> relational_expression
152 %type <expression> shift_expression
153 %type <expression> additive_expression
154 %type <expression> multiplicative_expression
155 %type <expression> unary_expression
156 %type <expression> constant_expression
157 %type <expression> integer_expression
158 %type <expression> postfix_expression
159 %type <expression> function_call_header_with_parameters
160 %type <expression> function_call_header_no_parameters
161 %type <expression> function_call_header
162 %type <expression> function_call_generic
163 %type <expression> function_call_or_method
164 %type <expression> function_call
165 %type <n> assignment_operator
166 %type <n> unary_operator
167 %type <node> function_identifier
168 %type <node> external_declaration
169 %type <declarator_list> init_declarator_list
170 %type <declarator_list> single_declaration
171 %type <expression> initializer
172 %type <node> declaration
173 %type <node> declaration_statement
174 %type <node> jump_statement
175 %type <struct_specifier> struct_specifier
176 %type <node> struct_declaration_list
177 %type <declarator_list> struct_declaration
178 %type <declaration> struct_declarator
179 %type <declaration> struct_declarator_list
180 %type <node> selection_statement_matched
181 %type <node> selection_statement_unmatched
182 %type <node> iteration_statement
183 %type <node> condition
184 %type <node> conditionopt
185 %type <node> for_init_statement
186 %type <for_rest_statement> for_rest_statement
192 _mesa_glsl_initialize_types(state);
194 external_declaration_list
197 state->language_version = 110;
198 _mesa_glsl_initialize_types(state);
200 external_declaration_list
204 VERSION INTCONSTANT EOL
210 /* FINISHME: Check against implementation support versions. */
211 state->language_version = $2;
214 _mesa_glsl_error(& @2, state, "Shading language version"
215 "%u is not supported\n", $2);
221 external_declaration_list:
224 insert_at_tail(& state->translation_unit,
225 (struct simple_node *) $1);
227 | external_declaration_list external_declaration
229 insert_at_tail(& state->translation_unit,
230 (struct simple_node *) $2);
241 $$ = new ast_expression(ast_identifier, NULL, NULL, NULL);
242 $$->primary_expression.identifier = $1;
246 $$ = new ast_expression(ast_int_constant, NULL, NULL, NULL);
247 $$->primary_expression.int_constant = $1;
251 $$ = new ast_expression(ast_uint_constant, NULL, NULL, NULL);
252 $$->primary_expression.uint_constant = $1;
256 $$ = new ast_expression(ast_float_constant, NULL, NULL, NULL);
257 $$->primary_expression.float_constant = $1;
261 $$ = new ast_expression(ast_bool_constant, NULL, NULL, NULL);
262 $$->primary_expression.bool_constant = $1;
272 | postfix_expression '[' integer_expression ']'
274 $$ = new ast_expression(ast_array_index, $1, $3, NULL);
280 | postfix_expression '.' IDENTIFIER
282 $$ = new ast_expression(ast_field_selection, $1, NULL, NULL);
283 $$->primary_expression.identifier = $3;
285 | postfix_expression INC_OP
287 $$ = new ast_expression(ast_post_inc, $1, NULL, NULL);
289 | postfix_expression DEC_OP
291 $$ = new ast_expression(ast_post_dec, $1, NULL, NULL);
300 function_call_or_method
303 function_call_or_method:
304 function_call_generic
305 | postfix_expression '.' function_call_generic
307 $$ = new ast_expression(ast_field_selection, $1, $3, NULL);
311 function_call_generic:
312 function_call_header_with_parameters ')'
313 | function_call_header_no_parameters ')'
316 function_call_header_no_parameters:
317 function_call_header VOID
318 | function_call_header
321 function_call_header_with_parameters:
322 function_call_header assignment_expression
325 $$->subexpressions[1] = $2;
327 | function_call_header_with_parameters ',' assignment_expression
330 insert_at_tail((struct simple_node *) $$->subexpressions[1],
331 (struct simple_node *) $3);
335 // Grammar Note: Constructors look like functions, but lexical
336 // analysis recognized most of them as keywords. They are now
337 // recognized through "type_specifier".
338 function_call_header:
339 function_identifier '('
341 $$ = new ast_expression(ast_function_call,
342 (struct ast_expression *) $1,
350 $$ = (struct ast_node *) $1;
354 ast_expression *expr =
355 new ast_expression(ast_identifier, NULL, NULL, NULL);
356 expr->primary_expression.identifier = $1;
358 $$ = (struct ast_node *) expr;
362 ast_expression *expr =
363 new ast_expression(ast_identifier, NULL, NULL, NULL);
364 expr->primary_expression.identifier = $1;
366 $$ = (struct ast_node *) expr;
370 // Grammar Note: No traditional style type casts.
373 | INC_OP unary_expression
375 $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
377 | DEC_OP unary_expression
379 $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
381 | unary_operator unary_expression
383 $$ = new ast_expression($1, $2, NULL, NULL);
387 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
389 '+' { $$ = ast_plus; }
390 | '-' { $$ = ast_neg; }
391 | '!' { $$ = ast_logic_not; }
392 | '~' { $$ = ast_bit_not; }
395 multiplicative_expression:
397 | multiplicative_expression '*' unary_expression
399 $$ = new ast_expression_bin(ast_mul, $1, $3);
401 | multiplicative_expression '/' unary_expression
403 $$ = new ast_expression_bin(ast_div, $1, $3);
405 | multiplicative_expression '%' unary_expression
407 $$ = new ast_expression_bin(ast_mod, $1, $3);
412 multiplicative_expression
413 | additive_expression '+' multiplicative_expression
415 $$ = new ast_expression_bin(ast_add, $1, $3);
417 | additive_expression '-' multiplicative_expression
419 $$ = new ast_expression_bin(ast_sub, $1, $3);
425 | shift_expression LEFT_OP additive_expression
427 $$ = new ast_expression_bin(ast_lshift, $1, $3);
429 | shift_expression RIGHT_OP additive_expression
431 $$ = new ast_expression_bin(ast_rshift, $1, $3);
435 relational_expression:
437 | relational_expression '<' shift_expression
439 $$ = new ast_expression_bin(ast_less, $1, $3);
441 | relational_expression '>' shift_expression
443 $$ = new ast_expression_bin(ast_greater, $1, $3);
445 | relational_expression LE_OP shift_expression
447 $$ = new ast_expression_bin(ast_lequal, $1, $3);
449 | relational_expression GE_OP shift_expression
451 $$ = new ast_expression_bin(ast_gequal, $1, $3);
456 relational_expression
457 | equality_expression EQ_OP relational_expression
459 $$ = new ast_expression_bin(ast_equal, $1, $3);
461 | equality_expression NE_OP relational_expression
463 $$ = new ast_expression_bin(ast_nequal, $1, $3);
469 | and_expression '&' equality_expression
471 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
475 exclusive_or_expression:
477 | exclusive_or_expression '^' and_expression
479 $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
483 inclusive_or_expression:
484 exclusive_or_expression
485 | inclusive_or_expression '|' exclusive_or_expression
487 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
491 logical_and_expression:
492 inclusive_or_expression
493 | logical_and_expression AND_OP inclusive_or_expression
495 $$ = new ast_expression_bin(ast_logic_and, $1, $3);
499 logical_xor_expression:
500 logical_and_expression
501 | logical_xor_expression XOR_OP logical_and_expression
503 $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
507 logical_or_expression:
508 logical_xor_expression
509 | logical_or_expression OR_OP logical_xor_expression
511 $$ = new ast_expression_bin(ast_logic_or, $1, $3);
515 conditional_expression:
516 logical_or_expression
517 | logical_or_expression '?' expression ':' assignment_expression
519 $$ = new ast_expression(ast_conditional, $1, $3, $5);
523 assignment_expression:
524 conditional_expression
525 | unary_expression assignment_operator assignment_expression
527 $$ = new ast_expression($2, $1, $3, NULL);
532 '=' { $$ = ast_assign; }
533 | MUL_ASSIGN { $$ = ast_mul_assign; }
534 | DIV_ASSIGN { $$ = ast_div_assign; }
535 | MOD_ASSIGN { $$ = ast_mod_assign; }
536 | ADD_ASSIGN { $$ = ast_add_assign; }
537 | SUB_ASSIGN { $$ = ast_sub_assign; }
538 | LEFT_ASSIGN { $$ = ast_ls_assign; }
539 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
540 | AND_ASSIGN { $$ = ast_and_assign; }
541 | XOR_ASSIGN { $$ = ast_xor_assign; }
542 | OR_ASSIGN { $$ = ast_or_assign; }
546 assignment_expression
550 | expression ',' assignment_expression
552 if ($1->oper != ast_sequence) {
553 $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
554 insert_at_tail(& $$->expressions, $1);
559 insert_at_tail(& $$->expressions, $3);
564 conditional_expression
568 function_prototype ';'
572 | init_declarator_list ';'
576 | PRECISION precision_qualifier type_specifier_no_prec ';'
578 $$ = NULL; /* FINISHME */
583 function_declarator ')'
588 | function_header_with_parameters
591 function_header_with_parameters:
592 function_header parameter_declaration
595 insert_at_head(& $$->parameters,
596 (struct simple_node *) $2);
598 | function_header_with_parameters ',' parameter_declaration
601 insert_at_head(& $$->parameters,
602 (struct simple_node *) $3);
607 fully_specified_type IDENTIFIER '('
609 $$ = new ast_function();
610 $$->return_type = $1;
615 parameter_declarator:
616 type_specifier IDENTIFIER
618 $$ = new ast_parameter_declarator();
619 $$->type = new ast_fully_specified_type();
620 $$->type->specifier = $1;
623 | type_specifier IDENTIFIER '[' constant_expression ']'
625 $$ = new ast_parameter_declarator();
626 $$->type = new ast_fully_specified_type();
627 $$->type->specifier = $1;
634 parameter_declaration:
635 parameter_type_qualifier parameter_qualifier parameter_declarator
640 $$->type->qualifier = $1.q;
642 | parameter_qualifier parameter_declarator
645 $$->type->qualifier = $1.q;
647 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
651 $$ = new ast_parameter_declarator();
652 $$->type = new ast_fully_specified_type();
653 $$->type->qualifier = $1.q;
654 $$->type->specifier = $3;
656 | parameter_qualifier parameter_type_specifier
658 $$ = new ast_parameter_declarator();
659 $$->type = new ast_fully_specified_type();
660 $$->type->qualifier = $1.q;
661 $$->type->specifier = $2;
666 /* empty */ { $$.i = 0; }
667 | IN { $$.i = 0; $$.q.in = 1; }
668 | OUT { $$.i = 0; $$.q.out = 1; }
669 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
672 parameter_type_specifier:
676 init_declarator_list:
678 | init_declarator_list ',' IDENTIFIER
680 ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
683 insert_at_tail(& $$->declarations,
684 (struct simple_node *) decl);
686 | init_declarator_list ',' IDENTIFIER '[' ']'
688 ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
691 insert_at_tail(& $$->declarations,
692 (struct simple_node *) decl);
694 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
696 ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
699 insert_at_tail(& $$->declarations,
700 (struct simple_node *) decl);
702 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
704 ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
707 insert_at_tail(& $$->declarations,
708 (struct simple_node *) decl);
710 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
712 ast_declaration *decl = new ast_declaration($3, true, $5, $8);
715 insert_at_tail(& $$->declarations,
716 (struct simple_node *) decl);
718 | init_declarator_list ',' IDENTIFIER '=' initializer
720 ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
723 insert_at_tail(& $$->declarations,
724 (struct simple_node *) decl);
728 // Grammar Note: No 'enum', or 'typedef'.
732 $$ = new ast_declarator_list($1);
734 | fully_specified_type IDENTIFIER
736 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
738 $$ = new ast_declarator_list($1);
739 insert_at_tail(& $$->declarations,
740 (struct simple_node *) decl);
742 | fully_specified_type IDENTIFIER '[' ']'
744 ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
746 $$ = new ast_declarator_list($1);
747 insert_at_tail(& $$->declarations,
748 (struct simple_node *) decl);
750 | fully_specified_type IDENTIFIER '[' constant_expression ']'
752 ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
754 $$ = new ast_declarator_list($1);
755 insert_at_tail(& $$->declarations,
756 (struct simple_node *) decl);
758 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
760 ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
762 $$ = new ast_declarator_list($1);
763 insert_at_tail(& $$->declarations,
764 (struct simple_node *) decl);
766 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
768 ast_declaration *decl = new ast_declaration($2, true, $4, $7);
770 $$ = new ast_declarator_list($1);
771 insert_at_tail(& $$->declarations,
772 (struct simple_node *) decl);
774 | fully_specified_type IDENTIFIER '=' initializer
776 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
778 $$ = new ast_declarator_list($1);
779 insert_at_tail(& $$->declarations,
780 (struct simple_node *) decl);
782 | INVARIANT IDENTIFIER // Vertex only.
784 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
786 $$ = new ast_declarator_list(NULL);
787 $$->invariant = true;
789 insert_at_tail(& $$->declarations,
790 (struct simple_node *) decl);
794 fully_specified_type:
797 $$ = new ast_fully_specified_type();
800 | type_qualifier type_specifier
802 $$ = new ast_fully_specified_type();
803 $$->qualifier = $1.q;
808 interpolation_qualifier:
809 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
810 | FLAT { $$.i = 0; $$.q.flat = 1; }
811 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
814 parameter_type_qualifier:
815 CONST { $$.i = 0; $$.q.constant = 1; }
820 | interpolation_qualifier type_qualifier
824 | INVARIANT type_qualifier
832 CONST { $$.i = 0; $$.q.constant = 1; }
833 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
834 | VARYING { $$.i = 0; $$.q.varying = 1; }
835 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
836 | IN { $$.i = 0; $$.q.in = 1; }
837 | OUT { $$.i = 0; $$.q.out = 1; }
838 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
839 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
840 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
844 type_specifier_no_prec
845 | precision_qualifier type_specifier_no_prec
852 type_specifier_no_prec:
853 type_specifier_nonarray
854 | type_specifier_nonarray '[' ']'
858 $$->array_size = NULL;
860 | type_specifier_nonarray '[' constant_expression ']'
868 type_specifier_nonarray:
869 basic_type_specifier_nonarray
871 $$ = new ast_type_specifier($1);
875 $$ = new ast_type_specifier(ast_struct);
880 $$ = new ast_type_specifier(ast_type_name);
885 basic_type_specifier_nonarray:
886 VOID { $$ = ast_void; }
887 | FLOAT { $$ = ast_float; }
888 | INT { $$ = ast_int; }
889 | UINT { $$ = ast_uint; }
890 | BOOL { $$ = ast_bool; }
891 | VEC2 { $$ = ast_vec2; }
892 | VEC3 { $$ = ast_vec3; }
893 | VEC4 { $$ = ast_vec4; }
894 | BVEC2 { $$ = ast_bvec2; }
895 | BVEC3 { $$ = ast_bvec3; }
896 | BVEC4 { $$ = ast_bvec4; }
897 | IVEC2 { $$ = ast_ivec2; }
898 | IVEC3 { $$ = ast_ivec3; }
899 | IVEC4 { $$ = ast_ivec4; }
900 | UVEC2 { $$ = ast_uvec2; }
901 | UVEC3 { $$ = ast_uvec3; }
902 | UVEC4 { $$ = ast_uvec4; }
903 | MAT2 { $$ = ast_mat2; }
904 | MAT3 { $$ = ast_mat3; }
905 | MAT4 { $$ = ast_mat4; }
906 | MAT2X2 { $$ = ast_mat2; }
907 | MAT2X3 { $$ = ast_mat2x3; }
908 | MAT2X4 { $$ = ast_mat2x4; }
909 | MAT3X2 { $$ = ast_mat3x2; }
910 | MAT3X3 { $$ = ast_mat3; }
911 | MAT3X4 { $$ = ast_mat3x4; }
912 | MAT4X2 { $$ = ast_mat4x2; }
913 | MAT4X3 { $$ = ast_mat4x3; }
914 | MAT4X4 { $$ = ast_mat4; }
915 | SAMPLER1D { $$ = ast_sampler1d; }
916 | SAMPLER2D { $$ = ast_sampler2d; }
917 | SAMPLER3D { $$ = ast_sampler3d; }
918 | SAMPLERCUBE { $$ = ast_samplercube; }
919 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
920 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
921 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
922 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
923 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
924 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
925 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
926 | ISAMPLER1D { $$ = ast_isampler1d; }
927 | ISAMPLER2D { $$ = ast_isampler2d; }
928 | ISAMPLER3D { $$ = ast_isampler3d; }
929 | ISAMPLERCUBE { $$ = ast_isamplercube; }
930 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
931 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
932 | USAMPLER1D { $$ = ast_usampler1d; }
933 | USAMPLER2D { $$ = ast_usampler2d; }
934 | USAMPLER3D { $$ = ast_usampler3d; }
935 | USAMPLERCUBE { $$ = ast_usamplercube; }
936 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
937 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
941 HIGH_PRECISION { $$ = ast_precision_high; }
942 | MEDIUM_PRECISION { $$ = ast_precision_medium; }
943 | LOW_PRECISION { $$ = ast_precision_low; }
947 STRUCT IDENTIFIER '{' struct_declaration_list '}'
949 $$ = new ast_struct_specifier($2, $4);
951 _mesa_symbol_table_add_symbol(state->symbols, 0, $2, $$);
953 | STRUCT '{' struct_declaration_list '}'
955 $$ = new ast_struct_specifier(NULL, $3);
959 struct_declaration_list:
962 $$ = (struct ast_node *) $1;
964 | struct_declaration_list struct_declaration
966 $$ = (struct ast_node *) $1;
967 insert_at_tail((struct simple_node *) $$,
968 (struct simple_node *) $2);
973 type_specifier struct_declarator_list ';'
975 ast_fully_specified_type *type = new ast_fully_specified_type();
977 type->specifier = $1;
978 $$ = new ast_declarator_list(type);
980 insert_at_tail((struct simple_node *) $2,
985 struct_declarator_list:
987 | struct_declarator_list ',' struct_declarator
990 insert_at_tail((struct simple_node *) $$,
991 (struct simple_node *) $3);
998 $$ = new ast_declaration($1, false, NULL, NULL);
1000 | IDENTIFIER '[' constant_expression ']'
1002 $$ = new ast_declaration($1, true, $3, NULL);
1007 assignment_expression
1010 declaration_statement:
1014 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1018 | statement_unmatched
1022 compound_statement { $$ = (struct ast_node *) $1; }
1026 statement_unmatched:
1027 selection_statement_unmatched
1031 declaration_statement
1032 | expression_statement
1033 | selection_statement_matched
1034 | switch_statement { $$ = NULL; }
1035 | case_label { $$ = NULL; }
1036 | iteration_statement
1043 $$ = new ast_compound_statement(true, NULL);
1045 | '{' statement_list '}'
1047 $$ = new ast_compound_statement(true, $2);
1051 statement_no_new_scope:
1052 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1056 compound_statement_no_new_scope:
1059 $$ = new ast_compound_statement(false, NULL);
1061 | '{' statement_list '}'
1063 $$ = new ast_compound_statement(false, $2);
1071 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1076 make_empty_list((struct simple_node *) $$);
1078 | statement_list statement
1081 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1085 insert_at_tail((struct simple_node *) $$,
1086 (struct simple_node *) $2);
1090 expression_statement:
1093 $$ = new ast_expression_statement(NULL);
1097 $$ = new ast_expression_statement($1);
1101 selection_statement_matched:
1102 IF '(' expression ')' statement_matched ELSE statement_matched
1104 $$ = new ast_selection_statement($3, $5, $7);
1108 selection_statement_unmatched:
1109 IF '(' expression ')' statement_matched
1111 $$ = new ast_selection_statement($3, $5, NULL);
1113 | IF '(' expression ')' statement_unmatched
1115 $$ = new ast_selection_statement($3, $5, NULL);
1117 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1119 $$ = new ast_selection_statement($3, $5, $7);
1126 $$ = (struct ast_node *) $1;
1128 | fully_specified_type IDENTIFIER '=' initializer
1130 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
1131 ast_declarator_list *declarator = new ast_declarator_list($1);
1133 insert_at_tail(& declarator->declarations,
1134 (struct simple_node *) decl);
1141 SWITCH '(' expression ')' compound_statement
1149 iteration_statement:
1150 WHILE '(' condition ')' statement_no_new_scope
1152 $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
1153 NULL, $3, NULL, $5);
1155 | DO statement WHILE '(' expression ')' ';'
1157 $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
1158 NULL, $5, NULL, $2);
1160 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1162 $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
1163 $3, $4.cond, $4.rest, $6);
1168 expression_statement
1169 | declaration_statement
1186 | conditionopt ';' expression
1193 // Grammar Note: No 'goto'. Gotos are not supported.
1197 $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1201 $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
1205 $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
1207 | RETURN expression ';'
1209 $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
1211 | DISCARD ';' // Fragment shader only.
1213 $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1217 external_declaration:
1218 function_definition { $$ = $1; }
1219 | declaration { $$ = $1; }
1222 function_definition:
1223 function_prototype compound_statement_no_new_scope
1225 $$ = new ast_function_definition();