Annotation of researchv10no/cmd/awk/parse.c, revision 1.1

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

unix.superglobalmegacorp.com

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