1: #
   2: #include "ne.h"
   3: #include "y.tab.c"
   4: 
   5: char *cntrl[] {
   6:     "sup", "super", "sub",
   7:     ".EN",
   8:     "sum", "from", "to",
   9:     "hat", "dot", "dotdot", "bar", "tilde", "under",
  10:     "prod", "int", "integral", "union", "inter",
  11:     "pile", "lpile", "cpile", "rpile", "over", "sqrt",
  12:     "above", "size", "font", "roman", "italic", "bold",
  13:     "left", "right",
  14:     "delim", "DELIM",
  15:     "DEFINE","define",
  16:     ".gsize", ".GSIZE", "gsize", "GSIZE", "gfont", "GFONT",
  17:     "HAT", "DOT", "DOTDOT", "BAR", "TILDE", "UNDER",
  18:     "PROD", "INT", "INTEGRAL", "UNION", "INTER",
  19:     "SUM", "FROM", "TO",
  20:     "SUP", "SUPER", "SUB", "PILE", "LPILE", "CPILE", "RPILE", "OVER", "SQRT",
  21:     "ABOVE", "SIZE", "FONT", "ROMAN", "ITALIC", "BOLD",
  22:     "LEFT", "RIGHT",
  23:     "up", "UP", "down", "DOWN", "fwd", "FWD", "back", "BACK",
  24:     "mark", "MARK", "lineup", "LINEUP",
  25:     "matrix", "lcol", "ccol", "rcol", "col",
  26:     0};
  27: 
  28: 
  29: int icntrl[]{
  30:     SUPER, SUPER, SUB,
  31:     0, /* EOF */
  32:     SUM, FROM, TO,
  33:     HAT, DOT, DOTDOT, BAR, TILDE, UNDER,
  34:     PROD, INT, INT, UNION, INTER,
  35:     PILE, LPILE, CPILE, RPILE, OVER, SQRT,
  36:     ABOVE, SIZE, FONT, ROMAN, ITALIC, BOLD,
  37:     LEFT, RIGHT,
  38:     DELIM, DELIM,
  39:     DEFINE, DEFINE,
  40:     GSIZE, GSIZE, GSIZE, GSIZE, GFONT, GFONT,
  41:     HAT, DOT, DOTDOT, BAR, TILDE, UNDER,
  42:     PROD, INT, INT, UNION, INTER,
  43:     SUM, FROM, TO,
  44:     SUPER, SUPER, SUB, PILE, LPILE, CPILE, RPILE, OVER, SQRT,
  45:     ABOVE, SIZE, FONT, ROMAN, ITALIC, BOLD,
  46:     LEFT, RIGHT,
  47:     UP, UP, DOWN, DOWN, FWD, FWD, BACK, BACK,
  48:     MARK, MARK, LINEUP, LINEUP,
  49:     MATRIX, LCOL, CCOL, RCOL, COL,
  50:     0};
  51: 
  52: int peek    -1;
  53: #define SSIZE   400
  54: char    token[SSIZE];
  55: int sp;
  56: int speek[10];
  57: char *swt[10];
  58: int sw -1;
  59: 
  60: getc(){
  61:   loop:
  62:     if(sw >= 0){
  63:         lastchar = (peek<0) ? *swt[sw]++ : peek;
  64:         peek = -1;
  65:         if(lastchar != '\0')return(lastchar);
  66:         peek = speek[sw--];
  67:         return(' ');
  68:         }
  69:     lastchar = (peek<0) ? getchar() : peek;
  70:     if( lastchar=='\n' )
  71:         linect++;
  72:     peek = -1;
  73:     if( lastchar!= '\0' )
  74:         return(lastchar);
  75:     if( ++ifile > svargc ){
  76:         peek = '\0';
  77:         return('\0');
  78:     }
  79:     close(fin);
  80:     linect = 1;
  81:     if( (fin=open(svargv[ifile],0)) >= 0 )
  82:         goto loop;
  83:     error(FATAL,"can't open file %s\n", svargv[ifile]);
  84: }
  85: 
  86: yylex(){
  87:     int c, type;
  88:   beg:
  89:     while( (c=getc())==' ' || c=='\n');
  90:     yylval=c;
  91:     switch(c){
  92: 
  93:     case '\0':
  94:         return('\0');
  95:     case '~':
  96:         return(SPACE);
  97:     case '^':
  98:         return(THIN);
  99:     case '\t':
 100:         return(TAB);
 101:     case '{':
 102:         return(MQ);
 103:     case '}':
 104:         return(MQ1);
 105:     case '"':
 106:         for(sp=0; (c=getc())!='"'; ){
 107:             if(c !='\\')token[sp++]=c;
 108:             else { if((c=getc())!= '"')token[sp++]='\\';
 109:                 token[sp++] = c; }
 110:             if( sp>=SSIZE )
 111:                 error(FATAL,"quoted string %.20s... too long", token);
 112:         }
 113:         token[sp]='\0';
 114:         yylval= &token[0];
 115:         return(QTEXT);
 116:     }
 117:     if( c==righteq )
 118:         return('\0');
 119: 
 120:     getstr(token, c);
 121:     if((type = lookup(token,nptr)) >= 0){
 122:         if(sw >= 9)
 123:             error(FATAL,"definitions nested > 9", sw);
 124:         swt[++sw] = sptr[type];
 125:         speek[sw] = peek;
 126:         peek = -1;
 127:         goto beg;
 128:         }
 129:     type = lookup(token,cntrl);
 130:     if( type < 0 )
 131:         return(CONTIG);
 132:     if( icntrl[type]==DEFINE ) {
 133:         define();
 134:         goto beg;
 135:     }
 136:     else if( icntrl[type]==DELIM ) {
 137:         delim();
 138:         goto beg;
 139:     }
 140:     else if( icntrl[type]==GSIZE ){
 141:         globsize();
 142:         goto beg;
 143:     }
 144:     else if( icntrl[type]==GFONT ) {
 145:         globfont();
 146:         goto beg;
 147:     }
 148:     else
 149:         return( icntrl[type] );
 150: }
 151: 
 152: getstr(s,c) char *s, c; {
 153:     for (sp=0; c!=' ' && c!='\t' && c!='\n' && c!='{' && c!='}'
 154:         && c!='"' && c!='~' && c!='^' && c!=righteq; ) {
 155:         if(c == '\\') if((c = getc()) != '"')s[sp++] = '\\';
 156:         s[sp++] = c;
 157:         if( sp>=SSIZE )
 158:             error(FATAL,"token %.20s... too long",s);
 159:         c = getc();
 160:         }
 161:     if( c=='{' || c=='}' || c=='"' || c=='~' || c=='^' || c=='\t' || c==righteq )
 162:         peek = c;
 163:     s[sp]='\0';
 164:     yylval = s;
 165: }
 166: 
 167: lookup(str,tbl) char *str; char *tbl[]; {
 168:     register i,j, r;
 169:     for(i=0; tbl[i]!=0; i++){ /* table of tbl wds */
 170:         for( j=0; (r=tbl[i][j])==str[j] && r!='\0'; j++);
 171:         if( r == str[j] )
 172:             return(i);
 173:     }
 174:     return( -1 );
 175: }
 176: 
 177: cstr(s,quote) char *s; int quote; {
 178:     int del,c,i;
 179:     while((del=getc()) == ' ' || del == '\t' || del == '\n');
 180:     if(quote)
 181:         for(i=0; (c=getc()) != del;)
 182:             s[i++] = c;
 183:     else {
 184:         s[0] = del;
 185:         for(i=1; (c=getc())!=' ' && c!= '\t' && c!='\n';)
 186:             s[i++]=c;
 187:     }
 188:     s[i] = '\0';
 189:     return(s);
 190: }
 191: 
 192: define() {
 193:     char *alloc();
 194:     int i, c;
 195:     while( (c=getc())==' ' || c=='\n' );
 196:     getstr(token,c);
 197:     if((i = lookup(token,nptr)) >= 0){
 198:         yyval = i;
 199:         free(sptr[yyval]);
 200:     } else {
 201:         yyval = ptr++;
 202:         for(i=0; token[i] != '\0'; i++);
 203:         nptr[yyval] = alloc(i+1);
 204:         for(i=0; nptr[yyval][i]=token[i]; i++);
 205:     }
 206:     if(dbg)printf(".\tdefine %s\n",nptr[yyval]);
 207:     cstr(token,1);
 208:     for(i=0; token[i] != '\0'; i++);
 209:     sptr[yyval] = alloc(i+1);
 210:     for(i=0; sptr[yyval][i] = token[i]; i++);
 211:     if(dbg)printf(".\tname %s defined as %s\n",nptr[yyval],sptr[yyval]);
 212: }
 213: 
 214: delim() {
 215:     char *s;
 216:     yyval = eqnreg = 0;
 217:     cstr(token,0);
 218:     lefteq = token[0];
 219:     righteq = token[1];
 220:     if( (lefteq == 'o' && righteq == 'f') || (lefteq == 'O' && righteq == 'F') )
 221:         lefteq = righteq = '\0';
 222: }
 223: 
 224: globsize() {
 225:     extern int gsize;
 226:     int c;
 227:     while( (c=getc())==' ' || c=='\n' );
 228:     getstr(token,c);
 229:     gsize = numb(token);
 230:     yyval = eqnreg = 0;
 231: }
 232: 
 233: globfont() {
 234:     extern int gfont;
 235:     while( (gfont=getc())==' ' || gfont=='\n' );
 236:     yyval = eqnreg = 0;
 237: }

Defined functions

cstr defined in line 177; used 2 times
define defined in line 192; used 1 times
delim defined in line 214; used 1 times
getc defined in line 60; used 13 times
getstr defined in line 152; used 3 times
globfont defined in line 233; used 1 times
globsize defined in line 224; used 1 times
lookup defined in line 167; used 4 times
yylex defined in line 86; never used

Defined variables

cntrl defined in line 5; used 1 times
icntrl defined in line 29; used 5 times
peek defined in line 52; used 11 times
sp defined in line 55; used 11 times
speek defined in line 56; used 2 times
sw defined in line 58; used 7 times
swt defined in line 57; used 2 times
token defined in line 54; used 21 times

Defined macros

SSIZE defined in line 53; used 3 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1001
Valid CSS Valid XHTML 1.0 Strict