Annotation of researchv8dc/cmd/awk/parse.c, revision 1.1.1.1

1.1       root        1: #define DEBUG
                      2: #include <stdio.h>
                      3: #include "awk.h"
                      4: #include "y.tab.h"
                      5: 
                      6: Node *nodealloc(n)
                      7: {
                      8:        register Node *x;
                      9:        x = (Node *) Malloc(sizeof(Node) + (n-1)*sizeof(Node *));
                     10:        if (x == NULL)
                     11:                error(FATAL, "out of space in nodealloc");
                     12:        x->nnext = NULL;
                     13:        x->lineno = lineno;
                     14:        return(x);
                     15: }
                     16: 
                     17: Node *exptostat(a) Node *a;
                     18: {
                     19:        a->ntype = NSTAT;
                     20:        return(a);
                     21: }
                     22: 
                     23: Node *node0(a)
                     24: {
                     25:        register Node *x;
                     26:        x = nodealloc(0);
                     27:        x->nobj = a;
                     28:        return(x);
                     29: }
                     30: 
                     31: Node *node1(a,b) Node *b;
                     32: {
                     33:        register Node *x;
                     34:        x = nodealloc(1);
                     35:        x->nobj = a;
                     36:        x->narg[0]=b;
                     37:        return(x);
                     38: }
                     39: 
                     40: Node *node2(a,b,c) Node *b, *c;
                     41: {
                     42:        register Node *x;
                     43:        x = nodealloc(2);
                     44:        x->nobj = a;
                     45:        x->narg[0] = b;
                     46:        x->narg[1] = c;
                     47:        return(x);
                     48: }
                     49: 
                     50: Node *node3(a,b,c,d) Node *b, *c, *d;
                     51: {
                     52:        register Node *x;
                     53:        x = nodealloc(3);
                     54:        x->nobj = a;
                     55:        x->narg[0] = b;
                     56:        x->narg[1] = c;
                     57:        x->narg[2] = d;
                     58:        return(x);
                     59: }
                     60: 
                     61: Node *node4(a,b,c,d,e) Node *b, *c, *d, *e;
                     62: {
                     63:        register Node *x;
                     64:        x = nodealloc(4);
                     65:        x->nobj = a;
                     66:        x->narg[0] = b;
                     67:        x->narg[1] = c;
                     68:        x->narg[2] = d;
                     69:        x->narg[3] = e;
                     70:        return(x);
                     71: }
                     72: 
                     73: Node *stat3(a,b,c,d) Node *b, *c, *d;
                     74: {
                     75:        register Node *x;
                     76:        x = node3(a,b,c,d);
                     77:        x->ntype = NSTAT;
                     78:        return(x);
                     79: }
                     80: 
                     81: Node *op2(a,b,c) Node *b, *c;
                     82: {
                     83:        register Node *x;
                     84:        x = node2(a,b,c);
                     85:        x->ntype = NEXPR;
                     86:        return(x);
                     87: }
                     88: 
                     89: Node *op1(a,b) Node *b;
                     90: {
                     91:        register Node *x;
                     92:        x = node1(a,b);
                     93:        x->ntype = NEXPR;
                     94:        return(x);
                     95: }
                     96: 
                     97: Node *stat1(a,b) Node *b;
                     98: {
                     99:        register Node *x;
                    100:        x = node1(a,b);
                    101:        x->ntype = NSTAT;
                    102:        return(x);
                    103: }
                    104: 
                    105: Node *op3(a,b,c,d) Node *b, *c, *d;
                    106: {
                    107:        register Node *x;
                    108:        x = node3(a,b,c,d);
                    109:        x->ntype = NEXPR;
                    110:        return(x);
                    111: }
                    112: 
                    113: Node *op4(a,b,c,d,e) Node *b, *c, *d, *e;
                    114: {
                    115:        register Node *x;
                    116:        x = node4(a,b,c,d,e);
                    117:        x->ntype = NEXPR;
                    118:        return(x);
                    119: }
                    120: 
                    121: Node *stat2(a,b,c) Node *b, *c;
                    122: {
                    123:        register Node *x;
                    124:        x = node2(a,b,c);
                    125:        x->ntype = NSTAT;
                    126:        return(x);
                    127: }
                    128: 
                    129: Node *stat4(a,b,c,d,e) Node *b, *c, *d, *e;
                    130: {
                    131:        register Node *x;
                    132:        x = node4(a,b,c,d,e);
                    133:        x->ntype = NSTAT;
                    134:        return(x);
                    135: }
                    136: 
                    137: Node *valtonode(a, b) Cell *a;
                    138: {
                    139:        register Node *x;
                    140: 
                    141:        a->ctype = OCELL;
                    142:        a->csub = b;
                    143:        x = node1(0, a);
                    144:        x->ntype = b == CFLD ? NFIELD : NVALUE;
                    145:        return(x);
                    146: }
                    147: 
                    148: Node *rectonode()
                    149: {
                    150:        return valtonode(lookup("$0", symtab), CFLD);
                    151: }
                    152: 
                    153: Node *makearr(p) Node *p;
                    154: {
                    155:        Cell *cp;
                    156: 
                    157:        if (isvalue(p)) {
                    158:                cp = (Cell *) (p->narg[0]);
                    159:                if (!isarr(cp)) {
                    160:                        xfree(cp->sval);
                    161:                        cp->sval = (char *) makesymtab();
                    162:                        cp->tval = ARR;
                    163:                }
                    164:        }
                    165:        return p;
                    166: }
                    167: 
                    168: Node *pa2stat(a,b,c) Node *a, *b, *c;
                    169: {
                    170:        register Node *x;
                    171:        x = node4(PASTAT2, a, b, c, (Node *) paircnt);
                    172:        paircnt++;
                    173:        x->ntype = NSTAT;
                    174:        return(x);
                    175: }
                    176: 
                    177: Node *linkum(a,b) Node *a, *b;
                    178: {
                    179:        register Node *c;
                    180: 
                    181:        if (errorflag)  /* don't link things that are wrong */
                    182:                return a;
                    183:        if (a == NULL) return(b);
                    184:        else if (b == NULL) return(a);
                    185:        for (c = a; c->nnext != NULL; c = c->nnext)
                    186:                ;
                    187:        c->nnext = b;
                    188:        return(a);
                    189: }
                    190: 
                    191: defn(v, vl, st)        /* turn on FCN bit in definition */
                    192:        Cell *v;
                    193:        Node *st, *vl;  /* body of function, arglist */
                    194: {
                    195:        Node *p;
                    196:        int n;
                    197: 
                    198:        v->tval = FCN;
                    199:        v->sval = (char *) st;
                    200:        n = 0;  /* count arguments */
                    201:        for (p = vl; p; p = p->nnext)
                    202:                n++;
                    203:        v->fval = n;
                    204:        dprintf("defining func %s (%d args)\n", v->nval, n);
                    205: }
                    206: 
                    207: isarg(s)       /* is s in argument list for current function? */
                    208:        char *s;
                    209: {
                    210:        extern Node *arglist;
                    211:        Node *p = arglist;
                    212:        int n;
                    213: 
                    214:        for (n = 0; p != 0; p = p->nnext, n++)
                    215:                if (strcmp(((Cell *)(p->narg[0]))->nval, s) == 0)
                    216:                        return n;
                    217:        return -1;
                    218: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.