-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglslparser.yp
1382 lines (1221 loc) · 31.7 KB
/
glslparser.yp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##
## glslparser.yp - grammar for OpenGL Shading Language and glue extensions
##
%{
use Parse::Lex;
##
## debug message handlers
##
sub _Dbug
{
print @_;
}
sub _Info
{
print @_;
}
sub _Stat
{
print @_;
}
sub _Warn
{
print STDERR @_;
}
sub _Fail
{
print STDERR @_;
}
##
## _Mark - mark a line and offset in the source text
##
sub _Mark($$$)
{
my $sp = shift;
my $lexeme = shift;
my $startend = shift;
$sp->YYData->{MARK_OFFSET} = $lexeme->{POS}->[$startend];
$sp->YYData->{MARK_LINE} = $lexeme->{LINE}->[$startend];
#print "Mark line ", $sp->YYData->{MARK_LINE}, " @", $sp->YYData->{MARK_OFFSET}, "\n";
}
##
## _Yank - yank text between last _Mark and current position
##
sub _Yank($$$)
{
my $sp = shift;
my $lexeme = shift;
my $startend = shift;
my $so = $sp->YYData->{MARK_OFFSET};
my $eo = $lexeme->{POS}->[$startend];
my $len = $eo - $so;
my $line = $sp->YYData->{MARK_LINE} - 1;
my $file = $sp->YYData->{FILE};
my $text = substr( $sp->YYData->{LINES}, $so, $len );
_Mark( $sp, $lexeme, $startend );
return '' if ($text =~ /^[\S\n]*$/) ;
return "#line $line \"$file\"\n$text\n";
}
##
## _MakeString - quote a C++-safe string
##
sub _MakeString($)
{
my $s = shift;
$s =~ s/\"/\\\"/g;
$s =~ s/\n/\\n\"\n\"/g;
return $s;
}
##
## _MergeLexemes - merge lexemes from the grammar productions
##
sub _MergeLexemes(@)
{
my (@prods) = (@_);
return $prods[1] if ($#prods == 1) ;
my $lexeme =
{
'TEXT' => $_[0]->YYName(),
'CHILD' => [],
'POS' => [ $prods[1]->{POS}->[0], $prods[$#prods]->{POS}->[1] ],
'LINE' => [ $prods[1]->{LINE}->[0], $prods[$#prods]->{LINE}->[1] ]
};
for (my $i = 1; $i <= $#prods; ++$i)
{
push( @{$lexeme->{CHILD}}, $prods[$i] );
}
return $lexeme;
}
##
## _ParseDecl - parse part of a declaration statement
##
sub _ParseDecl($$)
{
my $sp = shift;
my $lexeme = shift;
my $name = undef;
my $qt = undef;
my $asize = undef;
# HACK HACK HACK only handling the simplest cases for now...
if ($lexeme->{TEXT} =~ /^ID(_(UN)?SIZED_ARRAY)?/)
{
my $t = $lexeme->{CHILD}->[0];
if ($t->{TEXT} eq 'QUAL_TYPE_SPEC')
{
$name = $lexeme->{CHILD}->[1]->{TEXT};
$qt = { 'QUAL' => $t->{CHILD}->[0]->{TEXT}, 'TYPE' => $t->{CHILD}->[1]->{TEXT} };
if ($lexeme->{TEXT} =~ /^ID_UNSIZED_ARRAY/)
{
$asize = 0;
}
elsif ($lexeme->{TEXT} =~ /^ID_SIZED_ARRAY/)
{
$asize = $lexeme->{CHILD}->[3]->{TEXT};
#print "asize["; PrintTree( $lexeme->{CHILD}->[4], '' ); print "]\n";
}
}
}
elsif ($lexeme->{TEXT} =~ /^INIT_LIST_ID/)
{
$name = $lexeme->{CHILD}->[2]->{TEXT};
$qt = _ParseDecl( $sp, $lexeme->{CHILD}->[0] );
if ($lexeme->{TEXT} =~ /^INIT_LIST_ID_UNSIZED_ARRAY/)
{
$asize = 0;
}
elsif ($lexeme->{TEXT} =~ /^INIT_LIST_ID_SIZED_ARRAY/)
{
$asize = $lexeme->{CHILD}->[4]->{TEXT};
#print "asize["; PrintTree( $lexeme->{CHILD}->[4], '' ); print "]\n";
}
}
else
{
print "Unhandled decl:\n"; PrintTree( $lexeme, '' ); print "\n\n";
}
if (defined( $qt ))
{
my $scope = $sp->YYData->{DECL_SCOPE};
$sp->YYData->{DECLS}->{$scope}->{$name} =
{
'QUAL' => $qt->{QUAL},
'TYPE' => $qt->{TYPE},
'ASIZE' => $asize
};
#print "decl( $qt->{QUAL}, $qt->{TYPE}, $asize, $name )\n";
}
return( $qt );
}
##
## _CollectDecls - examine a declaration and track in/varying/uniform types
##
sub _CollectDecls($$)
{
my $sp = shift;
my $lexeme = shift;
my $scope = $sp->YYData->{DECL_SCOPE};
if ($lexeme->{TEXT} eq 'INIT')
{
$lexeme = $lexeme->{CHILD}->[0];
_ParseDecl( $sp, $lexeme );
#print "Decl:\n"; PrintTree( $lexeme, '' ); print "\n\n";
}
else
{
#print "Unhandled decl:\n"; PrintTree( $lexeme, '' ); print "\n\n";
}
}
%}
%defaultaction { &_MergeLexemes; }
%%
##
## the spec is just a set of statements
##
effects: effects_opt 'EOI' { $_[0]->YYData->{TREE} = $_[1]; $_[0]->YYAccept(); } ;
effects_opt:
/* empty */
| effect_translation_unit
;
variable_identifier:
IDENTIFIER
;
primary_expression:
variable_identifier
| INTCONSTANT
| UINTCONSTANT
| FLOATCONSTANT
| BOOLCONSTANT
| LEFT_PAREN expression RIGHT_PAREN
;
postfix_expression:
primary_expression
| postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET
| function_call
| postfix_expression DOT field_selection
| postfix_expression INC_OP
| postfix_expression DEC_OP
;
integer_expression:
expression
;
function_call:
function_call_or_method
;
function_call_or_method:
function_call_generic
| postfix_expression DOT function_call_generic
;
function_call_generic:
function_call_header_with_parameters RIGHT_PAREN
| function_call_header_no_parameters RIGHT_PAREN
;
function_call_header_no_parameters:
function_call_header VOID
| function_call_header
;
function_call_header_with_parameters:
function_call_header assignment_expression
| function_call_header_with_parameters COMMA assignment_expression
;
function_call_header:
function_identifier LEFT_PAREN
;
# Grammar Note: Constructors look like functions, but lexical analysis recognized most of them as
# keywords. They are now recognized through “type_specifier”.
function_identifier:
type_specifier
| IDENTIFIER
| field_selection
;
field_selection:
IDENTIFIER
;
unary_expression:
postfix_expression
| INC_OP unary_expression
| DEC_OP unary_expression
| unary_operator unary_expression
;
# Grammar Note: No traditional style type casts.
unary_operator:
PLUS
| DASH
| BANG
| TILDE
;
# Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
multiplicative_expression:
unary_expression
| multiplicative_expression STAR unary_expression
| multiplicative_expression SLASH unary_expression
| multiplicative_expression PERCENT unary_expression
;
additive_expression:
multiplicative_expression
| additive_expression PLUS multiplicative_expression
| additive_expression DASH multiplicative_expression
;
shift_expression:
additive_expression
| shift_expression LEFT_OP additive_expression
| shift_expression RIGHT_OP additive_expression
;
relational_expression:
shift_expression
| relational_expression LEFT_ANGLE shift_expression
| relational_expression RIGHT_ANGLE shift_expression
| relational_expression LE_OP shift_expression
| relational_expression GE_OP shift_expression
;
equality_expression:
relational_expression
| equality_expression EQ_OP relational_expression
| equality_expression NE_OP relational_expression
;
and_expression:
equality_expression
| and_expression AMPERSAND equality_expression
;
exclusive_or_expression:
and_expression
| exclusive_or_expression CARET and_expression
;
inclusive_or_expression:
exclusive_or_expression
| inclusive_or_expression VERTICAL_BAR exclusive_or_expression
;
logical_and_expression:
inclusive_or_expression
| logical_and_expression AND_OP inclusive_or_expression
;
logical_xor_expression:
logical_and_expression
| logical_xor_expression XOR_OP logical_and_expression
;
logical_or_expression:
logical_xor_expression
| logical_or_expression OR_OP logical_xor_expression
;
conditional_expression:
logical_or_expression
| logical_or_expression QUESTION expression COLON assignment_expression
;
assignment_expression:
conditional_expression
| unary_expression assignment_operator assignment_expression
;
assignment_operator:
EQUAL
| MUL_ASSIGN
| DIV_ASSIGN
| MOD_ASSIGN
| ADD_ASSIGN
| SUB_ASSIGN
| LEFT_ASSIGN
| RIGHT_ASSIGN
| AND_ASSIGN
| XOR_ASSIGN
| OR_ASSIGN
;
expression:
assignment_expression
| expression COMMA assignment_expression
;
constant_expression:
conditional_expression
;
declaration:
%name FUNC function_prototype SEMICOLON
| %name INIT init_declarator_list SEMICOLON
| %name PREC PRECISION precision_qualifier type_specifier_no_prec SEMICOLON
| %name ANON_IFACE type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE SEMICOLON
| %name IFACE type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER SEMICOLON
| %name ANON_IFACE_UNSIZED_ARRAY type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER LEFT_BRACKET RIGHT_BRACKET SEMICOLON
| %name ANON_IFACE_SIZED_ARRAY type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET SEMICOLON
| %name DECL type_qualifier SEMICOLON
;
function_prototype:
function_declarator RIGHT_PAREN
;
function_declarator:
function_header
| function_header_with_parameters
;
function_header_with_parameters:
function_header parameter_declaration
| function_header_with_parameters COMMA parameter_declaration
;
function_header:
fully_specified_type IDENTIFIER LEFT_PAREN
;
parameter_declarator:
type_specifier IDENTIFIER
| type_specifier IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET
;
parameter_declaration:
parameter_type_qualifier parameter_qualifier parameter_declarator
| parameter_type_qualifier parameter_qualifier parameter_type_specifier
| parameter_qualifier parameter_declarator
| parameter_qualifier parameter_type_specifier
;
parameter_qualifier:
/* empty */
| IN
| OUT
| INOUT
;
parameter_type_specifier:
type_specifier
;
init_declarator_list:
single_declaration
| %name INIT_LIST_ID init_declarator_list COMMA IDENTIFIER
| %name INIT_LIST_ID_UNSIZED_ARRAY init_declarator_list COMMA IDENTIFIER LEFT_BRACKET RIGHT_BRACKET
| %name INIT_LIST_ID_SIZED_ARRAY init_declarator_list COMMA IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET
| %name INIT_LIST_ID_UNSIZED_ARRAY_INIT init_declarator_list COMMA IDENTIFIER LEFT_BRACKET RIGHT_BRACKET EQUAL initializer
| %name INIT_LIST_ID_SIZED_ARRAY_INIT init_declarator_list COMMA IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET EQUAL initializer
| %name INIT_LIST_ID_INIT init_declarator_list COMMA IDENTIFIER EQUAL initializer
;
single_declaration:
%name TYPE fully_specified_type
| %name ID fully_specified_type IDENTIFIER
| %name ID_UNSIZED_ARRAY fully_specified_type IDENTIFIER LEFT_BRACKET RIGHT_BRACKET
| %name ID_SIZED_ARRAY fully_specified_type IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET
| %name ID_UNSIZED_ARRAY_INIT fully_specified_type IDENTIFIER LEFT_BRACKET RIGHT_BRACKET EQUAL initializer
| %name ID_SIZED_ARRAY_INIT fully_specified_type IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET EQUAL initializer
| %name ID_INIT fully_specified_type IDENTIFIER EQUAL initializer
| %name INVARIANT_ID INVARIANT IDENTIFIER
;
# Grammar Note: No 'enum', or 'typedef'.
fully_specified_type:
%name TYPE_SPEC type_specifier
| %name QUAL_TYPE_SPEC type_qualifier type_specifier
;
invariant_qualifier:
%name INVARIANT INVARIANT
;
interpolation_qualifier:
SMOOTH
| FLAT
| NOPERSPECTIVE
;
layout_qualifier:
LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN
;
layout_qualifier_id_list:
layout_qualifier_id
| layout_qualifier_id_list COMMA layout_qualifier_id
;
layout_qualifier_id:
IDENTIFIER
| IDENTIFIER EQUAL INTCONSTANT
;
parameter_type_qualifier:
CONST
;
type_qualifier:
%name QUAL_STORAGE storage_qualifier
| %name QUAL_LAYOUT layout_qualifier
| %name QUAL_LAYOUT_STORAGE layout_qualifier storage_qualifier
| %name QUAL_INTERP_STORAGE interpolation_qualifier storage_qualifier
| %name QUAL_INTERP interpolation_qualifier
| %name QUAL_INVARIANT_STORAGE invariant_qualifier storage_qualifier
| %name QUAL_INVARIANT_INTERP_STORAGE invariant_qualifier interpolation_qualifier storage_qualifier
| %name QUAL_INVARIANT invariant
;
storage_qualifier:
CONST
| ATTRIBUTE
| VARYING
| CENTROID VARYING
| IN
| OUT
| CENTROID IN
| CENTROID OUT
| UNIFORM
;
type_specifier:
type_specifier_no_prec
| precision_qualifier type_specifier_no_prec
;
type_specifier_no_prec:
%name TYPE_SPEC type_specifier_nonarray
| %name TYPE_SPEC_UNSIZED_ARRAY type_specifier_nonarray LEFT_BRACKET RIGHT_BRACKET
| %name TYPE_SPEC_SIZED_ARRAY type_specifier_nonarray LEFT_BRACKET constant_expression RIGHT_BRACKET
;
type_specifier_nonarray:
VOID
| FLOAT
| INT
| UINT
| BOOL
| VEC2
| VEC3
| VEC4
| BVEC2
| BVEC3
| BVEC4
| IVEC2
| IVEC3
| IVEC4
| UVEC2
| UVEC3
| UVEC4
| MAT2
| MAT3
| MAT4
| MAT2X2
| MAT2X3
| MAT2X4
| MAT3X2
| MAT3X3
| MAT3X4
| MAT4X2
| MAT4X3
| MAT4X4
| SAMPLER1D
| SAMPLER2D
| SAMPLER3D
| SAMPLERCUBE
| SAMPLER1DSHADOW
| SAMPLER2DSHADOW
| SAMPLERCUBESHADOW
| SAMPLER1DARRAY
| SAMPLER2DARRAY
| SAMPLER1DARRAYSHADOW
| SAMPLER2DARRAYSHADOW
| ISAMPLER1D
| ISAMPLER2D
| ISAMPLER3D
| ISAMPLERCUBE
| ISAMPLER1DARRAY
| ISAMPLER2DARRAY
| USAMPLER1D
| USAMPLER2D
| USAMPLER3D
| USAMPLERCUBE
| USAMPLER1DARRAY
| USAMPLER2DARRAY
| SAMPLER2DRECT
| SAMPLER2DRECTSHADOW
| ISAMPLER2DRECT
| USAMPLER2DRECT
| SAMPLERBUFFER
| ISAMPLERBUFFER
| USAMPLERBUFFER
| SAMPLER2DMS
| ISAMPLER2DMS
| USAMPLER2DMS
| SAMPLER2DMSARRAY
| ISAMPLER2DMSARRAY
| USAMPLER2DMSARRAY
| struct_specifier
| type_name
;
# TYPE_NAME should perform a semantic check on the validity of IDENTIFIER
type_name:
IDENTIFIER
;
precision_qualifier:
HIGH_PRECISION
| MEDIUM_PRECISION
| LOW_PRECISION
;
struct_specifier:
STRUCT IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE
| STRUCT LEFT_BRACE struct_declaration_list RIGHT_BRACE
;
struct_declaration_list:
struct_declaration
| struct_declaration_list struct_declaration
;
struct_declaration:
type_specifier struct_declarator_list SEMICOLON
| type_qualifier type_specifier struct_declarator_list SEMICOLON
;
struct_declarator_list:
struct_declarator
| struct_declarator_list COMMA struct_declarator
;
struct_declarator:
IDENTIFIER
| IDENTIFIER LEFT_BRACKET RIGHT_BRACKET
| IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET
;
initializer:
assignment_expression
;
declaration_statement:
declaration
;
statement:
compound_statement
| simple_statement
;
# Grammar Note: labeled statements for SWITCH only; 'goto' is not supported.
simple_statement:
expression_statement
| declaration_statement
| selection_statement
| switch_statement
| case_label
| iteration_statement
| jump_statement
;
compound_statement:
LEFT_BRACE RIGHT_BRACE
| LEFT_BRACE statement_list RIGHT_BRACE
;
statement_no_new_scope:
compound_statement_no_new_scope
| simple_statement
;
compound_statement_no_new_scope:
LEFT_BRACE RIGHT_BRACE
| LEFT_BRACE statement_list RIGHT_BRACE
;
statement_list:
statement
| statement_list statement
;
expression_statement:
SEMICOLON
| expression SEMICOLON
;
selection_statement:
IF LEFT_PAREN expression RIGHT_PAREN selection_rest_statement
;
selection_rest_statement:
statement ELSE statement
| statement
;
condition:
expression
| fully_specified_type IDENTIFIER EQUAL initializer
;
switch_statement:
SWITCH LEFT_PAREN expression RIGHT_PAREN LEFT_BRACE switch_statement_list RIGHT_BRACE
;
switch_statement_list:
/* empty */
| statement_list
;
case_label:
CASE expression COLON
| DEFAULT COLON
;
iteration_statement:
WHILE LEFT_PAREN condition RIGHT_PAREN statement_no_new_scope
| DO statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON
| FOR LEFT_PAREN for_init_statement for_rest_statement RIGHT_PAREN
| statement_no_new_scope
;
for_init_statement:
expression_statement
| declaration_statement
;
conditionopt:
/* empty */
| condition
;
for_rest_statement:
conditionopt SEMICOLON
| conditionopt SEMICOLON expression
;
jump_statement:
CONTINUE SEMICOLON
| BREAK SEMICOLON
| RETURN SEMICOLON
| RETURN expression SEMICOLON
| DISCARD SEMICOLON
;
# Grammar Note: No 'goto'. Gotos are not supported.
translation_unit:
external_declaration
| translation_unit external_declaration
;
external_declaration:
function_definition
| declaration
{
_CollectDecls( $_[0], $_[1] );
&_MergeLexemes;
}
;
function_definition:
function_prototype compound_statement_no_new_scope
;
effect_translation_unit:
effect_external_declaration
| effect_translation_unit effect_external_declaration
;
effect_external_declaration:
external_declaration
| shader_definition
| program_definition
;
shader_definition:
shader_type IDENTIFIER LEFT_BRACE
{
$_[0]->YYData->{GLOBAL_DECLS} .= _Yank( $_[0], $_[1], 0 );
_Mark( $_[0], $_[3], 1 );
# create a new scope for the shader
$_[0]->YYData->{DECL_SCOPE} = $_[1]->{TEXT};
$_[0]->YYData->{DECLS}->{$_[0]->YYData->{DECL_SCOPE}} = {};
}
translation_unit
{
my $type = $_[1]->{TEXT};
my $name = $_[2]->{TEXT};
my $globals = $_[0]->YYData->{GLOBAL_DECLS};
my $shader = _Yank( $_[0], $_[5], 1 );
if (exists( $_[0]->YYData->{$type}->{$name} ))
{
_Warn( "Duplicate $type $name declared!\n" );
}
$_[0]->YYData->{$type}->{$name} =
{
'TEXT' => _MakeString( "$globals\n$shader" ),
# merge the global then local scopes
'DECLS' => { ( %{$_[0]->YYData->{DECLS}->{''}}, %{$_[0]->YYData->{DECLS}->{$type}} ) }
};
#print "$type $name GLOBALS:\n", join( "\n", ( %{$_[0]->YYData->{DECLS}->{''}} ) ), "\n\n";
#print "$type $name LOCALS:\n", join( "\n", ( %{$_[0]->YYData->{DECLS}->{$type}} ) ), "\n\n";
#print "$type $name MERGED:\n", join( "\n", ( %{$_[0]->YYData->{$type}->{$name}->{DECLS}} ) ), "\n\n";
#print "Parsed $type ($name):\nglobals:\n$globals\nshader:\n$shader\n<><><><><><><><><><><><>\n";
}
RIGHT_BRACE
{
_Mark( $_[0], $_[7], 1 );
$_[0]->YYData->{DECL_SCOPE} = '';
&_MergeLexemes;
}
;
shader_type:
VERTEXSHADER
| GEOMETRYSHADER
| FRAGMENTSHADER
;
program_definition:
PROGRAM IDENTIFIER LEFT_BRACE
{
my $name = $_[2]->{TEXT};
$_[0]->YYData->{PROGRAM_SCOPE} = $name;
$_[0]->YYData->{PROGRAM}->{$name} = {};
}
program_shader_list RIGHT_BRACE
{
$_[0]->YYData->{PROGRAM_SCOPE} = undef;
&_MergeLexemes;
}
;
program_shader_list:
program_shader
| program_shader_list program_shader
;
program_shader:
shader_type IDENTIFIER SEMICOLON
{
my $type = $_[1]->{TEXT};
my $shader = $_[2]->{TEXT};
my $name = $_[0]->YYData->{PROGRAM_SCOPE};
if (exists( $_[0]->YYData->{PROGRAM}->{$name}->{$type} ))
{
_Warn( "Duplicate shader binding $shader in program $name\n" );
}
$_[0]->YYData->{PROGRAM}->{$name}->{$type} = $shader;
&_MergeLexemes;
}
;
%%
sub _Error()
{
if (exists( $_[0]->YYData->{ERRMSG} ))
{
_Fail( $_[0]->YYData->{ERRMSG} );
delete $_[0]->YYData->{ERRMSG};
return;
};
_Fail( "Syntax error at line " . $_[0]->YYData->{LEX}->line() . ".\n" );
}
my @_keywords =
(
# glue syntax keywords
[ 'VERTEXSHADER', 'vertexshader' ],
[ 'GEOMETRYSHADER', 'geometryshader' ],
[ 'FRAGMENTSHADER', 'fragmentshader' ],
[ 'PROGRAM', 'program' ],
# keywords and reserved words
[ 'ATTRIBUTE', 'attribute' ],
[ 'CONST', 'const' ],
[ 'UNIFORM', 'uniform' ],
[ 'VARYING', 'varying' ],
[ 'LAYOUT', 'layout' ],
[ 'CENTROID', 'centroid' ],
[ 'IF', 'if' ],
[ 'ELSE', 'else' ],
[ 'FLAT', 'flat' ],
[ 'SMOOTH', 'smooth' ],
[ 'NOPERSPECTIVE', 'noperspective' ],
[ 'SWITCH', 'switch' ],
[ 'CASE', 'case' ],
[ 'DEFAULT', 'default' ],
[ 'BREAK', 'break' ],
[ 'CONTINUE', 'continue' ],
[ 'DO', 'do' ],
[ 'FOR', 'for' ],
[ 'WHILE', 'while' ],
[ 'IN', 'in' ],
[ 'OUT', 'out' ],
[ 'INOUT', 'inout' ],
[ 'INT', 'int' ],
[ 'FLOAT', 'float' ],
[ 'VOID', 'void' ],
[ 'BOOL', 'bool' ],
[ 'INVARIANT', 'invariant' ],
[ 'DISCARD', 'discard' ],
[ 'RETURN', 'return' ],
[ 'MAT2', 'mat2' ],
[ 'MAT3', 'mat3' ],
[ 'MAT4', 'mat4' ],
[ 'MAT2X2', 'mat2x2' ],
[ 'MAT2X3', 'mat2x3' ],
[ 'MAT2X4', 'mat2x4' ],
[ 'MAT3X2', 'mat3x2' ],
[ 'MAT3X3', 'mat3x3' ],
[ 'MAT3X4', 'mat3x4' ],
[ 'MAT4X2', 'mat4x2' ],
[ 'MAT4X3', 'mat4x3' ],
[ 'MAT4X4', 'mat4x4' ],
[ 'VEC2', 'vec2' ],
[ 'VEC3', 'vec3' ],
[ 'VEC4', 'vec4' ],
[ 'UINT', 'uint' ],
[ 'LOW_PRECISION', 'lowp' ],
[ 'UVEC2', 'uvec2' ],
[ 'IVEC2', 'ivec2' ],
[ 'IVEC3', 'ivec3' ],
[ 'IVEC4', 'ivec4' ],
[ 'UVEC4', 'uvec4' ],
[ 'PRECISION', 'precision' ],
[ 'SAMPLERCUBESHADOW', 'samplerCubeShadow' ],
[ 'BVEC2', 'bvec2' ],
[ 'BVEC3', 'bvec3' ],
[ 'BVEC4', 'bvec4' ],
[ 'UVEC3', 'uvec3' ],
[ 'MEDIUM_PRECISION', 'mediump' ],
[ 'HIGH_PRECISION', 'highp' ],
[ 'SAMPLER1D', 'sampler1D' ],
[ 'SAMPLER2D', 'sampler2D' ],
[ 'SAMPLER3D', 'sampler3D' ],
[ 'SAMPLERCUBE', 'samplerCube' ],
[ 'SAMPLER1DSHADOW', 'sampler1DShadow' ],
[ 'SAMPLER2DSHADOW', 'sampler2DShadow' ],
[ 'SAMPLER1DARRAY', 'sampler1DArray' ],
[ 'SAMPLER2DARRAY', 'sampler2DArray' ],
[ 'SAMPLER1DARRAYSHADOW', 'sampler1DArrayShadow' ],
[ 'SAMPLER2DARRAYSHADOW', 'sampler2DArrayShadow' ],
[ 'ISAMPLER1D', 'isampler1D' ],
[ 'ISAMPLER2D', 'isampler2D' ],
[ 'ISAMPLER3D', 'isampler3D' ],
[ 'ISAMPLERCUBE', 'isamplerCube' ],
[ 'ISAMPLER1DARRAY', 'isampler1DArray' ],
[ 'ISAMPLER2DARRAY', 'isampler2DArray' ],
[ 'USAMPLER1D', 'usampler1D' ],
[ 'USAMPLER2D', 'usampler2D' ],
[ 'USAMPLER3D', 'usampler3D' ],
[ 'USAMPLERCUBE', 'usamplerCube' ],
[ 'USAMPLER1DARRAY', 'usampler1DArray' ],
[ 'USAMPLER2DARRAY', 'usampler2DArray' ],
[ 'SAMPLER2DRECT', 'sampler2DRect' ],
[ 'SAMPLERBUFFER', 'samplerBuffer' ],
[ 'SAMPLER2DMS', 'sampler2DMS' ],
[ 'STRUCT', 'struct' ],
[ 'COMMON', 'common' ],
[ 'PARTITION', 'partition' ],
[ 'ASM', 'asm' ],
[ 'CLASS', 'class' ],
[ 'GOTO', 'goto' ],
[ 'INLINE', 'inline' ],
[ 'LONG', 'long' ],
[ 'INPUT', 'input' ],
[ 'HVEC2', 'hvec2' ],
[ 'FILTER', 'filter' ],
[ 'IMAGE1D', 'image1D' ],
[ 'IMAGE2D', 'image2D' ],
[ 'IMAGE3D', 'image3D' ],
[ 'IMAGECUBE', 'imageCube' ],
[ 'IIMAGE1D', 'iimage1D' ],
[ 'IIMAGE2D', 'iimage2D' ],
[ 'IIMAGE3D', 'iimage3D' ],
[ 'IIMAGECUBE', 'iimageCube' ],
[ 'UIMAGE1D', 'uimage1D' ],
[ 'UIMAGE2D', 'uimage2D' ],
[ 'UIMAGE3D', 'uimage3D' ],
[ 'UIMAGECUBE', 'uimageCube' ],
[ 'IMAGE1DARRAY', 'image1DArray' ],
[ 'IIMAGE1DARRAY', 'iimage1DArray' ],
[ 'IMAGE2DARRAY', 'image2DArray' ],
[ 'IIMAGE2DARRAY', 'iimage2DArray' ],
[ 'UIMAGE1DARRAY', 'uimage1DArray' ],
[ 'UIMAGE2DARRAY', 'uimage2DArray' ],
[ 'NOINLINE', 'noinline' ],
[ 'SHORT', 'short' ],
[ 'HVEC3', 'hvec3' ],
[ 'OUTPUT', 'output' ],
[ 'HVEC4', 'hvec4' ],
[ 'DVEC2', 'dvec2' ],
[ 'DVEC3', 'dvec3' ],