1: # include "../ingres.h"
2: # include "../scanner.h"
3:
4: /*
5: ** NAME
6: ** A name is defined to be a sequence of MAXNAME or fewer alphanumeric
7: ** characters, starting with an alphabetic (underscore "_" is considered
8: ** an alphabetic). If it is not a keyword, each name is entered into
9: ** the symbol table, indexed by 'yylval'. A token is then returned for
10: ** that name.
11: */
12: name(chr)
13: char chr;
14: {
15: extern char *yylval;
16: extern char Cmap[];
17: char namebuf[MAXNAME + 1];
18: register int hi, lo, curr;
19: extern char *syment();
20:
21: /* fill in the name */
22: yylval = namebuf;
23: *yylval = chr;
24: do
25: {
26: *++yylval = gtchar();
27: if ((yylval - namebuf) > MAXNAME)
28: {
29: /* name too long */
30: *yylval = '\0';
31: yyerror(NAMELONG, namebuf, 0);
32: }
33:
34: } while (Cmap[*yylval] == ALPHA || Cmap[*yylval] == NUMBR);
35: backup(*yylval);
36: *yylval = '\0';
37:
38: /* is it a keyword ? */
39: lo = 0;
40: hi = Keyent - 1;
41: while (lo <= hi)
42: {
43: curr = (lo + hi) / 2;
44: switch (scompare(Keyword[curr].term, MAXNAME, namebuf, MAXNAME))
45: {
46: case 1:
47: hi = curr - 1;
48: continue;
49:
50: case -1:
51: lo = curr + 1;
52: continue;
53:
54: case 0:
55: Lastok.toktyp = Tokens.sconst;
56: Lastok.tok = Keyword[curr].term;
57: Lastok.tokop = Keyword[curr].opcode;
58: yylval = (char *) Keyword[curr].opcode;
59: return (Keyword[curr].token);
60: }
61: }
62:
63: /* else, USER DEFINED NAME */
64: # ifdef xSTR2
65: tTfp(71, 0, "name: %s\n", namebuf);
66: # endif
67: yylval = syment(namebuf, length(namebuf) + 1);
68: Lastok.tok = yylval;
69: Lastok.toktyp = Tokens.sconst;
70: Lastok.tokop = 0;
71: return (Tokens.name);
72: }
Defined functions
name
defined in line
12; used 2 times