1: #
   2: # include   <stdio.h>
   3: 
   4: # include   "constants.h"
   5: # include   "globals.h"
   6: 
   7: /*
   8: **  NAME -- Process an identifier or keyword token.
   9: **
  10: **	Name gets the identifier that follows in the std.
  11: **	input, and checks if it is a keyword.
  12: **	An identifier is defined as a sequence of
  13: **	MAXNAME or fewer alphanumerics, starting with an
  14: **	alphabetic character.
  15: **
  16: **	Parameters:
  17: **		chr - the first character of the identifier
  18: **
  19: **
  20: **	Returns:
  21: **		Tokens.sp_name - for a user-defined name
  22: **		Tokens.sp_struct_var -- if the name is declared
  23: **			a structurw variable
  24: **		other - lexical codes for keys
  25: **
  26: **	Side Effects:
  27: **		Adds a token to the symbol space.
  28: **		yylval is set to the new node in the space.
  29: **		If the identifier is a keyword, sets Opcode to
  30: **		op_code from tokens.y.
  31: **
  32: **	Defines:
  33: **		name()
  34: **
  35: **	Requires:
  36: **		yylval - to return a value for the token
  37: **		Cmap - to get character classes
  38: **		Opcode - to return opcodes of keywords
  39: **		Tokens - for the lex codes of NAMEs
  40: **		getch() - to get next character
  41: **		yysemerr() - to report buffer ovflo
  42: **		salloc() - to allocate place for a string
  43: **		addsym() - to add a symbol to the symbol space
  44: **		backup() - to push back a single char on the input stream
  45: **		getkey() - to search the keyword table for one
  46: **		getcvar() - to see if the id is a struct id
  47: **
  48: **	Called By:
  49: **		yylex()
  50: **
  51: **	Files:
  52: **		globals.h - for globals
  53: **		constants.h
  54: **
  55: **	Diagnostics:
  56: **		"name too long"	- along with the first
  57: **				  MAXNAME chars of the name,
  58: **				  (which is what the name is
  59: **				  truncated to)
  60: **
  61: **	History:
  62: **		first written - 4/19/78 (marc)
  63: */
  64: 
  65: name(chr)
  66: char        chr;
  67: {
  68:     int         lval;
  69:     register        i;
  70:     char            wbuf [MAXNAME + 1];
  71:     register char       *cp;
  72:     register char       c;
  73:     struct optab        *op;
  74:     extern struct optab *getkey();
  75:     extern struct cvar  *getcvar();
  76: 
  77:     c = chr;
  78:     cp = wbuf;
  79:     for (i = 0; i <= MAXNAME; i++)
  80:     {
  81:         lval = Cmap [c];
  82:         if (i < MAXNAME &&
  83:            (lval == ALPHA || lval == NUMBR))
  84:         {
  85:             *cp++ = c;
  86:             c = getch();
  87:         }
  88:         else if (lval == ALPHA || lval == NUMBR)
  89:         {
  90:             /* {i == MAXNAME && "c is legal" &&
  91: 			 *  cp == &wbuf [MAXNAME]}
  92: 			 */
  93:             *cp = '\0';
  94:             yysemerr("name too long", wbuf);
  95:             /* chomp to end of identifier */
  96: 
  97:             do
  98:             {
  99:                 c = getch();
 100:                 lval = Cmap [c];
 101:             }  while (lval == ALPHA || lval == NUMBR);
 102:             backup(c);
 103: 
 104:             /* take first MAXNAME characters as IDENTIFIER
 105: 			 * (non-key)
 106: 			 */
 107:             yylval = addsym(salloc(wbuf));
 108:             return (Tokens.sp_name);
 109:         }
 110:         else
 111:         {
 112:             /* {cp <= &wbuf [MAXNAME] && i <= MAXNAME
 113: 			 * && "c is not part of id"}
 114: 			 */
 115:             backup(c);
 116:             *cp = '\0';
 117:             i = 0;
 118:             break;
 119:         }
 120:     }
 121:     op = getkey(wbuf);
 122: 
 123:     /* Is it a keyword ? */
 124:     if (op)
 125:     {
 126:         yylval = addsym(op->op_term);
 127:         Opcode = op->op_code;
 128:         return (op->op_token);
 129:     }
 130:     /* user-defined name */
 131:     yylval = addsym(salloc(wbuf));
 132:     if (getcvar(wbuf)->c_type == opSTRUCT)
 133:         return(Tokens.sp_struct_var);
 134:     return (Tokens.sp_name);
 135: }

Defined functions

name defined in line 65; used 1 times
Last modified: 1995-04-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2550
Valid CSS Valid XHTML 1.0 Strict