fort not included in "all" or "install" until f77 copy of sources
[unix-history] / usr / src / old / awk / parse.c
CommitLineData
3da1e57a
KM
1/* parse.c 4.1 82/05/07 */
2
3#include "awk.def"
4#include "awk.h"
5#include "stdio.h"
6node *ALLOC(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 ALLOC");
12 return(x);
13}
14node *exptostat(a) node *a;
15{
16 a->ntype = NSTAT;
17 return(a);
18}
19node *nullstat;
20node *node0(a)
21{
22 register node *x;
23 x=ALLOC(0);
24 x->nnext = NULL;
25 x->nobj=a;
26 return(x);
27}
28node *node1(a,b) node *b;
29{
30 register node *x;
31 x=ALLOC(1);
32 x->nnext = NULL;
33 x->nobj=a;
34 x->narg[0]=b;
35 return(x);
36}
37node *node2(a,b,c) node *b, *c;
38{
39 register node *x;
40 x = ALLOC(2);
41 x->nnext = NULL;
42 x->nobj = a;
43 x->narg[0] = b;
44 x->narg[1] = c;
45 return(x);
46}
47node *node3(a,b,c,d) node *b, *c, *d;
48{
49 register node *x;
50 x = ALLOC(3);
51 x->nnext = NULL;
52 x->nobj = a;
53 x->narg[0] = b;
54 x->narg[1] = c;
55 x->narg[2] = d;
56 return(x);
57}
58node *node4(a,b,c,d,e) node *b, *c, *d, *e;
59{
60 register node *x;
61 x = ALLOC(4);
62 x->nnext = NULL;
63 x->nobj = a;
64 x->narg[0] = b;
65 x->narg[1] = c;
66 x->narg[2] = d;
67 x->narg[3] = e;
68 return(x);
69}
70node *stat3(a,b,c,d) node *b, *c, *d;
71{
72 register node *x;
73 x = node3(a,b,c,d);
74 x->ntype = NSTAT;
75 return(x);
76}
77node *op2(a,b,c) node *b, *c;
78{
79 register node *x;
80 x = node2(a,b,c);
81 x->ntype = NEXPR;
82 return(x);
83}
84node *op1(a,b) node *b;
85{
86 register node *x;
87 x = node1(a,b);
88 x->ntype = NEXPR;
89 return(x);
90}
91node *stat1(a,b) node *b;
92{
93 register node *x;
94 x = node1(a,b);
95 x->ntype = NSTAT;
96 return(x);
97}
98node *op3(a,b,c,d) node *b, *c, *d;
99{
100 register node *x;
101 x = node3(a,b,c,d);
102 x->ntype = NEXPR;
103 return(x);
104}
105node *stat2(a,b,c) node *b, *c;
106{
107 register node *x;
108 x = node2(a,b,c);
109 x->ntype = NSTAT;
110 return(x);
111}
112node *stat4(a,b,c,d,e) node *b, *c, *d, *e;
113{
114 register node *x;
115 x = node4(a,b,c,d,e);
116 x->ntype = NSTAT;
117 return(x);
118}
119node *valtonode(a, b) cell *a;
120{
121 register node *x;
122 x = node0(a);
123 x->ntype = NVALUE;
124 x->subtype = b;
125 return(x);
126}
127node *pa2stat(a,b,c) node *a, *b, *c;
128{
129 register node *x;
130 x = node3(paircnt++, a, b, c);
131 x->ntype = NPA2;
132 return(x);
133}
134node *linkum(a,b) node *a, *b;
135{
136 register node *c;
137 if(a == NULL) return(b);
138 else if(b == NULL) return(a);
139 for(c=a; c->nnext != NULL; c=c->nnext);
140 c->nnext = b;
141 return(a);
142}
143node *genprint()
144{
145 register node *x;
146 x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), nullstat);
147 return(x);
148}