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}
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 <node> 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 '('
340 $$ = new ast_expression(ast_function_call,
341 (struct ast_expression *) $1,
349 $$ = (struct ast_node *) $1;
353 ast_expression *expr =
354 new ast_expression(ast_identifier, NULL, NULL, NULL);
355 expr->primary_expression.identifier = $1;
357 $$ = (struct ast_node *) expr;
361 ast_expression *expr =
362 new ast_expression(ast_identifier, NULL, NULL, NULL);
363 expr->primary_expression.identifier = $1;
365 $$ = (struct ast_node *) expr;
369 // Grammar Note: No traditional style type casts.
372 | INC_OP unary_expression
374 $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
376 | DEC_OP unary_expression
378 $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
380 | unary_operator unary_expression
382 $$ = new ast_expression($1, $2, NULL, NULL);
386 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
388 '+' { $$ = ast_plus; }
389 | '-' { $$ = ast_neg; }
390 | '!' { $$ = ast_logic_not; }
391 | '~' { $$ = ast_bit_not; }
394 multiplicative_expression:
396 | multiplicative_expression '*' unary_expression
398 $$ = new ast_expression_bin(ast_mul, $1, $3);
400 | multiplicative_expression '/' unary_expression
402 $$ = new ast_expression_bin(ast_div, $1, $3);
404 | multiplicative_expression '%' unary_expression
406 $$ = new ast_expression_bin(ast_mod, $1, $3);
411 multiplicative_expression
412 | additive_expression '+' multiplicative_expression
414 $$ = new ast_expression_bin(ast_add, $1, $3);
416 | additive_expression '-' multiplicative_expression
418 $$ = new ast_expression_bin(ast_sub, $1, $3);
424 | shift_expression LEFT_OP additive_expression
426 $$ = new ast_expression_bin(ast_lshift, $1, $3);
428 | shift_expression RIGHT_OP additive_expression
430 $$ = new ast_expression_bin(ast_rshift, $1, $3);
434 relational_expression:
436 | relational_expression '<' shift_expression
438 $$ = new ast_expression_bin(ast_less, $1, $3);
440 | relational_expression '>' shift_expression
442 $$ = new ast_expression_bin(ast_greater, $1, $3);
444 | relational_expression LE_OP shift_expression
446 $$ = new ast_expression_bin(ast_lequal, $1, $3);
448 | relational_expression GE_OP shift_expression
450 $$ = new ast_expression_bin(ast_gequal, $1, $3);
455 relational_expression
456 | equality_expression EQ_OP relational_expression
458 $$ = new ast_expression_bin(ast_equal, $1, $3);
460 | equality_expression NE_OP relational_expression
462 $$ = new ast_expression_bin(ast_nequal, $1, $3);
468 | and_expression '&' equality_expression
470 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
474 exclusive_or_expression:
476 | exclusive_or_expression '^' and_expression
478 $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
482 inclusive_or_expression:
483 exclusive_or_expression
484 | inclusive_or_expression '|' exclusive_or_expression
486 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
490 logical_and_expression:
491 inclusive_or_expression
492 | logical_and_expression AND_OP inclusive_or_expression
494 $$ = new ast_expression_bin(ast_logic_and, $1, $3);
498 logical_xor_expression:
499 logical_and_expression
500 | logical_xor_expression XOR_OP logical_and_expression
502 $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
506 logical_or_expression:
507 logical_xor_expression
508 | logical_or_expression OR_OP logical_xor_expression
510 $$ = new ast_expression_bin(ast_logic_or, $1, $3);
514 conditional_expression:
515 logical_or_expression
516 | logical_or_expression '?' expression ':' assignment_expression
518 $$ = new ast_expression(ast_conditional, $1, $3, $5);
522 assignment_expression:
523 conditional_expression
524 | unary_expression assignment_operator assignment_expression
526 $$ = new ast_expression($2, $1, $3, NULL);
531 '=' { $$ = ast_assign; }
532 | MUL_ASSIGN { $$ = ast_mul_assign; }
533 | DIV_ASSIGN { $$ = ast_div_assign; }
534 | MOD_ASSIGN { $$ = ast_mod_assign; }
535 | ADD_ASSIGN { $$ = ast_add_assign; }
536 | SUB_ASSIGN { $$ = ast_sub_assign; }
537 | LEFT_ASSIGN { $$ = ast_ls_assign; }
538 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
539 | AND_ASSIGN { $$ = ast_and_assign; }
540 | XOR_ASSIGN { $$ = ast_xor_assign; }
541 | OR_ASSIGN { $$ = ast_or_assign; }
545 assignment_expression
549 | expression ',' assignment_expression
551 if ($1->oper != ast_sequence) {
552 $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
553 insert_at_tail(& $$->expressions, $1);
558 insert_at_tail(& $$->expressions, $3);
563 conditional_expression
567 function_prototype ';'
571 | init_declarator_list ';'
575 | PRECISION precision_qualifier type_specifier_no_prec ';'
577 $$ = NULL; /* FINISHME */
582 function_declarator ')'
587 | function_header_with_parameters
590 function_header_with_parameters:
591 function_header parameter_declaration
594 insert_at_head(& $$->parameters,
595 (struct simple_node *) $2);
597 | function_header_with_parameters ',' parameter_declaration
600 insert_at_head(& $$->parameters,
601 (struct simple_node *) $3);
606 fully_specified_type IDENTIFIER '('
608 $$ = new ast_function();
609 $$->return_type = $1;
614 parameter_declarator:
615 type_specifier IDENTIFIER
617 $$ = new ast_parameter_declarator();
618 $$->type = new ast_fully_specified_type();
619 $$->type->specifier = $1;
622 | type_specifier IDENTIFIER '[' constant_expression ']'
624 $$ = new ast_parameter_declarator();
625 $$->type = new ast_fully_specified_type();
626 $$->type->specifier = $1;
633 parameter_declaration:
634 parameter_type_qualifier parameter_qualifier parameter_declarator
639 $$->type->qualifier = $1.q;
641 | parameter_qualifier parameter_declarator
644 $$->type->qualifier = $1.q;
646 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
650 $$ = new ast_parameter_declarator();
651 $$->type = new ast_fully_specified_type();
652 $$->type->qualifier = $1.q;
653 $$->type->specifier = $3;
655 | parameter_qualifier parameter_type_specifier
657 $$ = new ast_parameter_declarator();
658 $$->type = new ast_fully_specified_type();
659 $$->type->qualifier = $1.q;
660 $$->type->specifier = $2;
665 /* empty */ { $$.i = 0; }
666 | IN { $$.i = 0; $$.q.in = 1; }
667 | OUT { $$.i = 0; $$.q.out = 1; }
668 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
671 parameter_type_specifier:
675 init_declarator_list:
677 | init_declarator_list ',' IDENTIFIER
679 ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
682 insert_at_tail(& $$->declarations,
683 (struct simple_node *) decl);
685 | init_declarator_list ',' IDENTIFIER '[' ']'
687 ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
690 insert_at_tail(& $$->declarations,
691 (struct simple_node *) decl);
693 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
695 ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
698 insert_at_tail(& $$->declarations,
699 (struct simple_node *) decl);
701 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
703 ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
706 insert_at_tail(& $$->declarations,
707 (struct simple_node *) decl);
709 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
711 ast_declaration *decl = new ast_declaration($3, true, $5, $8);
714 insert_at_tail(& $$->declarations,
715 (struct simple_node *) decl);
717 | init_declarator_list ',' IDENTIFIER '=' initializer
719 ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
722 insert_at_tail(& $$->declarations,
723 (struct simple_node *) decl);
727 // Grammar Note: No 'enum', or 'typedef'.
731 $$ = new ast_declarator_list($1);
733 | fully_specified_type IDENTIFIER
735 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
737 $$ = new ast_declarator_list($1);
738 insert_at_tail(& $$->declarations,
739 (struct simple_node *) decl);
741 | fully_specified_type IDENTIFIER '[' ']'
743 ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
745 $$ = new ast_declarator_list($1);
746 insert_at_tail(& $$->declarations,
747 (struct simple_node *) decl);
749 | fully_specified_type IDENTIFIER '[' constant_expression ']'
751 ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
753 $$ = new ast_declarator_list($1);
754 insert_at_tail(& $$->declarations,
755 (struct simple_node *) decl);
757 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
759 ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
761 $$ = new ast_declarator_list($1);
762 insert_at_tail(& $$->declarations,
763 (struct simple_node *) decl);
765 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
767 ast_declaration *decl = new ast_declaration($2, true, $4, $7);
769 $$ = new ast_declarator_list($1);
770 insert_at_tail(& $$->declarations,
771 (struct simple_node *) decl);
773 | fully_specified_type IDENTIFIER '=' initializer
775 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
777 $$ = new ast_declarator_list($1);
778 insert_at_tail(& $$->declarations,
779 (struct simple_node *) decl);
781 | INVARIANT IDENTIFIER // Vertex only.
783 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
785 $$ = new ast_declarator_list(NULL);
786 $$->invariant = true;
788 insert_at_tail(& $$->declarations,
789 (struct simple_node *) decl);
793 fully_specified_type:
796 $$ = new ast_fully_specified_type();
799 | type_qualifier type_specifier
801 $$ = new ast_fully_specified_type();
802 $$->qualifier = $1.q;
807 interpolation_qualifier:
808 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
809 | FLAT { $$.i = 0; $$.q.flat = 1; }
810 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
813 parameter_type_qualifier:
814 CONST { $$.i = 0; $$.q.constant = 1; }
819 | interpolation_qualifier type_qualifier
823 | INVARIANT type_qualifier
831 CONST { $$.i = 0; $$.q.constant = 1; }
832 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
833 | VARYING { $$.i = 0; $$.q.varying = 1; }
834 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
835 | IN { $$.i = 0; $$.q.in = 1; }
836 | OUT { $$.i = 0; $$.q.out = 1; }
837 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
838 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
839 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
843 type_specifier_no_prec
844 | precision_qualifier type_specifier_no_prec
851 type_specifier_no_prec:
852 type_specifier_nonarray
853 | type_specifier_nonarray '[' ']'
857 $$->array_size = NULL;
859 | type_specifier_nonarray '[' constant_expression ']'
867 type_specifier_nonarray:
868 basic_type_specifier_nonarray
870 $$ = new ast_type_specifier($1);
874 $$ = new ast_type_specifier(ast_struct);
879 $$ = new ast_type_specifier(ast_type_name);
884 basic_type_specifier_nonarray:
885 VOID { $$ = ast_void; }
886 | FLOAT { $$ = ast_float; }
887 | INT { $$ = ast_int; }
888 | UINT { $$ = ast_uint; }
889 | BOOL { $$ = ast_bool; }
890 | VEC2 { $$ = ast_vec2; }
891 | VEC3 { $$ = ast_vec3; }
892 | VEC4 { $$ = ast_vec4; }
893 | BVEC2 { $$ = ast_bvec2; }
894 | BVEC3 { $$ = ast_bvec3; }
895 | BVEC4 { $$ = ast_bvec4; }
896 | IVEC2 { $$ = ast_ivec2; }
897 | IVEC3 { $$ = ast_ivec3; }
898 | IVEC4 { $$ = ast_ivec4; }
899 | UVEC2 { $$ = ast_uvec2; }
900 | UVEC3 { $$ = ast_uvec3; }
901 | UVEC4 { $$ = ast_uvec4; }
902 | MAT2 { $$ = ast_mat2; }
903 | MAT3 { $$ = ast_mat3; }
904 | MAT4 { $$ = ast_mat4; }
905 | MAT2X2 { $$ = ast_mat2; }
906 | MAT2X3 { $$ = ast_mat2x3; }
907 | MAT2X4 { $$ = ast_mat2x4; }
908 | MAT3X2 { $$ = ast_mat3x2; }
909 | MAT3X3 { $$ = ast_mat3; }
910 | MAT3X4 { $$ = ast_mat3x4; }
911 | MAT4X2 { $$ = ast_mat4x2; }
912 | MAT4X3 { $$ = ast_mat4x3; }
913 | MAT4X4 { $$ = ast_mat4; }
914 | SAMPLER1D { $$ = ast_sampler1d; }
915 | SAMPLER2D { $$ = ast_sampler2d; }
916 | SAMPLER3D { $$ = ast_sampler3d; }
917 | SAMPLERCUBE { $$ = ast_samplercube; }
918 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
919 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
920 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
921 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
922 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
923 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
924 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
925 | ISAMPLER1D { $$ = ast_isampler1d; }
926 | ISAMPLER2D { $$ = ast_isampler2d; }
927 | ISAMPLER3D { $$ = ast_isampler3d; }
928 | ISAMPLERCUBE { $$ = ast_isamplercube; }
929 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
930 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
931 | USAMPLER1D { $$ = ast_usampler1d; }
932 | USAMPLER2D { $$ = ast_usampler2d; }
933 | USAMPLER3D { $$ = ast_usampler3d; }
934 | USAMPLERCUBE { $$ = ast_usamplercube; }
935 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
936 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
940 HIGH_PRECISION { $$ = ast_precision_high; }
941 | MEDIUM_PRECISION { $$ = ast_precision_medium; }
942 | LOW_PRECISION { $$ = ast_precision_low; }
946 STRUCT IDENTIFIER '{' struct_declaration_list '}'
948 $$ = new ast_struct_specifier($2, $4);
950 _mesa_symbol_table_add_symbol(state->symbols, 0, $2, $$);
952 | STRUCT '{' struct_declaration_list '}'
954 $$ = new ast_struct_specifier(NULL, $3);
958 struct_declaration_list:
961 $$ = (struct ast_node *) $1;
963 | struct_declaration_list struct_declaration
965 $$ = (struct ast_node *) $1;
966 insert_at_tail((struct simple_node *) $$,
967 (struct simple_node *) $2);
972 type_specifier struct_declarator_list ';'
974 ast_fully_specified_type *type = new ast_fully_specified_type();
976 type->specifier = $1;
977 $$ = new ast_declarator_list(type);
979 insert_at_tail((struct simple_node *) $2,
984 struct_declarator_list:
986 | struct_declarator_list ',' struct_declarator
989 insert_at_tail((struct simple_node *) $$,
990 (struct simple_node *) $3);
997 $$ = new ast_declaration($1, false, NULL, NULL);
999 | IDENTIFIER '[' constant_expression ']'
1001 $$ = new ast_declaration($1, true, $3, NULL);
1006 assignment_expression
1009 declaration_statement:
1013 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1017 | statement_unmatched
1021 compound_statement { $$ = (struct ast_node *) $1; }
1025 statement_unmatched:
1026 selection_statement_unmatched
1030 declaration_statement
1031 | expression_statement
1032 | selection_statement_matched
1033 | switch_statement { $$ = NULL; }
1034 | case_label { $$ = NULL; }
1035 | iteration_statement
1042 $$ = new ast_compound_statement(true, NULL);
1044 | '{' statement_list '}'
1046 $$ = new ast_compound_statement(true, $2);
1050 statement_no_new_scope:
1051 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1055 compound_statement_no_new_scope:
1058 $$ = new ast_compound_statement(false, NULL);
1060 | '{' statement_list '}'
1062 $$ = new ast_compound_statement(false, $2);
1070 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1075 make_empty_list((struct simple_node *) $$);
1077 | statement_list statement
1080 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1084 insert_at_tail((struct simple_node *) $$,
1085 (struct simple_node *) $2);
1089 expression_statement:
1092 $$ = new ast_expression_statement(NULL);
1096 $$ = new ast_expression_statement($1);
1100 selection_statement_matched:
1101 IF '(' expression ')' statement_matched ELSE statement_matched
1103 $$ = new ast_selection_statement($3, $5, $7);
1107 selection_statement_unmatched:
1108 IF '(' expression ')' statement_matched
1110 $$ = new ast_selection_statement($3, $5, NULL);
1112 | IF '(' expression ')' statement_unmatched
1114 $$ = new ast_selection_statement($3, $5, NULL);
1116 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1118 $$ = new ast_selection_statement($3, $5, $7);
1125 $$ = (struct ast_node *) $1;
1127 | fully_specified_type IDENTIFIER '=' initializer
1129 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
1130 ast_declarator_list *declarator = new ast_declarator_list($1);
1132 insert_at_tail(& declarator->declarations,
1133 (struct simple_node *) decl);
1140 SWITCH '(' expression ')' compound_statement
1148 iteration_statement:
1149 WHILE '(' condition ')' statement_no_new_scope
1151 $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
1152 NULL, $3, NULL, $5);
1154 | DO statement WHILE '(' expression ')' ';'
1156 $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
1157 NULL, $5, NULL, $2);
1159 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1161 $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
1162 $3, $4.cond, $4.rest, $6);
1167 expression_statement
1168 | declaration_statement
1185 | conditionopt ';' expression
1192 // Grammar Note: No 'goto'. Gotos are not supported.
1196 $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1200 $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
1204 $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
1206 | RETURN expression ';'
1208 $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
1210 | DISCARD ';' // Fragment shader only.
1212 $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1216 external_declaration:
1217 function_definition { $$ = $1; }
1218 | declaration { $$ = $1; }
1221 function_definition:
1222 function_prototype compound_statement_no_new_scope
1224 $$ = new ast_function_definition();