/* @(#)rpc_parse.c 2.1 88/08/01 4.0 RPCSRC */
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
* Mountain View, California 94043
static char sccsid
[] = "@(#)rpc_parse.c 1.4 87/04/28 (C) 1987 SMI";
* rpc_parse.c, Parser for the RPC protocol compiler
* Copyright (C) 1987 Sun Microsystems, Inc.
* return the next definition you see
defp
= ALLOC(definition
);
error("definition keyword expected");
scan(TOK_SEMICOLON
, &tok
);
STOREVAL(&defined
, defp
);
defp
->def_kind
= DEF_STRUCT
;
defp
->def_name
= tok
.str
;
tailp
= &defp
->def
.st
.decls
;
get_declaration(&dec
, DEF_STRUCT
);
decls
= ALLOC(decl_list
);
scan(TOK_SEMICOLON
, &tok
);
} while (tok
.kind
!= TOK_RBRACE
);
defp
->def_kind
= DEF_PROGRAM
;
defp
->def_name
= tok
.str
;
vtailp
= &defp
->def
.pr
.versions
;
vlist
= ALLOC(version_list
);
vlist
->vers_name
= tok
.str
;
plist
= ALLOC(proc_list
);
get_type(&plist
->res_prefix
, &plist
->res_type
, DEF_PROGRAM
);
if (streq(plist
->res_type
, "opaque")) {
error("illegal result type");
plist
->proc_name
= tok
.str
;
get_type(&plist
->arg_prefix
, &plist
->arg_type
, DEF_PROGRAM
);
if (streq(plist
->arg_type
, "opaque")) {
error("illegal argument type");
scan(TOK_SEMICOLON
, &tok
);
plist
->proc_num
= tok
.str
;
} while (tok
.kind
!= TOK_RBRACE
);
vlist
->vers_num
= tok
.str
;
scan(TOK_SEMICOLON
, &tok
);
scan2(TOK_VERSION
, TOK_RBRACE
, &tok
);
} while (tok
.kind
== TOK_VERSION
);
defp
->def
.pr
.prog_num
= tok
.str
;
defp
->def_kind
= DEF_ENUM
;
defp
->def_name
= tok
.str
;
tailp
= &defp
->def
.en
.vals
;
elist
= ALLOC(enumval_list
);
elist
->assignment
= NULL
;
scan3(TOK_COMMA
, TOK_RBRACE
, TOK_EQUAL
, &tok
);
if (tok
.kind
== TOK_EQUAL
) {
elist
->assignment
= tok
.str
;
scan2(TOK_COMMA
, TOK_RBRACE
, &tok
);
} while (tok
.kind
!= TOK_RBRACE
);
defp
->def_kind
= DEF_CONST
;
defp
->def_name
= tok
.str
;
scan2(TOK_IDENT
, TOK_STRCONST
, &tok
);
defp
->def_kind
= DEF_UNION
;
defp
->def_name
= tok
.str
;
get_declaration(&dec
, DEF_UNION
);
defp
->def
.un
.enum_decl
= dec
;
tailp
= &defp
->def
.un
.cases
;
while (tok
.kind
== TOK_CASE
) {
cases
= ALLOC(case_list
);
cases
->case_name
= tok
.str
;
get_declaration(&dec
, DEF_UNION
);
scan(TOK_SEMICOLON
, &tok
);
scan3(TOK_CASE
, TOK_DEFAULT
, TOK_RBRACE
, &tok
);
if (tok
.kind
== TOK_DEFAULT
) {
get_declaration(&dec
, DEF_UNION
);
defp
->def
.un
.default_decl
= ALLOC(declaration
);
*defp
->def
.un
.default_decl
= dec
;
scan(TOK_SEMICOLON
, &tok
);
defp
->def
.un
.default_decl
= NULL
;
defp
->def_kind
= DEF_TYPEDEF
;
get_declaration(&dec
, DEF_TYPEDEF
);
defp
->def_name
= dec
.name
;
defp
->def
.ty
.old_prefix
= dec
.prefix
;
defp
->def
.ty
.old_type
= dec
.type
;
defp
->def
.ty
.rel
= dec
.rel
;
defp
->def
.ty
.array_max
= dec
.array_max
;
get_declaration(dec
, dkind
)
get_type(&dec
->prefix
, &dec
->type
, dkind
);
if (streq(dec
->type
, "void")) {
scan2(TOK_STAR
, TOK_IDENT
, &tok
);
if (tok
.kind
== TOK_STAR
) {
if (peekscan(TOK_LBRACKET
, &tok
)) {
if (dec
->rel
== REL_POINTER
) {
error("no array-of-pointer declarations -- use typedef");
dec
->array_max
= tok
.str
;
scan(TOK_RBRACKET
, &tok
);
} else if (peekscan(TOK_LANGLE
, &tok
)) {
if (dec
->rel
== REL_POINTER
) {
error("no array-of-pointer declarations -- use typedef");
if (peekscan(TOK_RANGLE
, &tok
)) {
dec
->array_max
= "~0"; /* unspecified size, use max */
dec
->array_max
= tok
.str
;
if (streq(dec
->type
, "opaque")) {
if (dec
->rel
!= REL_ARRAY
&& dec
->rel
!= REL_VECTOR
) {
error("array declaration expected");
} else if (streq(dec
->type
, "string")) {
if (dec
->rel
!= REL_ARRAY
) {
error("variable-length array declaration expected");
get_type(prefixp
, typep
, dkind
)
(void) peekscan(TOK_INT
, &tok
);
(void) peekscan(TOK_INT
, &tok
);
if (dkind
!= DEF_UNION
&& dkind
!= DEF_PROGRAM
) {
error("voids allowed only inside union and program definitions");
error("expected type specifier");
(void) peekscan(TOK_INT
, &tok
);
(void) peekscan(TOK_INT
, &tok
);