# 2.11BSD#431 - /usr/src/new/PORT/B/src/bsmall/b2syn.c

##### Functions

    ateol             X
    atkw              X
    close_stream      X
    count             X
    fcol              X
    find              X
    findceol          X
    findkw            X
    getline           X
    ilev              X
    inistreams        X
    keyword           X
    lcol              X
    need              X
    nothing           X
    open_stream       X
    re_streams        X
    req               X
    reqkw             X
    start_stream      X
    tag               X
    thought           X
    upto              X
    veli              X

##### Variables

    Procedure         X
    Visible           X
    alino             X
    tagbuf            X
    tagbufend         X
    txbuf             X
    txbufstart        X

##### Macros

    Interactive       X
    Otherwise         X
    TAGBUFSIZE        X
    TXBUFSIZE         X
    Where_inside      X

       1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
       2: /* $Header: b2syn.c,v 1.1 84/06/28 00:49:21 timo Exp $ */
       3:
       4: /* General parsing routines for B interpreter */
       5: #include "b.h"
       6: #include "b1obj.h"
       7: #include "b0con.h" /*for CLEAR_EOF*/
       8: #include "b2env.h"
       9: #include "b2scr.h"
      10: #include "b2syn.h"
      11:
      12: Visible Procedure upto(q, ff) txptr q; string ff; {
      13:     Skipsp(tx);
      14:     if (tx < q) parerr("something unexpected following ", ff);
      15: }
      16:
      17: Visible Procedure nothing(q, xp) txptr q; string xp; {
      18:     if (tx >= q) {
      19:         if (Char(tx-1) == ' ') tx--;
      20:         parerr("nothing instead of expected ", xp);
      21:     }
      22: }
      23:
      24: Visible bool ateol() {
      25:     Skipsp(tx);
      26:     if (Ceol(tx)) {
      27:         To_eol(tx);
      28:         return Yes;
      29:     }
      30:     return No;
      31: }
      32:
      33: #define Where_inside(r, t) \
      34:     register txptr ttx= tx; char lc= '+', q; \
      35:     register intlet parcnt= 0; register bool outs= Yes; bool kw= No; \
      36:     while (r) \
      37:     if (outs) { \
      38:         if (parcnt == 0 && (t))
      39: #define Otherwise \
      40:         if (Char(ttx) == '(' || Char(ttx) == '[' || Char(ttx) == '{') \
      41:             parcnt++; \
      42:         else if (Char(ttx) == ')' || Char(ttx) == ']' || Char(ttx) == '}') { \
      43:             if (parcnt > 0) parcnt--; \
      44:         } else if ((Char(ttx) == '\'' || Char(ttx) == '"') && !Keytagmark(lc)) { \
      45:             outs= No; q= Char(ttx); \
      46:         } \
      47:         lc= Char(ttx++); kw= kw ? Keymark(lc) : Cap(lc); \
      48:     } else { \
      49:         if (Char(ttx) == q) { \
      50:             outs= Yes; kw= No; lc= '+'; \
      51:         } else if (!outs && Char(ttx) == '`') { \
      52:             txptr tx0= tx, yx, zx; \
      53:             tx= ttx+1; \
      54:             req("`", lcol(), &yx, &zx); \
      55:             ttx= yx; tx= tx0; \
      56:         } \
      57:         ttx++; \
      58:     }
      59:
      60: Visible Procedure findceol() {
      61:     Where_inside (!Eol(ttx), Char(ttx) == '\\') {
      62:         ceol= ttx;
      63:         return;
      64:     } Otherwise ceol= ttx;
      65: }
      66:
      67: Visible bool atkw(ss) register string ss; {
      68:     register txptr tp= tx;
      69:     while (*ss) if (*ss++ != Char(tp++)) return No;
      70:     if (Keymark(Char(tp))) return No;
      71:     tx= tp;
      72:     return Yes;
      73: }
      74:
      75: Visible Procedure need(ss) string ss; {
      76:     register string sp= ss;
      77:     Skipsp(tx);
      78:     while (*sp) if (*sp++ != Char(tx++))
      79:         pprerr("according to the syntax I expected ", ss);
      80: }
      81:
      82: Visible Procedure thought(c) register char c; {
      83:     Skipsp(tx);
      84:     if (Char(tx++) != c) syserr("I'm confused; can't trust me own eyes");
      85: }
      86:
      87: Visible Procedure reqkw(ss, ptx, qtx) string ss; txptr *ptx, *qtx; {
      88:     Where_inside (!Eol(ttx), Char(ttx) == *ss && !kw) {
      89:         string sp= ss+1;
      90:         *qtx= (*ptx= ttx)+1;
      91:         while (*sp) if (*sp++ != Char((*qtx)++)) goto isnt;
      92:         if (Keymark(Char(*qtx))) goto isnt;
      93:         return;
      94:     }
      95: isnt:   Otherwise parerr("cannot find expected ", ss);
      96: }
      97:
      98: Visible Procedure req(ss, utx, ptx, qtx) string ss; txptr utx, *ptx, *qtx; {
      99:     Where_inside (ttx < utx && !Eol(ttx), Char(ttx) == *ss) {
     100:         string sp= ss+1;
     101:         *qtx= (*ptx= ttx)+1;
     102:         while (*sp && *qtx < utx) if (*sp++ != Char((*qtx)++)) goto isnt;
     103:         return;
     104:     }
     105: isnt:   Otherwise parerr("cannot find expected ", ss);
     106: }
     107:
     108: Visible bool find(ss, utx, ptx, qtx) string ss; txptr utx, *ptx, *qtx; {
     109:     Where_inside (ttx < utx, Char(ttx) == *ss && !(kw && Cap(*ss))) {
     110:         string sp= ss+1;
     111:         *qtx= (*ptx= ttx)+1;
     112:         while (*sp && *qtx < utx) if (*sp++ != Char((*qtx)++)) goto isnt;
     113:         if (Cap(*ss) && Keymark(Char(*qtx))) goto isnt;
     114:         return Yes;
     115:     }
     116: isnt:   Otherwise return No;
     117: }
     118:
     119: Visible intlet count(ss, utx) string ss; txptr utx; {
     120:     intlet cnt= 0;
     121:     Where_inside (ttx < utx, Char(ttx) == *ss) {
     122:         string sp= ss+1; txptr tp= ttx+1;
     123:         while (*sp && tp < utx) if (*sp++ != Char(tp++)) goto isnt;
     124:         cnt++;
     125:     }
     126: isnt:   Otherwise return cnt;
     127: }
     128:
     129: #define TAGBUFSIZE 100
     130: char tagbuf[TAGBUFSIZE];
     131: txptr tagbufend= &tagbuf[TAGBUFSIZE];
     132:
     133: Visible value tag() {
     134:     txptr tp= tagbuf; value res= Vnil;
     135:     Skipsp(tx);
     136:     if (!Letter(Char(tx))) return Vnil;
     137:     while (Tagmark(Char(tx))) {
     138:         *tp++= Char(tx++);
     139:         if (tp+1 >= tagbufend) {
     140:             *tp= '\0';
     141:             concat_to(&res, tagbuf);
     142:             tp= tagbuf;
     143:         }
     144:     }
     145:     *tp= '\0';
     146:     concat_to(&res, tagbuf);
     147:     return(res);
     148: }
     149:
     150: Visible value findkw(u, f, t) txptr u, *f, *t; {
     151:     txptr sp= tx, kp= tagbuf; value word= Vnil;
     152:     while (sp < u && !Cap(Char(sp))) sp++;
     153:     *f= sp;
     154:     while (sp < u && Keymark(Char(sp))) {
     155:         *kp++= Char(sp++);
     156:         if (kp+1 >= tagbufend) {
     157:             *kp= '\0';
     158:             concat_to(&word, tagbuf);
     159:             kp= tagbuf;
     160:         }
     161:     }
     162:     *kp= '\0';
     163:     concat_to(&word, tagbuf);
     164:     *t= sp; /* if no keyword is found, f and t are set to u */
     165:     return(word);
     166: }
     167:
     168: Visible value keyword(u) txptr u; {
     169:     txptr f;
     170:     Skipsp(tx);
     171:     if (!Cap(Char(tx))) parerr("no keyword where expected", "");
     172:     return findkw(u, &f, &tx);
     173: }
     174:
     175: /* Stream handling */
     176: /* Txbuf holds streams of incoming characters from a file or the keyboard */
     177: /* The current stream is marked by txstart and txend,			  */
     178: /* with tx pointing somewhere in the middle				  */
     179: /* The main stream is for immediate commands, but new ones are created	  */
     180: /* for reading units, and for the read command (when this is implemented) */
     181:
     182: #define TXBUFSIZE (1<<13)
     183: char txbuf[TXBUFSIZE];
     184: txptr txbufstart= &txbuf[1], txstart, txend, txbufend= &txbuf[TXBUFSIZE];
     185:
     186: intlet alino;
     187:
     188: #define Interactive (interactive && sv_ifile == ifile)
     189:
     190: Visible txptr fcol() { /* the first position of the current line */
     191:     txptr ax= tx;
     192:     while (!Eol(ax-1) && Char(ax-1) != Eotc) ax--;
     193:     return(ax);
     194: }
     195:
     196: Visible txptr lcol() { /* the position beyond the last character of the line */
     197:     txptr ax= tx;
     198:     while (!Eol(ax)) ax++;
     199:     return(ax);
     200: }
     201:
     202: Visible Procedure getline() {
     203:     intlet k; bool got;
     204:     if (Eof0) {
     205:         *txend++= Eouc; *txend= Eotc;
     206:         Eof= Yes;
     207:         return;
     208:     }
     209:     alino++;
     210:     got= No;
     211:     while (!got) {
     212:         if (Interactive) {
     213:             if (outeractive) {
     214:                 line();
     215:                 at_nwl= No;
     216:             }
     217:             fprintf(stderr, cmd_prompt);
     218:         }
     219:         got= Yes;
     220:         while ((k= getc(ifile)) != EOF && k != '\n') {
     221:             *txend++= k;
     222:             if (txend > txbufend-5) syserr("text buffer overflow");
     223:         }
     224:         if (k == EOF && Interactive) {
     225:             if (filtered) bye(0); /* Editor has died */
     226:             fprintf(stderr, "\r*** use QUIT to end session\n");
     227:             CLEAR_EOF;
     228:             if (outeractive) at_nwl= Yes;
     229:             got= No;
     230:         }
     231:     }
     232:     if (Interactive && outeractive && k == '\n') at_nwl= Yes;
     233:     *txend++= '\n'; *txend= Eotc;
     234:     Eof0= k == EOF;
     235: }
     236:
     237: Visible intlet ilev(new) bool new; {
     238:     register intlet i;
     239:     lino++;
     240:     if (Char(tx) == Eouc) {
     241:         ++tx; /* veli() */
     242:         if(!new)debug("ilev saw Eouc and returns since new == No");
     243:         if (!new) return cur_ilev= 0;
     244:         debug("ilev saw Eouc but proceeds since new == Yes");
     245:     } else if (Char(tx++) != '\n')
     246:         syserr("ilev called when not at end of line");
     247:     if(Char(tx-1)!=Eouc)debug("ilev saw no Eouc");
     248:     if (Char(tx) == Eotc) getline();
     249:     i= 0;
     250:     while (Char(tx) == ' ' || Char(tx) == '\t') {
     251:         if (Char(tx) == ' ') i++;
     252:         else i= (i/4+1)*4;
     253:         tx++;
     254:     }
     255:     if (Char(tx) == '\n') return cur_ilev= 0;
     256:     if (i%4 == 2)
     257:         parerr("cannot make out indentation; use tab to indent", "");
     258:     return cur_ilev= (i+1)/4; /* small deviation accepted */
     259: }
     260:
     261: Visible Procedure veli() {
     262:     /* resets tx after look-ahead call of ilev */
     263:     debug("calling veli");
     264:     while (Char(--tx) != '\n' && Char(tx) != Eouc);
     265:     lino--;
     266:     debug("leaving veli");
     267: }
     268:
     269: Visible Procedure inistreams() {
     270:     txstart= txbufstart;
     271:     start_stream();
     272: }
     273:
     274: Visible Procedure re_streams() {
     275:     if (Char(tx+1) == Eotc) inistreams();
     276: }
     277:
     278: Visible Procedure open_stream() {
     279:     txstart= txend+2;
     280:     start_stream();
     281: }
     282:
     283: Hidden Procedure start_stream() {
     284:     *(txend= txstart)= Eotc;
     285:     tx= txend-1;
     286:     *tx= Eouc;
     287: }
     288:
     289: Visible Procedure close_stream(otx, otxstart) txptr otx, otxstart; {
     290:     txend= txstart-2;
     291:     tx= otx;
     292:     txstart= otxstart;
     293: }

#### Defined functions

ateol defined in line 24; used 4 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 455, 483
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 42
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 431

atkw defined in line 67; used 47 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 59, 89, 98, 109, 116, 125-129(2), 140, 151, 171, 182, 189-192(2), 235, 246, 253, 267, 311, 321, 331, 338, 347, 363, 369, 375-379(2), 385, 489
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 83(3), 209(3)
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 50
- in /usr/src/new/PORT/B/src/bsmall/b2tes.c line 27-30(4)
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 29(3), 160, 274(2), 432, 498

close_stream defined in line 289; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 61

count defined in line 119; used 6 times

- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 100, 454
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 52
- in /usr/src/new/PORT/B/src/bsmall/b2tar.c line 23
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 402, 448

fcol defined in line 190; used 2 times

- in /usr/src/new/PORT/B/src/bsmall/b2err.c line 63
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 54

find defined in line 108; used 10 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 153, 270
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 417
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 51
- in /usr/src/new/PORT/B/src/bsmall/b2tes.c line 22(2), 33-37(2), 153-154(2)

findceol defined in line 60; used 12 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 459, 469, 485
- in /usr/src/new/PORT/B/src/bsmall/b2mai.c line 132
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 54, 181
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 158, 249, 272, 351, 433, 497

findkw defined in line 150; used 4 times

- in line 172
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 44
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 167, 499

getline defined in line 202; used 2 times

- in line 248
- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 430

ilev defined in line 237; used 9 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 458, 468, 484
- in /usr/src/new/PORT/B/src/bsmall/b2mai.c line 131
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 54, 181
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 60
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 432, 496

inistreams defined in line 269; used 3 times

- in line 275
- in /usr/src/new/PORT/B/src/bsmall/b2mai.c line 123
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 201

keyword defined in line 168; used 10 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 446
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 141, 212
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 45
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 37, 51, 142, 160, 233, 251

lcol defined in line 196; used 3 times

- in line 54
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 55
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 499

need defined in line 75; used 4 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 247
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 461-464(2)
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 454

nothing defined in line 17; used 9 times

- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 135, 185, 291
- in /usr/src/new/PORT/B/src/bsmall/b2tar.c line 38
- in /usr/src/new/PORT/B/src/bsmall/b2tes.c line 46
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 103, 179, 417, 463

open_stream defined in line 278; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 52

re_streams defined in line 274; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b2mai.c line 127

req defined in line 98; used 24 times

- in line 54
- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 227, 488
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 104, 187, 242, 401, 416, 462-466(2), 477
- in /usr/src/new/PORT/B/src/bsmall/b2tar.c line 26, 40, 58
- in /usr/src/new/PORT/B/src/bsmall/b2tes.c line 49
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 38, 159, 273, 352, 394, 405, 419, 451, 466

reqkw defined in line 87; used 8 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 100, 131, 142, 156, 173, 273
- in /usr/src/new/PORT/B/src/bsmall/b2tes.c line 150
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 175

start_stream defined in line 283; used 2 times

- in line 271, 280

tag defined in line 133; used 21 times

- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 136, 160, 292
- in /usr/src/new/PORT/B/src/bsmall/b2sem.h line 51
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 145, 326
- in /usr/src/new/PORT/B/src/bsmall/b2syn.h line 48
- in /usr/src/new/PORT/B/src/bsmall/b2tar.c line 43
- in /usr/src/new/PORT/B/src/bsmall/b2tes.c line 56, 98
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 44, 85, 94, 111, 278-286(3), 353, 422, 469, 513

thought defined in line 82; used 6 times

- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 400, 410
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 253, 290, 353, 521

upto defined in line 12; used 13 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 248, 312, 322, 348, 491
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 117
- in /usr/src/new/PORT/B/src/bsmall/b2tes.c line 67, 76, 94, 102
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 241, 456, 488

veli defined in line 261; used 7 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 464, 474, 503
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 437, 503, 511, 518

#### Defined variables

Procedure defined in line 202; never used
Visible defined in line 237; never used
alino defined in line 186; used 1 times

- in line 209

tagbuf defined in line 130; used 9 times

- in line 131-134(2), 141-151(4), 158-163(3)

tagbufend defined in line 131; used 2 times

- in line 139, 156

txbuf defined in line 183; used 2 times

- in line 184(2)

txbufstart defined in line 184; used 1 times

- in line 270

#### Defined macros

Interactive defined in line 188; used 3 times

- in line 212, 224, 232

Otherwise defined in line 39; used 5 times

- in line 64, 95, 105, 116, 126

TAGBUFSIZE defined in line 129; used 2 times

- in line 130-131(2)

TXBUFSIZE defined in line 182; used 2 times

- in line 183-184(2)

Where_inside defined in line 33; used 5 times

- in line 61, 88, 99, 109, 121

Last modified: 1985-08-27 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1615 |