1: # include <stdio.h>
2: # include "constants.h"
3: # include "globals.h"
4: # include "y.tab.h"
5: # include <sccs.h>
6:
7: SCCSID(@(#)name.c 8.1 12/31/84)
8:
9:
10: /*
11: ** NAME -- Process an identifier or keyword token.
12: **
13: ** Name gets the identifier that follows in the std.
14: ** input, and checks if it is a keyword.
15: ** An identifier is defined as a sequence of
16: ** MAXNAME or fewer alphanumerics, starting with an
17: ** alphabetic character.
18: **
19: ** Parameters:
20: ** chr - the first character of the identifier
21: **
22: ** Returns:
23: ** Tokens.sp_name - for a user-defined name
24: ** Tokens.sp_struct_var -- if the name is declared
25: ** a structurw variable
26: ** other - lexical codes for keys
27: **
28: ** Side Effects:
29: ** Adds a token to the symbol space.
30: ** yylval is set to the new node in the space.
31: ** If the identifier is a keyword, sets Opcode to
32: ** op_code from tokens.y.
33: */
34:
35: name(chr)
36: char chr;
37: {
38: int lval;
39: register i;
40: char wbuf [MAXNAME + 1];
41: register char *cp;
42: register char c;
43: struct optab *op;
44: struct optab *getkey();
45: struct cvar *getcvar();
46: struct cvar *hold;
47:
48: c = chr;
49: cp = wbuf;
50: for (i = 0; i <= MAXNAME; i++)
51: {
52: lval = Cmap [c];
53: if (i < MAXNAME &&
54: (lval == ALPHA || lval == NUMBR))
55: {
56: *cp++ = c;
57: c = getch();
58: }
59: else if (lval == ALPHA || lval == NUMBR)
60: {
61: /* {i == MAXNAME && "c is legal" &&
62: * cp == &wbuf [MAXNAME]}
63: */
64: *cp = '\0';
65: yysemerr("name too long", wbuf);
66: /* chomp to end of identifier */
67:
68: do
69: {
70: c = getch();
71: lval = Cmap [c];
72: } while (lval == ALPHA || lval == NUMBR);
73: backup(c);
74:
75: /* take first MAXNAME characters as IDENTIFIER
76: * (non-key)
77: */
78: yylval.u_dn = addsym(salloc(wbuf));
79: return (Tokens.sp_name);
80: }
81: else
82: {
83: /* {cp <= &wbuf [MAXNAME] && i <= MAXNAME
84: * && "c is not part of id"}
85: */
86: backup(c);
87: *cp = '\0';
88: i = 0;
89: break;
90: }
91: }
92: op = getkey(wbuf);
93:
94: /* Is it a keyword ? */
95: if (op)
96: {
97: yylval.u_dn = addsym(op->op_term);
98: Opcode = op->op_code;
99: return (op->op_token);
100: }
101: /* user-defined name */
102: yylval.u_dn = addsym(salloc(wbuf));
103: hold = getcvar(wbuf);
104: if (hold != 0 && hold->c_type == opSTRUCT)
105: return(Tokens.sp_struct_var);
106: return (Tokens.sp_name);
107: }
Defined functions
name
defined in line
7; used 1 times