|
|
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: return valtonode(recloc, CFLD); ! 152: } ! 153: ! 154: Node *makearr(p) Node *p; ! 155: { ! 156: Cell *cp; ! 157: ! 158: if (isvalue(p)) { ! 159: cp = (Cell *) (p->narg[0]); ! 160: if (isfunc(cp)) ! 161: yyerror("%s is a function, not an array", cp->nval); ! 162: else if (!isarr(cp)) { ! 163: xfree(cp->sval); ! 164: cp->sval = (uchar *) makesymtab(NSYMTAB); ! 165: cp->tval = ARR; ! 166: } ! 167: } ! 168: return p; ! 169: } ! 170: ! 171: Node *pa2stat(a,b,c) Node *a, *b, *c; ! 172: { ! 173: register Node *x; ! 174: x = node4(PASTAT2, a, b, c, (Node *) paircnt); ! 175: paircnt++; ! 176: x->ntype = NSTAT; ! 177: return(x); ! 178: } ! 179: ! 180: Node *linkum(a,b) Node *a, *b; ! 181: { ! 182: register Node *c; ! 183: ! 184: if (errorflag) /* don't link things that are wrong */ ! 185: return a; ! 186: if (a == NULL) return(b); ! 187: else if (b == NULL) return(a); ! 188: for (c = a; c->nnext != NULL; c = c->nnext) ! 189: ; ! 190: c->nnext = b; ! 191: return(a); ! 192: } ! 193: ! 194: defn(v, vl, st) /* turn on FCN bit in definition */ ! 195: Cell *v; ! 196: Node *st, *vl; /* body of function, arglist */ ! 197: { ! 198: Node *p; ! 199: int n; ! 200: ! 201: if (isarr(v)) { ! 202: yyerror("`%s' is an array name and a function name", v->nval); ! 203: return; ! 204: } ! 205: v->tval = FCN; ! 206: v->sval = (uchar *) st; ! 207: n = 0; /* count arguments */ ! 208: for (p = vl; p; p = p->nnext) ! 209: n++; ! 210: v->fval = n; ! 211: dprintf("defining func %s (%d args)\n", v->nval, n); ! 212: } ! 213: ! 214: isarg(s) /* is s in argument list for current function? */ ! 215: uchar *s; ! 216: { ! 217: extern Node *arglist; ! 218: Node *p = arglist; ! 219: int n; ! 220: ! 221: for (n = 0; p != 0; p = p->nnext, n++) ! 222: if (strcmp(((Cell *)(p->narg[0]))->nval, s) == 0) ! 223: return n; ! 224: return -1; ! 225: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.