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_function_expression($1);
348 $$ = (struct ast_node *) $1;
352 $$ = new ast_expression($1);
356 $$ = new ast_expression($1);
360 // Grammar Note: No traditional style type casts.
363 | INC_OP unary_expression
365 $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
367 | DEC_OP unary_expression
369 $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
371 | unary_operator unary_expression
373 $$ = new ast_expression($1, $2, NULL, NULL);
377 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
379 '+' { $$ = ast_plus; }
380 | '-' { $$ = ast_neg; }
381 | '!' { $$ = ast_logic_not; }
382 | '~' { $$ = ast_bit_not; }
385 multiplicative_expression:
387 | multiplicative_expression '*' unary_expression
389 $$ = new ast_expression_bin(ast_mul, $1, $3);
391 | multiplicative_expression '/' unary_expression
393 $$ = new ast_expression_bin(ast_div, $1, $3);
395 | multiplicative_expression '%' unary_expression
397 $$ = new ast_expression_bin(ast_mod, $1, $3);
402 multiplicative_expression
403 | additive_expression '+' multiplicative_expression
405 $$ = new ast_expression_bin(ast_add, $1, $3);
407 | additive_expression '-' multiplicative_expression
409 $$ = new ast_expression_bin(ast_sub, $1, $3);
415 | shift_expression LEFT_OP additive_expression
417 $$ = new ast_expression_bin(ast_lshift, $1, $3);
419 | shift_expression RIGHT_OP additive_expression
421 $$ = new ast_expression_bin(ast_rshift, $1, $3);
425 relational_expression:
427 | relational_expression '<' shift_expression
429 $$ = new ast_expression_bin(ast_less, $1, $3);
431 | relational_expression '>' shift_expression
433 $$ = new ast_expression_bin(ast_greater, $1, $3);
435 | relational_expression LE_OP shift_expression
437 $$ = new ast_expression_bin(ast_lequal, $1, $3);
439 | relational_expression GE_OP shift_expression
441 $$ = new ast_expression_bin(ast_gequal, $1, $3);
446 relational_expression
447 | equality_expression EQ_OP relational_expression
449 $$ = new ast_expression_bin(ast_equal, $1, $3);
451 | equality_expression NE_OP relational_expression
453 $$ = new ast_expression_bin(ast_nequal, $1, $3);
459 | and_expression '&' equality_expression
461 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
465 exclusive_or_expression:
467 | exclusive_or_expression '^' and_expression
469 $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
473 inclusive_or_expression:
474 exclusive_or_expression
475 | inclusive_or_expression '|' exclusive_or_expression
477 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
481 logical_and_expression:
482 inclusive_or_expression
483 | logical_and_expression AND_OP inclusive_or_expression
485 $$ = new ast_expression_bin(ast_logic_and, $1, $3);
489 logical_xor_expression:
490 logical_and_expression
491 | logical_xor_expression XOR_OP logical_and_expression
493 $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
497 logical_or_expression:
498 logical_xor_expression
499 | logical_or_expression OR_OP logical_xor_expression
501 $$ = new ast_expression_bin(ast_logic_or, $1, $3);
505 conditional_expression:
506 logical_or_expression
507 | logical_or_expression '?' expression ':' assignment_expression
509 $$ = new ast_expression(ast_conditional, $1, $3, $5);
513 assignment_expression:
514 conditional_expression
515 | unary_expression assignment_operator assignment_expression
517 $$ = new ast_expression($2, $1, $3, NULL);
522 '=' { $$ = ast_assign; }
523 | MUL_ASSIGN { $$ = ast_mul_assign; }
524 | DIV_ASSIGN { $$ = ast_div_assign; }
525 | MOD_ASSIGN { $$ = ast_mod_assign; }
526 | ADD_ASSIGN { $$ = ast_add_assign; }
527 | SUB_ASSIGN { $$ = ast_sub_assign; }
528 | LEFT_ASSIGN { $$ = ast_ls_assign; }
529 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
530 | AND_ASSIGN { $$ = ast_and_assign; }
531 | XOR_ASSIGN { $$ = ast_xor_assign; }
532 | OR_ASSIGN { $$ = ast_or_assign; }
536 assignment_expression
540 | expression ',' assignment_expression
542 if ($1->oper != ast_sequence) {
543 $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
544 insert_at_tail(& $$->expressions, $1);
549 insert_at_tail(& $$->expressions, $3);
554 conditional_expression
558 function_prototype ';'
562 | init_declarator_list ';'
566 | PRECISION precision_qualifier type_specifier_no_prec ';'
568 $$ = NULL; /* FINISHME */
573 function_declarator ')'
578 | function_header_with_parameters
581 function_header_with_parameters:
582 function_header parameter_declaration
585 insert_at_head(& $$->parameters,
586 (struct simple_node *) $2);
588 | function_header_with_parameters ',' parameter_declaration
591 insert_at_head(& $$->parameters,
592 (struct simple_node *) $3);
597 fully_specified_type IDENTIFIER '('
599 $$ = new ast_function();
600 $$->return_type = $1;
605 parameter_declarator:
606 type_specifier IDENTIFIER
608 $$ = new ast_parameter_declarator();
609 $$->type = new ast_fully_specified_type();
610 $$->type->specifier = $1;
613 | type_specifier IDENTIFIER '[' constant_expression ']'
615 $$ = new ast_parameter_declarator();
616 $$->type = new ast_fully_specified_type();
617 $$->type->specifier = $1;
624 parameter_declaration:
625 parameter_type_qualifier parameter_qualifier parameter_declarator
630 $$->type->qualifier = $1.q;
632 | parameter_qualifier parameter_declarator
635 $$->type->qualifier = $1.q;
637 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
641 $$ = new ast_parameter_declarator();
642 $$->type = new ast_fully_specified_type();
643 $$->type->qualifier = $1.q;
644 $$->type->specifier = $3;
646 | parameter_qualifier parameter_type_specifier
648 $$ = new ast_parameter_declarator();
649 $$->type = new ast_fully_specified_type();
650 $$->type->qualifier = $1.q;
651 $$->type->specifier = $2;
656 /* empty */ { $$.i = 0; }
657 | IN { $$.i = 0; $$.q.in = 1; }
658 | OUT { $$.i = 0; $$.q.out = 1; }
659 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
662 parameter_type_specifier:
666 init_declarator_list:
668 | init_declarator_list ',' IDENTIFIER
670 ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
673 insert_at_tail(& $$->declarations,
674 (struct simple_node *) decl);
676 | init_declarator_list ',' IDENTIFIER '[' ']'
678 ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
681 insert_at_tail(& $$->declarations,
682 (struct simple_node *) decl);
684 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
686 ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
689 insert_at_tail(& $$->declarations,
690 (struct simple_node *) decl);
692 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
694 ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
697 insert_at_tail(& $$->declarations,
698 (struct simple_node *) decl);
700 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
702 ast_declaration *decl = new ast_declaration($3, true, $5, $8);
705 insert_at_tail(& $$->declarations,
706 (struct simple_node *) decl);
708 | init_declarator_list ',' IDENTIFIER '=' initializer
710 ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
713 insert_at_tail(& $$->declarations,
714 (struct simple_node *) decl);
718 // Grammar Note: No 'enum', or 'typedef'.
722 $$ = new ast_declarator_list($1);
724 | fully_specified_type IDENTIFIER
726 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
728 $$ = new ast_declarator_list($1);
729 insert_at_tail(& $$->declarations,
730 (struct simple_node *) decl);
732 | fully_specified_type IDENTIFIER '[' ']'
734 ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
736 $$ = new ast_declarator_list($1);
737 insert_at_tail(& $$->declarations,
738 (struct simple_node *) decl);
740 | fully_specified_type IDENTIFIER '[' constant_expression ']'
742 ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
744 $$ = new ast_declarator_list($1);
745 insert_at_tail(& $$->declarations,
746 (struct simple_node *) decl);
748 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
750 ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
752 $$ = new ast_declarator_list($1);
753 insert_at_tail(& $$->declarations,
754 (struct simple_node *) decl);
756 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
758 ast_declaration *decl = new ast_declaration($2, true, $4, $7);
760 $$ = new ast_declarator_list($1);
761 insert_at_tail(& $$->declarations,
762 (struct simple_node *) decl);
764 | fully_specified_type IDENTIFIER '=' initializer
766 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
768 $$ = new ast_declarator_list($1);
769 insert_at_tail(& $$->declarations,
770 (struct simple_node *) decl);
772 | INVARIANT IDENTIFIER // Vertex only.
774 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
776 $$ = new ast_declarator_list(NULL);
777 $$->invariant = true;
779 insert_at_tail(& $$->declarations,
780 (struct simple_node *) decl);
784 fully_specified_type:
787 $$ = new ast_fully_specified_type();
790 | type_qualifier type_specifier
792 $$ = new ast_fully_specified_type();
793 $$->qualifier = $1.q;
798 interpolation_qualifier:
799 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
800 | FLAT { $$.i = 0; $$.q.flat = 1; }
801 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
804 parameter_type_qualifier:
805 CONST { $$.i = 0; $$.q.constant = 1; }
810 | interpolation_qualifier type_qualifier
814 | INVARIANT type_qualifier
822 CONST { $$.i = 0; $$.q.constant = 1; }
823 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
824 | VARYING { $$.i = 0; $$.q.varying = 1; }
825 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
826 | IN { $$.i = 0; $$.q.in = 1; }
827 | OUT { $$.i = 0; $$.q.out = 1; }
828 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
829 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
830 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
834 type_specifier_no_prec
835 | precision_qualifier type_specifier_no_prec
842 type_specifier_no_prec:
843 type_specifier_nonarray
844 | type_specifier_nonarray '[' ']'
848 $$->array_size = NULL;
850 | type_specifier_nonarray '[' constant_expression ']'
858 type_specifier_nonarray:
859 basic_type_specifier_nonarray
861 $$ = new ast_type_specifier($1);
865 $$ = new ast_type_specifier(ast_struct);
870 $$ = new ast_type_specifier(ast_type_name);
875 basic_type_specifier_nonarray:
876 VOID { $$ = ast_void; }
877 | FLOAT { $$ = ast_float; }
878 | INT { $$ = ast_int; }
879 | UINT { $$ = ast_uint; }
880 | BOOL { $$ = ast_bool; }
881 | VEC2 { $$ = ast_vec2; }
882 | VEC3 { $$ = ast_vec3; }
883 | VEC4 { $$ = ast_vec4; }
884 | BVEC2 { $$ = ast_bvec2; }
885 | BVEC3 { $$ = ast_bvec3; }
886 | BVEC4 { $$ = ast_bvec4; }
887 | IVEC2 { $$ = ast_ivec2; }
888 | IVEC3 { $$ = ast_ivec3; }
889 | IVEC4 { $$ = ast_ivec4; }
890 | UVEC2 { $$ = ast_uvec2; }
891 | UVEC3 { $$ = ast_uvec3; }
892 | UVEC4 { $$ = ast_uvec4; }
893 | MAT2 { $$ = ast_mat2; }
894 | MAT3 { $$ = ast_mat3; }
895 | MAT4 { $$ = ast_mat4; }
896 | MAT2X2 { $$ = ast_mat2; }
897 | MAT2X3 { $$ = ast_mat2x3; }
898 | MAT2X4 { $$ = ast_mat2x4; }
899 | MAT3X2 { $$ = ast_mat3x2; }
900 | MAT3X3 { $$ = ast_mat3; }
901 | MAT3X4 { $$ = ast_mat3x4; }
902 | MAT4X2 { $$ = ast_mat4x2; }
903 | MAT4X3 { $$ = ast_mat4x3; }
904 | MAT4X4 { $$ = ast_mat4; }
905 | SAMPLER1D { $$ = ast_sampler1d; }
906 | SAMPLER2D { $$ = ast_sampler2d; }
907 | SAMPLER3D { $$ = ast_sampler3d; }
908 | SAMPLERCUBE { $$ = ast_samplercube; }
909 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
910 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
911 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
912 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
913 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
914 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
915 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
916 | ISAMPLER1D { $$ = ast_isampler1d; }
917 | ISAMPLER2D { $$ = ast_isampler2d; }
918 | ISAMPLER3D { $$ = ast_isampler3d; }
919 | ISAMPLERCUBE { $$ = ast_isamplercube; }
920 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
921 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
922 | USAMPLER1D { $$ = ast_usampler1d; }
923 | USAMPLER2D { $$ = ast_usampler2d; }
924 | USAMPLER3D { $$ = ast_usampler3d; }
925 | USAMPLERCUBE { $$ = ast_usamplercube; }
926 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
927 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
931 HIGH_PRECISION { $$ = ast_precision_high; }
932 | MEDIUM_PRECISION { $$ = ast_precision_medium; }
933 | LOW_PRECISION { $$ = ast_precision_low; }
937 STRUCT IDENTIFIER '{' struct_declaration_list '}'
939 $$ = new ast_struct_specifier($2, $4);
941 _mesa_symbol_table_add_symbol(state->symbols, 0, $2, $$);
943 | STRUCT '{' struct_declaration_list '}'
945 $$ = new ast_struct_specifier(NULL, $3);
949 struct_declaration_list:
952 $$ = (struct ast_node *) $1;
954 | struct_declaration_list struct_declaration
956 $$ = (struct ast_node *) $1;
957 insert_at_tail((struct simple_node *) $$,
958 (struct simple_node *) $2);
963 type_specifier struct_declarator_list ';'
965 ast_fully_specified_type *type = new ast_fully_specified_type();
967 type->specifier = $1;
968 $$ = new ast_declarator_list(type);
970 insert_at_tail((struct simple_node *) $2,
975 struct_declarator_list:
977 | struct_declarator_list ',' struct_declarator
980 insert_at_tail((struct simple_node *) $$,
981 (struct simple_node *) $3);
988 $$ = new ast_declaration($1, false, NULL, NULL);
990 | IDENTIFIER '[' constant_expression ']'
992 $$ = new ast_declaration($1, true, $3, NULL);
997 assignment_expression
1000 declaration_statement:
1004 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1008 | statement_unmatched
1012 compound_statement { $$ = (struct ast_node *) $1; }
1016 statement_unmatched:
1017 selection_statement_unmatched
1021 declaration_statement
1022 | expression_statement
1023 | selection_statement_matched
1024 | switch_statement { $$ = NULL; }
1025 | case_label { $$ = NULL; }
1026 | iteration_statement
1033 $$ = new ast_compound_statement(true, NULL);
1035 | '{' statement_list '}'
1037 $$ = new ast_compound_statement(true, $2);
1041 statement_no_new_scope:
1042 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1046 compound_statement_no_new_scope:
1049 $$ = new ast_compound_statement(false, NULL);
1051 | '{' statement_list '}'
1053 $$ = new ast_compound_statement(false, $2);
1061 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1066 make_empty_list((struct simple_node *) $$);
1068 | statement_list statement
1071 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1075 insert_at_tail((struct simple_node *) $$,
1076 (struct simple_node *) $2);
1080 expression_statement:
1083 $$ = new ast_expression_statement(NULL);
1087 $$ = new ast_expression_statement($1);
1091 selection_statement_matched:
1092 IF '(' expression ')' statement_matched ELSE statement_matched
1094 $$ = new ast_selection_statement($3, $5, $7);
1098 selection_statement_unmatched:
1099 IF '(' expression ')' statement_matched
1101 $$ = new ast_selection_statement($3, $5, NULL);
1103 | IF '(' expression ')' statement_unmatched
1105 $$ = new ast_selection_statement($3, $5, NULL);
1107 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1109 $$ = new ast_selection_statement($3, $5, $7);
1116 $$ = (struct ast_node *) $1;
1118 | fully_specified_type IDENTIFIER '=' initializer
1120 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
1121 ast_declarator_list *declarator = new ast_declarator_list($1);
1123 insert_at_tail(& declarator->declarations,
1124 (struct simple_node *) decl);
1131 SWITCH '(' expression ')' compound_statement
1139 iteration_statement:
1140 WHILE '(' condition ')' statement_no_new_scope
1142 $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
1143 NULL, $3, NULL, $5);
1145 | DO statement WHILE '(' expression ')' ';'
1147 $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
1148 NULL, $5, NULL, $2);
1150 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1152 $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
1153 $3, $4.cond, $4.rest, $6);
1158 expression_statement
1159 | declaration_statement
1176 | conditionopt ';' expression
1183 // Grammar Note: No 'goto'. Gotos are not supported.
1187 $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1191 $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
1195 $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
1197 | RETURN expression ';'
1199 $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
1201 | DISCARD ';' // Fragment shader only.
1203 $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1207 external_declaration:
1208 function_definition { $$ = $1; }
1209 | declaration { $$ = $1; }
1212 function_definition:
1213 function_prototype compound_statement_no_new_scope
1215 $$ = new ast_function_definition();