1: #
   2: # include   <stdio.h>
   3: 
   4: # include   "constants.h"
   5: # include   "globals.h"
   6: 
   7: 
   8: 
   9: int yyline;
  10: 
  11: /*
  12: **  YYLEX -- Lexical analyzer
  13: **	Yylex controls the return to the parser of lexemes,
  14: **	and the copying out of C_CODE on the all to yylex
  15: **	after yylex() returned the C_CODE.
  16: **
  17: **	Returns:
  18: **		Lexical tokens.
  19: **
  20: **	Side Effects:
  21: **		Copies C code out on call after seeing it.
  22: **		Puts terminals in symbol space.
  23: **
  24: **	Called By:
  25: **		Yacc internals (yyparse()).
  26: **
  27: **	History:
  28: **		6/1/78 -- (marc) modified from the yylex
  29: **			of the old equel by jim ford
  30: */
  31: 
  32: 
  33: 
  34: yylex()
  35: {
  36:     register int        rtval;
  37:     register char       chr;
  38:     extern char     *yysterm [];
  39: 
  40: 
  41: 
  42:     /* get next token */
  43:     rtval = CONTINUE;
  44: 
  45:     while (rtval == CONTINUE)
  46:     {
  47:         if (C_code_flg)
  48:         {
  49:             copy_c_code();
  50:             Newline = 1;
  51:         }
  52:         Pre_proc_flg = 0;
  53: 
  54:         /* END OF FILE ? */
  55:         if ((chr = getch()) == EOF_TOK)
  56:         {
  57: #			ifdef xDEBUG
  58:             if (Lex_debug)
  59:                 printf("end of file\n");
  60: #			endif
  61:             return (0);
  62:         }
  63: 
  64:         /* Test for a line of C code */
  65:         if (Newline && if_c_code(chr))
  66:         {
  67:             if (C_code_flg)
  68:                 continue;
  69:             rtval = Tokens.sp_c_code;
  70:             C_code_flg = 1;
  71:             break;
  72:         }
  73:         else
  74:         {
  75:             C_code_flg = 0;
  76:             if (Newline)
  77:             {
  78:                 Newline = 0;
  79:                 continue;
  80:             }
  81:         }
  82: 
  83:         /* CARRIAGE CONTROL ? */
  84:         Newline = chr == '\n';
  85: 
  86:         switch (Cmap [chr])
  87:         {
  88: 
  89:           case PUNCT :
  90:             continue;
  91: 
  92:           case OPATR :
  93:             rtval = operator(chr);
  94:             break;
  95: 
  96:           case NUMBR :
  97:             rtval = number(chr);
  98:             break;
  99: 
 100:           case ALPHA :
 101:             rtval = name(chr);
 102:             break;
 103: 
 104:         }
 105:     }
 106:     if (Lex_debug)
 107:         printf("YYLEX : %s: '%s'\n", yysterm [rtval - 256],
 108:         yylval ? ((struct disp_node *)yylval)->d_elm : "");
 109:     return (rtval);
 110: }
 111: 
 112: /*
 113: **  COPY_C_CODE -- Copies out a line of C code
 114: **	The test for Charcnt != 0 is beacuse if a C pre-processor
 115: **	line follows an equel line, and equate_lines() puts out no
 116: **	newline, the initial '#' will not be on the beginning of
 117: **	the line. As is, if this should happen, then the line
 118: **	with the '#' will be one line in the output ahead of
 119: **	where it should be.
 120: **
 121: **	History:
 122: **		6/1/78 -- (marc) written from original
 123: **			by j.f.
 124: **		8/30/78 -- (marc) Charcnt test added
 125: */
 126: 
 127: 
 128: char *copy_c_code()
 129: {
 130:     char    ch [2];
 131: 
 132: 
 133:     ch [1] = 0;
 134:     equate_lines();
 135:     if (Pre_proc_flg)
 136:     {
 137:         if (Charcnt != 0)
 138:             w_raw("\n");
 139:         w_raw("#");
 140:     }
 141:     do
 142:     {
 143:         if ((*ch = getch()) == EOF_TOK)
 144:             return (ch);
 145:         w_raw(ch);
 146:     } while (*ch != '\n');
 147: }
 148: 
 149: 
 150: 
 151: /*
 152: **  IF_C_CODE -- Test to see if a line is C code
 153: **
 154: **	Sees if a line begins with "##" to see if it is equel.
 155: **
 156: **	Parameters:
 157: **		chr -- first char of line
 158: **
 159: **	Returns:
 160: **		0 -- Quel line
 161: **		1 -- C line
 162: **
 163: **	Called By:
 164: **		yylex()
 165: **
 166: **	History:
 167: **		6/1/78 -- (marc) written
 168: */
 169: 
 170: 
 171: if_c_code(chr)
 172: char    chr;
 173: {
 174:     for ( ; ; )
 175:     {
 176:         if (chr != '#')
 177:         {
 178:             backup(chr);
 179:             return (1);
 180:         }
 181:         Pre_proc_flg = 1;
 182:         if ((chr = getch()) == EOF_TOK)
 183:         {
 184:             return (0);
 185:         }
 186:         if (chr != '#')
 187:         {
 188:             backup(chr);
 189:             return (1);
 190:         }
 191:         else
 192:         {
 193:             return (0);
 194:         }
 195:     }
 196: }

Defined functions

copy_c_code defined in line 128; used 1 times
  • in line 49
if_c_code defined in line 171; used 1 times
  • in line 65
yylex defined in line 34; used 1 times

Defined variables

Last modified: 1995-04-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3137
Valid CSS Valid XHTML 1.0 Strict