xref: /titanic_50/usr/src/tools/ndrgen/ndr_parse.y (revision 69b3e10436272b0970d58743de375d0dd61046ce)
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 #include "ndrgen.h"
29 
30 typedef struct node *node_ptr;
31 #define YYSTYPE node_ptr
32 %}
33 
34 /* keywords */
35 %token STRUCT_KW UNION_KW TYPEDEF_KW
36 
37 /* advice keywords */
38 %token ALIGN_KW OPERATION_KW IN_KW OUT_KW
39 %token INTERFACE_KW UUID_KW _NO_REORDER_KW EXTERN_KW
40 %token SIZE_IS_KW LENGTH_IS_KW STRING_KW REFERENCE_KW
41 %token CASE_KW DEFAULT_KW SWITCH_IS_KW
42 %token TRANSMIT_AS_KW ARG_IS_KW
43 
44 /* composite keywords */
45 %token BASIC_TYPE TYPENAME
46 
47 /* symbols and punctuation */
48 %token IDENTIFIER INTEGER STRING
49 %token LC RC SEMI STAR DIV MOD PLUS MINUS AND OR XOR LB RB LP RP
50 
51 
52 %token L_MEMBER
53 
54 
55 %%
56 
57 defn	:	/* empty */
58 	|	construct_list	={ construct_list = (struct node *)$1; }
59 	;
60 
61 construct_list:	construct
62 	|	construct_list construct ={ n_splice ($1,$2); }
63 	;
64 
65 construct:	struct
66 	|	union
67 	|	typedef
68 	;
69 
70 struct	:	advice STRUCT_KW typename LC members RC SEMI
71 		={ $$ = n_cons (STRUCT_KW, $1, $3, $5);
72 		   construct_fixup ($$);
73 		}
74 	;
75 
76 union	:	advice UNION_KW typename LC members RC SEMI
77 		={ $$ = n_cons (UNION_KW, $1, $3, $5);
78 		   construct_fixup ($$);
79 		}
80 	;
81 
82 typedef	:	TYPEDEF_KW member
83 		={ $$ = n_cons (TYPEDEF_KW, 0, $2->n_m_name, $2);
84 		   construct_fixup ($$);
85 		}
86 	;
87 
88 members	:	member
89 	|	members member		 ={ n_splice ($1,$2); }
90 	;
91 
92 member	:	advice type declarator SEMI
93 		={ $$ = n_cons (L_MEMBER, $1, $2, $3);
94 		   member_fixup ($$);
95 		}
96 	;
97 
98 advice	:	/* empty */		={ $$ = 0; }
99 	|	adv_list
100 	;
101 
102 adv_list:	LB adv_attrs RB		={ $$ = $2; }
103 	|	adv_list LB adv_attrs RB ={ n_splice ($1,$3); }
104 	;
105 
106 adv_attrs:	adv_attr
107 	|	adv_attr adv_attr	={ n_splice ($1,$2); }
108 	;
109 
110 adv_attr:	IN_KW			={ $$ = n_cons (IN_KW); }
111 	|	OUT_KW			={ $$ = n_cons (OUT_KW); }
112 	|	OPERATION_KW LP arg RP	={ $$ = n_cons (OPERATION_KW, $3); }
113 	|	ALIGN_KW LP arg RP	={ $$ = n_cons (ALIGN_KW, $3); }
114 	|	STRING_KW		={ $$ = n_cons (STRING_KW); }
115 
116 	|	SIZE_IS_KW LP arg RP
117 				={ $$ = n_cons (SIZE_IS_KW, $3, $3, $3); }
118 	|	SIZE_IS_KW LP arg operator INTEGER RP
119 				={ $$ = n_cons (SIZE_IS_KW, $3, $4, $5); }
120 
121 	|	LENGTH_IS_KW LP arg RP
122 				={ $$ = n_cons (LENGTH_IS_KW, $3, $3, $3); }
123 	|	LENGTH_IS_KW LP arg operator INTEGER RP
124 				={ $$ = n_cons (LENGTH_IS_KW, $3, $4, $5); }
125 
126 	|	SWITCH_IS_KW LP arg RP
127 				={ $$ = n_cons (SWITCH_IS_KW, $3, $3, $3); }
128 	|	SWITCH_IS_KW LP arg operator INTEGER RP
129 				={ $$ = n_cons (SWITCH_IS_KW, $3, $4, $5); }
130 
131 	|	CASE_KW LP arg RP	={ $$ = n_cons (CASE_KW, $3); }
132 	|	DEFAULT_KW		={ $$ = n_cons (DEFAULT_KW); }
133 
134 	|	ARG_IS_KW LP arg RP	={ $$ = n_cons (ARG_IS_KW, $3); }
135 	|	TRANSMIT_AS_KW LP BASIC_TYPE RP
136 					={ $$ = n_cons (TRANSMIT_AS_KW, $3); }
137 
138 	|	INTERFACE_KW LP arg RP	={ $$ = n_cons (INTERFACE_KW, $3); }
139 	|	UUID_KW LP arg RP	={ $$ = n_cons (UUID_KW, $3); }
140 	|	_NO_REORDER_KW		={ $$ = n_cons (_NO_REORDER_KW); }
141 	|	EXTERN_KW		={ $$ = n_cons (EXTERN_KW); }
142 	|	REFERENCE_KW		={ $$ = n_cons (REFERENCE_KW); }
143 	;
144 
145 arg	:	IDENTIFIER
146 	|	INTEGER
147 	|	STRING
148 	;
149 
150 type	:	BASIC_TYPE
151 	|	typename
152 	|	STRUCT_KW typename	={ $$ = $2; }
153 	|	UNION_KW  typename	={ $$ = $2; }
154 	;
155 
156 typename:	TYPENAME
157 	|	IDENTIFIER
158 	;
159 
160 operator:	STAR
161 	|	DIV
162 	|	MOD
163 	|	PLUS
164 	|	MINUS
165 	|	AND
166 	|	OR
167 	|	XOR
168 	;
169 
170 declarator:	decl1
171 	;
172 
173 decl1	:	decl2
174 	|	STAR decl1		={ $$ = n_cons (STAR, $2); }
175 	;
176 
177 decl2	:	decl3
178 	|	decl3 LB RB		={ $$ = n_cons (LB, $1, 0); }
179 	|	decl3 LB STAR RB	={ $$ = n_cons (LB, $1, 0); }
180 	|	decl3 LB INTEGER RB	={ $$ = n_cons (LB, $1, $3); }
181 	;
182 
183 decl3	:	IDENTIFIER
184 	|	LP decl1 RP		={ $$ = n_cons (LP, $2); }
185 	;
186 
187 
188 
189 %%
190