xref: /illumos-gate/usr/src/tools/ndrgen/ndr_parse.y (revision 0554d5ecd11d9644cbb915be31b5a0b7abb40122)
1 %{
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 /*
29  * Copyright 2020 Tintri by DDN, Inc. All rights reserved.
30  */
31 
32 #include "ndrgen.h"
33 
34 typedef struct node *node_ptr;
35 #define YYSTYPE node_ptr
36 %}
37 
38 /* keywords */
39 %token STRUCT_KW UNION_KW TYPEDEF_KW
40 
41 /* advice keywords */
42 %token ALIGN_KW OPERATION_KW IN_KW OUT_KW
43 %token INTERFACE_KW UUID_KW _NO_REORDER_KW EXTERN_KW
44 %token SIZE_IS_KW LENGTH_IS_KW STRING_KW REFERENCE_KW
45 %token CASE_KW DEFAULT_KW SWITCH_IS_KW
46 %token TRANSMIT_AS_KW ARG_IS_KW FAKE_KW
47 
48 /* composite keywords */
49 %token BASIC_TYPE TYPENAME
50 
51 /* symbols and punctuation */
52 %token IDENTIFIER INTEGER STRING
53 %token LC RC SEMI STAR DIV MOD PLUS MINUS AND OR XOR LB RB LP RP
54 
55 
56 %token L_MEMBER
57 
58 
59 %%
60 
61 defn	:	/* empty */
62 	|	construct_list	={ construct_list = (struct node *)$1; }
63 	;
64 
65 construct_list:	construct
66 	|	construct_list construct ={ n_splice ($1,$2); }
67 	;
68 
69 construct:	struct
70 	|	union
71 	|	typedef
72 	;
73 
74 struct	:	advice STRUCT_KW typename LC members RC SEMI
75 		={ $$ = n_cons (STRUCT_KW, $1, $3, $5);
76 		   construct_fixup ($$);
77 		}
78 	;
79 
80 union	:	advice UNION_KW typename LC members RC SEMI
81 		={ $$ = n_cons (UNION_KW, $1, $3, $5);
82 		   construct_fixup ($$);
83 		}
84 	;
85 
86 typedef	:	TYPEDEF_KW member
87 		={ $$ = n_cons (TYPEDEF_KW, 0, $2->n_m_name, $2);
88 		   construct_fixup ($$);
89 		}
90 	;
91 
92 members	:	member
93 	|	members member		 ={ n_splice ($1,$2); }
94 	;
95 
96 member	:	advice type declarator SEMI
97 		={ $$ = n_cons (L_MEMBER, $1, $2, $3);
98 		   member_fixup ($$);
99 		}
100 	;
101 
102 advice	:	/* empty */		={ $$ = 0; }
103 	|	adv_list
104 	;
105 
106 adv_list:	LB adv_attrs RB		={ $$ = $2; }
107 	|	adv_list LB adv_attrs RB ={ n_splice ($1,$3); }
108 	;
109 
110 adv_attrs:	adv_attr
111 	|	adv_attr adv_attr	={ n_splice ($1,$2); }
112 	;
113 
114 adv_attr:	IN_KW			={ $$ = n_cons (IN_KW); }
115 	|	OUT_KW			={ $$ = n_cons (OUT_KW); }
116 	|	OPERATION_KW LP arg RP	={ $$ = n_cons (OPERATION_KW, $3); }
117 	|	ALIGN_KW LP arg RP	={ $$ = n_cons (ALIGN_KW, $3); }
118 	|	STRING_KW		={ $$ = n_cons (STRING_KW); }
119 	|	FAKE_KW			={ $$ = n_cons (FAKE_KW); }
120 
121 	|	SIZE_IS_KW LP arg RP
122 				={ $$ = n_cons (SIZE_IS_KW, $3, $3, $3); }
123 	|	SIZE_IS_KW LP arg operator INTEGER RP
124 				={ $$ = n_cons (SIZE_IS_KW, $3, $4, $5); }
125 
126 	|	LENGTH_IS_KW LP arg RP
127 				={ $$ = n_cons (LENGTH_IS_KW, $3, $3, $3); }
128 	|	LENGTH_IS_KW LP arg operator INTEGER RP
129 				={ $$ = n_cons (LENGTH_IS_KW, $3, $4, $5); }
130 
131 	|	SWITCH_IS_KW LP arg RP
132 				={ $$ = n_cons (SWITCH_IS_KW, $3, $3, $3); }
133 	|	SWITCH_IS_KW LP arg operator INTEGER RP
134 				={ $$ = n_cons (SWITCH_IS_KW, $3, $4, $5); }
135 
136 	|	CASE_KW LP arg RP	={ $$ = n_cons (CASE_KW, $3); }
137 	|	DEFAULT_KW		={ $$ = n_cons (DEFAULT_KW); }
138 
139 	|	ARG_IS_KW LP arg RP	={ $$ = n_cons (ARG_IS_KW, $3); }
140 	|	TRANSMIT_AS_KW LP BASIC_TYPE RP
141 					={ $$ = n_cons (TRANSMIT_AS_KW, $3); }
142 
143 	|	INTERFACE_KW LP arg RP	={ $$ = n_cons (INTERFACE_KW, $3); }
144 	|	UUID_KW LP arg RP	={ $$ = n_cons (UUID_KW, $3); }
145 	|	_NO_REORDER_KW		={ $$ = n_cons (_NO_REORDER_KW); }
146 	|	EXTERN_KW		={ $$ = n_cons (EXTERN_KW); }
147 	|	REFERENCE_KW		={ $$ = n_cons (REFERENCE_KW); }
148 	;
149 
150 arg	:	IDENTIFIER
151 	|	INTEGER
152 	|	STRING
153 	;
154 
155 type	:	BASIC_TYPE
156 	|	typename
157 	|	STRUCT_KW typename	={ $$ = $2; }
158 	|	UNION_KW  typename	={ $$ = $2; }
159 	;
160 
161 typename:	TYPENAME
162 	|	IDENTIFIER
163 	;
164 
165 operator:	STAR
166 	|	DIV
167 	|	MOD
168 	|	PLUS
169 	|	MINUS
170 	|	AND
171 	|	OR
172 	|	XOR
173 	;
174 
175 declarator:	decl1
176 	;
177 
178 decl1	:	decl2
179 	|	STAR decl1		={ $$ = n_cons (STAR, $2); }
180 	;
181 
182 decl2	:	decl3
183 	|	decl3 LB RB		={ $$ = n_cons (LB, $1, 0); }
184 	|	decl3 LB STAR RB	={ $$ = n_cons (LB, $1, 0); }
185 	|	decl3 LB INTEGER RB	={ $$ = n_cons (LB, $1, $3); }
186 	;
187 
188 decl3	:	IDENTIFIER
189 	|	LP decl1 RP		={ $$ = n_cons (LP, $2); }
190 	;
191 
192 
193 
194 %%
195