version 1.5, 2001/11/24 19:17:47 |
version 1.6, 2001/11/24 19:19:59 |
|
|
#endif |
#endif |
|
|
/* |
/* |
* rpc_scan.c, Scanner for the RPC protocol compiler |
* rpc_scan.c, Scanner for the RPC protocol compiler |
* Copyright (C) 1987, Sun Microsystems, Inc. |
* Copyright (C) 1987, Sun Microsystems, Inc. |
*/ |
*/ |
#include <sys/cdefs.h> |
#include <sys/cdefs.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
|
static token lasttok; /* last token, if pushed */ |
static token lasttok; /* last token, if pushed */ |
|
|
/* |
/* |
* scan expecting 1 given token |
* scan expecting 1 given token |
*/ |
*/ |
void |
void |
scan(expect, tokp) |
scan(expect, tokp) |
|
|
token *tokp; |
token *tokp; |
{ |
{ |
get_token(tokp); |
get_token(tokp); |
if (tokp->kind != expect) |
if (tokp->kind != expect) { |
expected1(expect); |
expected1(expect); |
|
} |
} |
} |
|
|
/* |
/* |
* scan expecting any of the 2 given tokens |
* scan expecting any of the 2 given tokens |
*/ |
*/ |
void |
void |
scan2(expect1, expect2, tokp) |
scan2(expect1, expect2, tokp) |
|
|
token *tokp; |
token *tokp; |
{ |
{ |
get_token(tokp); |
get_token(tokp); |
if (tokp->kind != expect1 && tokp->kind != expect2) |
if (tokp->kind != expect1 && tokp->kind != expect2) { |
expected2(expect1, expect2); |
expected2(expect1, expect2); |
|
} |
} |
} |
|
|
/* |
/* |
* scan expecting any of the 3 given token |
* scan expecting any of the 3 given token |
*/ |
*/ |
void |
void |
scan3(expect1, expect2, expect3, tokp) |
scan3(expect1, expect2, expect3, tokp) |
|
|
token *tokp; |
token *tokp; |
{ |
{ |
get_token(tokp); |
get_token(tokp); |
if (tokp->kind != expect1 && tokp->kind != expect2 && |
if (tokp->kind != expect1 && tokp->kind != expect2 |
tokp->kind != expect3) |
&& tokp->kind != expect3) { |
expected3(expect1, expect2, expect3); |
expected3(expect1, expect2, expect3); |
|
} |
} |
} |
|
|
/* |
/* |
* scan expecting a constant, possibly symbolic |
* scan expecting a constant, possibly symbolic |
*/ |
*/ |
void |
void |
scan_num(tokp) |
scan_num(tokp) |
|
|
} |
} |
|
|
/* |
/* |
* Peek at the next token |
* Peek at the next token |
*/ |
*/ |
void |
void |
peek(tokp) |
peek(tokp) |
|
|
} |
} |
|
|
/* |
/* |
* Peek at the next token and scan it if it matches what you expect |
* Peek at the next token and scan it if it matches what you expect |
*/ |
*/ |
int |
int |
peekscan(expect, tokp) |
peekscan(expect, tokp) |
|
|
} |
} |
|
|
/* |
/* |
* Get the next token, printing out any directive that are encountered. |
* Get the next token, printing out any directive that are encountered. |
*/ |
*/ |
void |
void |
get_token(tokp) |
get_token(tokp) |
|
|
if (commenting) { |
if (commenting) { |
break; |
break; |
} else if (cppline(curline)) { |
} else if (cppline(curline)) { |
docppline(curline, &linenum, |
docppline(curline, &linenum, |
&infilename); |
&infilename); |
} else if (directive(curline)) { |
} else if (directive(curline)) { |
printdirective(curline); |
printdirective(curline); |
} else { |
} else { |
|
|
} |
} |
|
|
/* |
/* |
* 'where' is not whitespace, comment or directive Must be a token! |
* 'where' is not whitespace, comment or directive Must be a token! |
*/ |
*/ |
switch (*where) { |
switch (*where) { |
case ':': |
case ':': |
|
|
} |
} |
|
|
static token symbols[] = { |
static token symbols[] = { |
{TOK_CONST, "const"}, |
{TOK_CONST, "const"}, |
{TOK_UNION, "union"}, |
{TOK_UNION, "union"}, |
{TOK_SWITCH, "switch"}, |
{TOK_SWITCH, "switch"}, |
{TOK_CASE, "case"}, |
{TOK_CASE, "case"}, |
{TOK_DEFAULT, "default"}, |
{TOK_DEFAULT, "default"}, |
{TOK_STRUCT, "struct"}, |
{TOK_STRUCT, "struct"}, |
{TOK_TYPEDEF, "typedef"}, |
{TOK_TYPEDEF, "typedef"}, |
{TOK_ENUM, "enum"}, |
{TOK_ENUM, "enum"}, |
{TOK_OPAQUE, "opaque"}, |
{TOK_OPAQUE, "opaque"}, |
{TOK_BOOL, "bool"}, |
{TOK_BOOL, "bool"}, |
{TOK_VOID, "void"}, |
{TOK_VOID, "void"}, |
{TOK_CHAR, "char"}, |
{TOK_CHAR, "char"}, |
{TOK_INT, "int"}, |
{TOK_INT, "int"}, |
{TOK_UNSIGNED, "unsigned"}, |
{TOK_UNSIGNED, "unsigned"}, |
{TOK_SHORT, "short"}, |
{TOK_SHORT, "short"}, |
{TOK_LONG, "long"}, |
{TOK_LONG, "long"}, |
{TOK_FLOAT, "float"}, |
{TOK_FLOAT, "float"}, |
{TOK_DOUBLE, "double"}, |
{TOK_DOUBLE, "double"}, |
{TOK_STRING, "string"}, |
{TOK_STRING, "string"}, |
{TOK_PROGRAM, "program"}, |
{TOK_PROGRAM, "program"}, |
{TOK_VERSION, "version"}, |
{TOK_VERSION, "version"}, |
{TOK_EOF, "??????"}, |
{TOK_EOF, "??????"}, |
}; |
}; |
|
|
static |
static |