1: # include   <stdio.h>
   2: # include   "constants.h"
   3: # include   "globals.h"
   4: # include   "y.tab.h"
   5: # include   <sccs.h>
   6: 
   7: SCCSID(@(#)operator.c	8.1	12/31/84)
   8: 
   9: 
  10: /*
  11: **  OPERATOR -- process a token starting with an operator
  12: **
  13: **	Processes operators, strings, comments, and
  14: **	floating constants without a leading 0.
  15: **
  16: **	Parameters:
  17: **		chr - first character of token {Cmap [chr] == OPATR}
  18: **
  19: **	Returns:
  20: **		NUMBER or STRING token, or operator token.
  21: **		CONTINUE on error.
  22: **
  23: **	Side Effects:
  24: **		Adds a node to the Symbol space, and returns adress
  25: **		in "yylval".
  26: **		Opcode is set to the opcode of the operator.
  27: **		May backup a character.
  28: */
  29: 
  30: operator(chr)
  31: char    chr;
  32: {
  33:     register struct optab   *op;
  34:     char            opbuf [3];
  35: 
  36:     opbuf [0] = chr;
  37:     opbuf [1] = getch();
  38:     opbuf [2] = '\0';
  39: 
  40:     if (opbuf [0] == '.' && Cmap [opbuf [1]] == NUMBR)
  41:     {
  42:         /* floating mantissa w/o leading 0 */
  43:         backup(opbuf [1]);
  44:         return (number(opbuf [0]));
  45:     }
  46:     if (Cmap [opbuf [1]] != OPATR)
  47:     {
  48:         backup(opbuf [1]);
  49:         opbuf [1] = '\0';
  50:     }
  51:     /* operator has been reduced to its smallest
  52: 	 * possible length, now try to find it in the
  53: 	 * operator table [tokens.y]
  54: 	 */
  55:     for ( ; ; )
  56:     {
  57:         for (op = Optab; op->op_term; op++)
  58:             if (sequal(op->op_term, opbuf))
  59:                 break;
  60:         if (!op->op_term && opbuf [1])
  61:         {
  62:             /* reduce a 2 char operator to 1 char,
  63: 			 * and re-search
  64: 			 */
  65:             backup(opbuf[1]);
  66:             opbuf [1] = '\0';
  67:             continue;
  68:         }
  69:         break;
  70:     }
  71:     if (op->op_term)
  72:     {
  73:         /* string quotes ? */
  74:         if (op->op_token == Tokens.sp_quote)
  75:             return (string(op));
  76: 
  77:         /* comment indicator ? */
  78:         if (op->op_token == Tokens.sp_bgncmnt)
  79:             return (comment());
  80: 
  81:         /* {sequal(opbuf, op->op_term)} */
  82:         Opcode = op->op_code;
  83:         yylval.u_dn = addsym(op->op_term);
  84:         return (op->op_token);
  85:     }
  86:     yysemerr("bad operator", opbuf);
  87: 
  88:     /* operator not found, skip token and try again */
  89:     return (CONTINUE);
  90: }

Defined functions

operator defined in line 7; used 1 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 964
Valid CSS Valid XHTML 1.0 Strict