aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/lib/libdtrace/common/dt_grammar.y
blob: 0cb6fa6b52534e8c7dc72c1d5e5595ee3c90812b (plain) (blame)
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
%{
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
 */

#include <dt_impl.h>

#define	OP1(op, c)	dt_node_op1(op, c)
#define	OP2(op, l, r)	dt_node_op2(op, l, r)
#define	OP3(x, y, z)	dt_node_op3(x, y, z)
#define	LINK(l, r)	dt_node_link(l, r)
#define	DUP(s)		strdup(s)

%}

%union {
	dt_node_t *l_node;
	dt_decl_t *l_decl;
	char *l_str;
	uintmax_t l_int;
	int l_tok;
}

%token	DT_TOK_COMMA DT_TOK_ELLIPSIS
%token	DT_TOK_ASGN DT_TOK_ADD_EQ DT_TOK_SUB_EQ DT_TOK_MUL_EQ
%token	DT_TOK_DIV_EQ DT_TOK_MOD_EQ DT_TOK_AND_EQ DT_TOK_XOR_EQ DT_TOK_OR_EQ
%token	DT_TOK_LSH_EQ DT_TOK_RSH_EQ DT_TOK_QUESTION DT_TOK_COLON
%token	DT_TOK_LOR DT_TOK_LXOR DT_TOK_LAND
%token	DT_TOK_BOR DT_TOK_XOR DT_TOK_BAND DT_TOK_EQU DT_TOK_NEQ
%token	DT_TOK_LT DT_TOK_LE DT_TOK_GT DT_TOK_GE DT_TOK_LSH DT_TOK_RSH
%token	DT_TOK_ADD DT_TOK_SUB DT_TOK_MUL DT_TOK_DIV DT_TOK_MOD
%token	DT_TOK_LNEG DT_TOK_BNEG DT_TOK_ADDADD DT_TOK_SUBSUB
%token	DT_TOK_PREINC DT_TOK_POSTINC DT_TOK_PREDEC DT_TOK_POSTDEC
%token	DT_TOK_IPOS DT_TOK_INEG DT_TOK_DEREF DT_TOK_ADDROF
%token	DT_TOK_OFFSETOF DT_TOK_SIZEOF DT_TOK_STRINGOF DT_TOK_XLATE
%token	DT_TOK_LPAR DT_TOK_RPAR DT_TOK_LBRAC DT_TOK_RBRAC DT_TOK_PTR DT_TOK_DOT

%token <l_str>	DT_TOK_STRING
%token <l_str>	DT_TOK_IDENT
%token <l_str>	DT_TOK_PSPEC
%token <l_str>	DT_TOK_AGG
%token <l_str>	DT_TOK_TNAME
%token <l_int>	DT_TOK_INT

%token	DT_KEY_AUTO
%token	DT_KEY_BREAK
%token	DT_KEY_CASE
%token	DT_KEY_CHAR
%token	DT_KEY_CONST
%token	DT_KEY_CONTINUE
%token	DT_KEY_COUNTER
%token	DT_KEY_DEFAULT
%token	DT_KEY_DO
%token	DT_KEY_DOUBLE
%token	DT_KEY_ELSE
%token	DT_KEY_ENUM
%token	DT_KEY_EXTERN
%token	DT_KEY_FLOAT
%token	DT_KEY_FOR
%token	DT_KEY_GOTO
%token	DT_KEY_IF
%token	DT_KEY_IMPORT
%token	DT_KEY_INLINE
%token	DT_KEY_INT
%token	DT_KEY_LONG
%token	DT_KEY_PROBE
%token	DT_KEY_PROVIDER
%token	DT_KEY_REGISTER
%token	DT_KEY_RESTRICT
%token	DT_KEY_RETURN
%token	DT_KEY_SELF
%token	DT_KEY_SHORT
%token	DT_KEY_SIGNED
%token	DT_KEY_STATIC
%token	DT_KEY_STRING
%token	DT_KEY_STRUCT
%token	DT_KEY_SWITCH
%token	DT_KEY_THIS
%token	DT_KEY_TYPEDEF
%token	DT_KEY_UNION
%token	DT_KEY_UNSIGNED
%token	DT_KEY_USERLAND
%token	DT_KEY_VOID
%token	DT_KEY_VOLATILE
%token	DT_KEY_WHILE
%token	DT_KEY_XLATOR

%token	DT_TOK_EPRED
%token	DT_CTX_DEXPR
%token	DT_CTX_DPROG
%token	DT_CTX_DTYPE
%token	DT_TOK_EOF	0

%left	DT_TOK_COMMA
%right	DT_TOK_ASGN DT_TOK_ADD_EQ DT_TOK_SUB_EQ DT_TOK_MUL_EQ DT_TOK_DIV_EQ
	DT_TOK_MOD_EQ DT_TOK_AND_EQ DT_TOK_XOR_EQ DT_TOK_OR_EQ DT_TOK_LSH_EQ
	DT_TOK_RSH_EQ
%left	DT_TOK_QUESTION DT_TOK_COLON
%left	DT_TOK_LOR
%left	DT_TOK_LXOR
%left	DT_TOK_LAND
%left	DT_TOK_BOR
%left	DT_TOK_XOR
%left	DT_TOK_BAND
%left	DT_TOK_EQU DT_TOK_NEQ
%left	DT_TOK_LT DT_TOK_LE DT_TOK_GT DT_TOK_GE
%left	DT_TOK_LSH DT_TOK_RSH
%left	DT_TOK_ADD DT_TOK_SUB
%left	DT_TOK_MUL DT_TOK_DIV DT_TOK_MOD
%right	DT_TOK_LNEG DT_TOK_BNEG DT_TOK_ADDADD DT_TOK_SUBSUB
	DT_TOK_IPOS DT_TOK_INEG
%right	DT_TOK_DEREF DT_TOK_ADDROF DT_TOK_SIZEOF DT_TOK_STRINGOF DT_TOK_XLATE
%left	DT_TOK_LPAR DT_TOK_RPAR DT_TOK_LBRAC DT_TOK_RBRAC DT_TOK_PTR DT_TOK_DOT

%type	<l_node>	d_expression
%type	<l_node>	d_program
%type	<l_node>	d_type

%type	<l_node>	translation_unit
%type	<l_node>	external_declaration
%type	<l_node>	inline_definition
%type	<l_node>	translator_definition
%type	<l_node>	translator_member_list
%type	<l_node>	translator_member
%type	<l_node>	provider_definition
%type	<l_node>	provider_probe_list
%type	<l_node>	provider_probe
%type	<l_node>	probe_definition
%type	<l_node>	probe_specifiers
%type	<l_node>	probe_specifier_list
%type	<l_node>	probe_specifier
%type	<l_node>	statement_list
%type	<l_node>	statement_list_impl
%type	<l_node>	statement_or_block
%type	<l_node>	statement
%type	<l_node>	declaration
%type	<l_node>	init_declarator_list
%type	<l_node>	init_declarator

%type	<l_decl>	type_specifier
%type	<l_decl>	type_qualifier
%type	<l_decl>	struct_or_union_specifier
%type	<l_decl>	specifier_qualifier_list
%type	<l_decl>	enum_specifier
%type	<l_decl>	declarator
%type	<l_decl>	direct_declarator
%type	<l_decl>	pointer
%type	<l_decl>	type_qualifier_list
%type	<l_decl>	type_name
%type	<l_decl>	abstract_declarator
%type	<l_decl>	direct_abstract_declarator

%type	<l_node>	parameter_type_list
%type	<l_node>	parameter_list
%type	<l_node>	parameter_declaration

%type	<l_node>	array
%type	<l_node>	array_parameters
%type	<l_node>	function
%type	<l_node>	function_parameters

%type	<l_node>	expression
%type	<l_node>	assignment_expression
%type	<l_node>	conditional_expression
%type	<l_node>	constant_expression
%type	<l_node>	logical_or_expression
%type	<l_node>	logical_xor_expression
%type	<l_node>	logical_and_expression
%type	<l_node>	inclusive_or_expression
%type	<l_node>	exclusive_or_expression
%type	<l_node>	and_expression
%type	<l_node>	equality_expression
%type	<l_node>	relational_expression
%type	<l_node>	shift_expression
%type	<l_node>	additive_expression
%type	<l_node>	multiplicative_expression
%type	<l_node>	cast_expression
%type	<l_node>	unary_expression
%type	<l_node>	postfix_expression
%type	<l_node>	primary_expression
%type	<l_node>	argument_expression_list

%type	<l_tok>		assignment_operator
%type	<l_tok>		unary_operator
%type	<l_tok>		struct_or_union

%type	<l_str>		dtrace_keyword_ident

%%

dtrace_program: d_expression DT_TOK_EOF { return (dt_node_root($1)); }
	|	d_program DT_TOK_EOF { return (dt_node_root($1)); }
	|	d_type DT_TOK_EOF { return (dt_node_root($1)); }
	;

d_expression:	DT_CTX_DEXPR { $$ = NULL; }
	|	DT_CTX_DEXPR expression { $$ = $2; }
	;

d_program:	DT_CTX_DPROG { $$ = dt_node_program(NULL); }
	|	DT_CTX_DPROG translation_unit { $$ = dt_node_program($2); }
	;

d_type:		DT_CTX_DTYPE { $$ = NULL; }
	|	DT_CTX_DTYPE type_name { $$ = (dt_node_t *)$2; }
	;

translation_unit:
		external_declaration
	|	translation_unit external_declaration { $$ = LINK($1, $2); }
	;

external_declaration:
		inline_definition
	|	translator_definition
	|	provider_definition
	|	probe_definition
	|	declaration
	;

inline_definition:
		DT_KEY_INLINE declaration_specifiers declarator
		    { dt_scope_push(NULL, CTF_ERR); } DT_TOK_ASGN
		    assignment_expression ';' {
			/*
			 * We push a new declaration scope before shifting the
			 * assignment_expression in order to preserve ds_class
			 * and ds_ident for use in dt_node_inline().  Once the
			 * entire inline_definition rule is matched, pop the
			 * scope and construct the inline using the saved decl.
			 */
			dt_scope_pop();
			$$ = dt_node_inline($6);
		}
	;

translator_definition:
		DT_KEY_XLATOR type_name DT_TOK_LT type_name
		    DT_TOK_IDENT DT_TOK_GT '{' translator_member_list '}' ';' {
			$$ = dt_node_xlator($2, $4, $5, $8);
		}
	|	DT_KEY_XLATOR type_name DT_TOK_LT type_name
		    DT_TOK_IDENT DT_TOK_GT '{' '}' ';' {
			$$ = dt_node_xlator($2, $4, $5, NULL);
		}
	;

translator_member_list:
		translator_member
	|	translator_member_list translator_member { $$ = LINK($1,$2); }
	;

translator_member:
		DT_TOK_IDENT DT_TOK_ASGN assignment_expression ';' {
			$$ = dt_node_member(NULL, $1, $3);
		}
	;

provider_definition:
		DT_KEY_PROVIDER DT_TOK_IDENT '{' provider_probe_list '}' ';' {
			$$ = dt_node_provider($2, $4);
		}
	|	DT_KEY_PROVIDER DT_TOK_IDENT '{' '}' ';' {
			$$ = dt_node_provider($2, NULL);
		}
	;

provider_probe_list:
		provider_probe
	|	provider_probe_list provider_probe { $$ = LINK($1, $2); }
	;

provider_probe:
		DT_KEY_PROBE DT_TOK_IDENT function DT_TOK_COLON function ';' {
			$$ = dt_node_probe($2, 2, $3, $5);
		}
	|	DT_KEY_PROBE DT_TOK_IDENT function ';' {
			$$ = dt_node_probe($2, 1, $3, NULL);
		}
	;
	

probe_definition:
		probe_specifiers {
			/*
			 * If the input stream is a file, do not permit a probe
			 * specification without / <pred> / or { <act> } after
			 * it.  This can only occur if the next token is EOF or
			 * an ambiguous predicate was slurped up as a comment.
			 * We cannot perform this check if input() is a string
			 * because dtrace(1M) [-fmnP] also use the compiler and
			 * things like dtrace -n BEGIN have to be accepted.
			 */
			if (yypcb->pcb_fileptr != NULL) {
				dnerror($1, D_SYNTAX, "expected predicate and/"
				    "or actions following probe description\n");
			}
			$$ = dt_node_clause($1, NULL, NULL);
			yybegin(YYS_CLAUSE);
		}
	|	probe_specifiers '{' statement_list '}' {
			$$ = dt_node_clause($1, NULL, $3);
			yybegin(YYS_CLAUSE);
		}
	|	probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED {
			dnerror($3, D_SYNTAX, "expected actions { } following "
			    "probe description and predicate\n");
		}
	|	probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED
		    '{' statement_list '}' {
			$$ = dt_node_clause($1, $3, $6);
			yybegin(YYS_CLAUSE);
		}
	;

probe_specifiers:
		probe_specifier_list { yybegin(YYS_EXPR); $$ = $1; }
	;

probe_specifier_list:
		probe_specifier
	|	probe_specifier_list DT_TOK_COMMA probe_specifier {
			$$ = LINK($1, $3);
		}
	;

probe_specifier:
		DT_TOK_PSPEC { $$ = dt_node_pdesc_by_name($1); }
	|	DT_TOK_INT   { $$ = dt_node_pdesc_by_id($1); }
	;

statement_list_impl: /* empty */ { $$ = NULL; }
	|	statement_list_impl statement { $$ = LINK($1, $2); }
	;

statement_list:
		statement_list_impl { $$ = $1; }
	|	statement_list_impl expression {
			$$ = LINK($1, dt_node_statement($2));
		}
	;

statement_or_block:
		statement
	|	'{' statement_list '}' { $$ = $2; }

statement:	';' { $$ = NULL; }
	|	expression ';' { $$ = dt_node_statement($1); }
	|	DT_KEY_IF DT_TOK_LPAR expression DT_TOK_RPAR statement_or_block {
			$$ = dt_node_if($3, $5, NULL);
		}
	|	DT_KEY_IF DT_TOK_LPAR expression DT_TOK_RPAR
		statement_or_block DT_KEY_ELSE statement_or_block {
			$$ = dt_node_if($3, $5, $7);
		}
	;

argument_expression_list:
		assignment_expression
	|	argument_expression_list DT_TOK_COMMA assignment_expression {
			$$ = LINK($1, $3);
		}
	;

primary_expression:
		DT_TOK_IDENT { $$ = dt_node_ident($1); }
	|	DT_TOK_AGG { $$ = dt_node_ident($1); }
	|	DT_TOK_INT { $$ = dt_node_int($1); }
	|	DT_TOK_STRING { $$ = dt_node_string($1); }
	|	DT_KEY_SELF { $$ = dt_node_ident(DUP("self")); }
	|	DT_KEY_THIS { $$ = dt_node_ident(DUP("this")); }
	|	DT_TOK_LPAR expression DT_TOK_RPAR { $$ = $2; }
	;

postfix_expression:
		primary_expression
	|	postfix_expression
		    DT_TOK_LBRAC argument_expression_list DT_TOK_RBRAC {
			$$ = OP2(DT_TOK_LBRAC, $1, $3);
		}
	|	postfix_expression DT_TOK_LPAR DT_TOK_RPAR {
			$$ = dt_node_func($1, NULL);
		}
	|	postfix_expression
		    DT_TOK_LPAR argument_expression_list DT_TOK_RPAR {
			$$ = dt_node_func($1, $3);
		}
	|	postfix_expression DT_TOK_DOT DT_TOK_IDENT {
			$$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
		}
	|	postfix_expression DT_TOK_DOT DT_TOK_TNAME {
			$$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
		}
	|	postfix_expression DT_TOK_DOT dtrace_keyword_ident {
			$$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
		}
	|	postfix_expression DT_TOK_PTR DT_TOK_IDENT {
			$$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
		}
	|	postfix_expression DT_TOK_PTR DT_TOK_TNAME {
			$$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
		}
	|	postfix_expression DT_TOK_PTR dtrace_keyword_ident {
			$$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
		}
	|	postfix_expression DT_TOK_ADDADD {
			$$ = OP1(DT_TOK_POSTINC, $1);
		}
	|	postfix_expression DT_TOK_SUBSUB {
			$$ = OP1(DT_TOK_POSTDEC, $1);
		}
	|	DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA 
		    DT_TOK_IDENT DT_TOK_RPAR {
			$$ = dt_node_offsetof($3, $5);
		}
	|	DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA 
		    DT_TOK_TNAME DT_TOK_RPAR {
			$$ = dt_node_offsetof($3, $5);
		}
	|	DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA
		    dtrace_keyword_ident DT_TOK_RPAR {
			$$ = dt_node_offsetof($3, $5);
		}
	|	DT_TOK_XLATE DT_TOK_LT type_name DT_TOK_GT
		    DT_TOK_LPAR expression DT_TOK_RPAR {
			$$ = OP2(DT_TOK_XLATE, dt_node_type($3), $6);
		}
	;

unary_expression:
		postfix_expression
	|	DT_TOK_ADDADD unary_expression { $$ = OP1(DT_TOK_PREINC, $2); }
	|	DT_TOK_SUBSUB unary_expression { $$ = OP1(DT_TOK_PREDEC, $2); }
	|	unary_operator cast_expression { $$ = OP1($1, $2); }
	|	DT_TOK_SIZEOF unary_expression { $$ = OP1(DT_TOK_SIZEOF, $2); }
	|	DT_TOK_SIZEOF DT_TOK_LPAR type_name DT_TOK_RPAR {
			$$ = OP1(DT_TOK_SIZEOF, dt_node_type($3));
		}
	|	DT_TOK_STRINGOF unary_expression {
			$$ = OP1(DT_TOK_STRINGOF, $2);
		}
	;

unary_operator:	DT_TOK_BAND { $$ = DT_TOK_ADDROF; }
	|	DT_TOK_MUL { $$ = DT_TOK_DEREF; }
	|	DT_TOK_ADD { $$ = DT_TOK_IPOS; }
	|	DT_TOK_SUB { $$ = DT_TOK_INEG; }
	|	DT_TOK_BNEG { $$ = DT_TOK_BNEG; }
	|	DT_TOK_LNEG { $$ = DT_TOK_LNEG; }
	;

cast_expression:
		unary_expression
	|	DT_TOK_LPAR type_name DT_TOK_RPAR cast_expression {
			$$ = OP2(DT_TOK_LPAR, dt_node_type($2), $4);
		}
	;

multiplicative_expression:
		cast_expression
	|	multiplicative_expression DT_TOK_MUL cast_expression {
			$$ = OP2(DT_TOK_MUL, $1, $3);
		}
	|	multiplicative_expression DT_TOK_DIV cast_expression {
			$$ = OP2(DT_TOK_DIV, $1, $3);
		}
	|	multiplicative_expression DT_TOK_MOD cast_expression {
			$$ = OP2(DT_TOK_MOD, $1, $3);
		}
	;

additive_expression:
		multiplicative_expression
	|	additive_expression DT_TOK_ADD multiplicative_expression {
			$$ = OP2(DT_TOK_ADD, $1, $3);
		}
	|	additive_expression DT_TOK_SUB multiplicative_expression {
			$$ = OP2(DT_TOK_SUB, $1, $3);
		}
	;

shift_expression:
		additive_expression
	|	shift_expression DT_TOK_LSH additive_expression {
			$$ = OP2(DT_TOK_LSH, $1, $3);
		}
	|	shift_expression DT_TOK_RSH additive_expression {
			$$ = OP2(DT_TOK_RSH, $1, $3);
		}
	;

relational_expression:
		shift_expression
	|	relational_expression DT_TOK_LT shift_expression {
			$$ = OP2(DT_TOK_LT, $1, $3);
		}
	|	relational_expression DT_TOK_GT shift_expression {
			$$ = OP2(DT_TOK_GT, $1, $3);
		}
	|	relational_expression DT_TOK_LE shift_expression {
			$$ = OP2(DT_TOK_LE, $1, $3);
		}
	|	relational_expression DT_TOK_GE shift_expression {
			$$ = OP2(DT_TOK_GE, $1, $3);
		}
	;

equality_expression:
		relational_expression
	|	equality_expression DT_TOK_EQU relational_expression {
			$$ = OP2(DT_TOK_EQU, $1, $3);
		}
	|	equality_expression DT_TOK_NEQ relational_expression {
			$$ = OP2(DT_TOK_NEQ, $1, $3);
		}
	;

and_expression:
		equality_expression
	|	and_expression DT_TOK_BAND equality_expression {
			$$ = OP2(DT_TOK_BAND, $1, $3);
		}
	;

exclusive_or_expression:
		and_expression
	|	exclusive_or_expression DT_TOK_XOR and_expression {
			$$ = OP2(DT_TOK_XOR, $1, $3);
		}
	;

inclusive_or_expression:
		exclusive_or_expression
	|	inclusive_or_expression DT_TOK_BOR exclusive_or_expression {
			$$ = OP2(DT_TOK_BOR, $1, $3);
		}
	;

logical_and_expression:
		inclusive_or_expression
	|	logical_and_expression DT_TOK_LAND inclusive_or_expression {
			$$ = OP2(DT_TOK_LAND, $1, $3);
		}
	;

logical_xor_expression:
		logical_and_expression
	|	logical_xor_expression DT_TOK_LXOR logical_and_expression {
			$$ = OP2(DT_TOK_LXOR, $1, $3);
		}
	;

logical_or_expression:
		logical_xor_expression
	|	logical_or_expression DT_TOK_LOR logical_xor_expression {
			$$ = OP2(DT_TOK_LOR, $1, $3);
		}
	;

constant_expression: conditional_expression
	;

conditional_expression:
		logical_or_expression
	|	logical_or_expression DT_TOK_QUESTION expression DT_TOK_COLON
		    conditional_expression { $$ = OP3($1, $3, $5); }
	;

assignment_expression:
		conditional_expression
	|	unary_expression assignment_operator assignment_expression {
			$$ = OP2($2, $1, $3);
		}
	;

assignment_operator:
		DT_TOK_ASGN   { $$ = DT_TOK_ASGN; }
	|	DT_TOK_MUL_EQ { $$ = DT_TOK_MUL_EQ; }
	|	DT_TOK_DIV_EQ { $$ = DT_TOK_DIV_EQ; }
	|	DT_TOK_MOD_EQ { $$ = DT_TOK_MOD_EQ; }
	|	DT_TOK_ADD_EQ { $$ = DT_TOK_ADD_EQ; }
	|	DT_TOK_SUB_EQ { $$ = DT_TOK_SUB_EQ; }
	|	DT_TOK_LSH_EQ { $$ = DT_TOK_LSH_EQ; }
	|	DT_TOK_RSH_EQ { $$ = DT_TOK_RSH_EQ; }
	|	DT_TOK_AND_EQ { $$ = DT_TOK_AND_EQ; }
	|	DT_TOK_XOR_EQ { $$ = DT_TOK_XOR_EQ; }
	|	DT_TOK_OR_EQ  { $$ = DT_TOK_OR_EQ; }
	;

expression:	assignment_expression
	|	expression DT_TOK_COMMA assignment_expression {
			$$ = OP2(DT_TOK_COMMA, $1, $3);
		}
	;

declaration:	declaration_specifiers ';' {
			$$ = dt_node_decl();
			dt_decl_free(dt_decl_pop());
			yybegin(YYS_CLAUSE);
		}
	|	declaration_specifiers init_declarator_list ';' {
			$$ = $2;
			dt_decl_free(dt_decl_pop());
			yybegin(YYS_CLAUSE);
		}
	;

declaration_specifiers:
		d_storage_class_specifier
	|	d_storage_class_specifier declaration_specifiers
	|	type_specifier
	|	type_specifier declaration_specifiers
	|	type_qualifier
	|	type_qualifier declaration_specifiers
	;

parameter_declaration_specifiers:
		storage_class_specifier
	|	storage_class_specifier declaration_specifiers
	|	type_specifier
	|	type_specifier declaration_specifiers
	|	type_qualifier
	|	type_qualifier declaration_specifiers
	;

storage_class_specifier:
		DT_KEY_AUTO { dt_decl_class(DT_DC_AUTO); }
	|	DT_KEY_REGISTER { dt_decl_class(DT_DC_REGISTER); }
	|	DT_KEY_STATIC { dt_decl_class(DT_DC_STATIC); }
	|	DT_KEY_EXTERN { dt_decl_class(DT_DC_EXTERN); }
	|	DT_KEY_TYPEDEF { dt_decl_class(DT_DC_TYPEDEF); }
	;

d_storage_class_specifier:
		storage_class_specifier
	|	DT_KEY_SELF { dt_decl_class(DT_DC_SELF); }
	|	DT_KEY_THIS { dt_decl_class(DT_DC_THIS); }
	;

type_specifier:	DT_KEY_VOID { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("void")); }
	|	DT_KEY_CHAR { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("char")); }
	|	DT_KEY_SHORT { $$ = dt_decl_attr(DT_DA_SHORT); }
	|	DT_KEY_INT { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("int")); }
	|	DT_KEY_LONG { $$ = dt_decl_attr(DT_DA_LONG); }
	|	DT_KEY_FLOAT { $$ = dt_decl_spec(CTF_K_FLOAT, DUP("float")); }
	|	DT_KEY_DOUBLE { $$ = dt_decl_spec(CTF_K_FLOAT, DUP("double")); }
	|	DT_KEY_SIGNED { $$ = dt_decl_attr(DT_DA_SIGNED); }
	|	DT_KEY_UNSIGNED { $$ = dt_decl_attr(DT_DA_UNSIGNED); }
	|	DT_KEY_USERLAND { $$ = dt_decl_attr(DT_DA_USER); }
	|	DT_KEY_STRING {
			$$ = dt_decl_spec(CTF_K_TYPEDEF, DUP("string"));
		}
	|	DT_TOK_TNAME { $$ = dt_decl_spec(CTF_K_TYPEDEF, $1); }
	|	struct_or_union_specifier
	|	enum_specifier
	;

type_qualifier:	DT_KEY_CONST { $$ = dt_decl_attr(DT_DA_CONST); }
	|	DT_KEY_RESTRICT { $$ = dt_decl_attr(DT_DA_RESTRICT); }
	|	DT_KEY_VOLATILE { $$ = dt_decl_attr(DT_DA_VOLATILE); }
	;

struct_or_union_specifier:
		struct_or_union_definition struct_declaration_list '}' {
			$$ = dt_scope_pop();
		}
	|	struct_or_union DT_TOK_IDENT { $$ = dt_decl_spec($1, $2); }
	|	struct_or_union DT_TOK_TNAME { $$ = dt_decl_spec($1, $2); }
	;

struct_or_union_definition:
		struct_or_union '{' { dt_decl_sou($1, NULL); }
	|	struct_or_union DT_TOK_IDENT '{' { dt_decl_sou($1, $2); }
	|	struct_or_union DT_TOK_TNAME '{' { dt_decl_sou($1, $2); }
	;

struct_or_union:
		DT_KEY_STRUCT { $$ = CTF_K_STRUCT; }
	|	DT_KEY_UNION { $$ = CTF_K_UNION; }
	;

struct_declaration_list:
		struct_declaration
	|	struct_declaration_list struct_declaration
	;

init_declarator_list:
		init_declarator
	|	init_declarator_list DT_TOK_COMMA init_declarator {
			$$ = LINK($1, $3);
		}
	;

init_declarator:
		declarator {
			$$ = dt_node_decl();
			dt_decl_reset();
		}
	;

struct_declaration:
		specifier_qualifier_list struct_declarator_list ';' {
			dt_decl_free(dt_decl_pop());
		}
	;

specifier_qualifier_list:
		type_specifier
	|	type_specifier specifier_qualifier_list { $$ = $2; }
	|	type_qualifier
	|	type_qualifier specifier_qualifier_list { $$ = $2; }
	;

struct_declarator_list:
		struct_declarator
	|	struct_declarator_list DT_TOK_COMMA struct_declarator
	;

struct_declarator:
		declarator { dt_decl_member(NULL); }
	|	DT_TOK_COLON constant_expression { dt_decl_member($2); }
	|	declarator DT_TOK_COLON constant_expression {
			dt_decl_member($3);
		}
	;

enum_specifier:
		enum_definition enumerator_list '}' { $$ = dt_scope_pop(); }
	|	DT_KEY_ENUM DT_TOK_IDENT { $$ = dt_decl_spec(CTF_K_ENUM, $2); }
	|	DT_KEY_ENUM DT_TOK_TNAME { $$ = dt_decl_spec(CTF_K_ENUM, $2); }
	;

enum_definition:
		DT_KEY_ENUM '{' { dt_decl_enum(NULL); }
	|	DT_KEY_ENUM DT_TOK_IDENT '{' { dt_decl_enum($2); }
	|	DT_KEY_ENUM DT_TOK_TNAME '{' { dt_decl_enum($2); }
	;

enumerator_list:
		enumerator
	|	enumerator_list DT_TOK_COMMA enumerator
	;

enumerator:	DT_TOK_IDENT { dt_decl_enumerator($1, NULL); }
	|	DT_TOK_IDENT DT_TOK_ASGN expression {
			dt_decl_enumerator($1, $3);
		}
	;

declarator:	direct_declarator
	|	pointer direct_declarator
	;

direct_declarator:
		DT_TOK_IDENT { $$ = dt_decl_ident($1); }
	|	lparen declarator DT_TOK_RPAR { $$ = $2; }
	|	direct_declarator array { dt_decl_array($2); }
	|	direct_declarator function { dt_decl_func($1, $2); }
	;

lparen:		DT_TOK_LPAR { dt_decl_top()->dd_attr |= DT_DA_PAREN; }
	;

pointer:	DT_TOK_MUL { $$ = dt_decl_ptr(); }
	|	DT_TOK_MUL type_qualifier_list { $$ = dt_decl_ptr(); }
	|	DT_TOK_MUL pointer { $$ = dt_decl_ptr(); }
	|	DT_TOK_MUL type_qualifier_list pointer { $$ = dt_decl_ptr(); }
	;

type_qualifier_list:
		type_qualifier
	|	type_qualifier_list type_qualifier { $$ = $2; }
	;

parameter_type_list:
		parameter_list
	|	DT_TOK_ELLIPSIS { $$ = dt_node_vatype(); }
	|	parameter_list DT_TOK_COMMA DT_TOK_ELLIPSIS {
			$$ = LINK($1, dt_node_vatype());
		}
	;

parameter_list:	parameter_declaration
	|	parameter_list DT_TOK_COMMA parameter_declaration {
			$$ = LINK($1, $3);
		}
	;

parameter_declaration:
		parameter_declaration_specifiers {
			$$ = dt_node_type(NULL);
		}
	|	parameter_declaration_specifiers declarator {
			$$ = dt_node_type(NULL);
		}
	|	parameter_declaration_specifiers abstract_declarator {
			$$ = dt_node_type(NULL);
		}
	;

type_name:	specifier_qualifier_list {
			$$ = dt_decl_pop();
		}
	|	specifier_qualifier_list abstract_declarator {
			$$ = dt_decl_pop();
		}
	;

abstract_declarator:
		pointer
	|	direct_abstract_declarator
	|	pointer direct_abstract_declarator
	;

direct_abstract_declarator:
		lparen abstract_declarator DT_TOK_RPAR { $$ = $2; }
	|	direct_abstract_declarator array { dt_decl_array($2); }
	|	array { dt_decl_array($1); $$ = NULL; }
	|	direct_abstract_declarator function { dt_decl_func($1, $2); }
	|	function { dt_decl_func(NULL, $1); }
	;

array:		DT_TOK_LBRAC { dt_scope_push(NULL, CTF_ERR); }
		    array_parameters DT_TOK_RBRAC {
			dt_scope_pop();
			$$ = $3;
		}
	;

array_parameters:
		/* empty */ 		{ $$ = NULL; }
	|	constant_expression	{ $$ = $1; }
	|	parameter_type_list	{ $$ = $1; }
	;

function:	DT_TOK_LPAR { dt_scope_push(NULL, CTF_ERR); }
		    function_parameters DT_TOK_RPAR {
			dt_scope_pop();
			$$ = $3;
		}
	;

function_parameters:
		/* empty */ 		{ $$ = NULL; }
	|	parameter_type_list	{ $$ = $1; }
	;

dtrace_keyword_ident:
	  DT_KEY_PROBE { $$ = DUP("probe"); }
	| DT_KEY_PROVIDER { $$ = DUP("provider"); }
	| DT_KEY_SELF { $$ = DUP("self"); }
	| DT_KEY_STRING { $$ = DUP("string"); }
	| DT_TOK_STRINGOF { $$ = DUP("stringof"); }
	| DT_KEY_USERLAND { $$ = DUP("userland"); }
	| DT_TOK_XLATE { $$ = DUP("xlate"); }
	| DT_KEY_XLATOR { $$ = DUP("translator"); }
	;

%%