1ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner/****************************************************************
2ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerCopyright (C) Lucent Technologies 1997
3ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerAll Rights Reserved
4ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
5ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerPermission to use, copy, modify, and distribute this software and
6ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerits documentation for any purpose and without fee is hereby
7ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnergranted, provided that the above copyright notice appear in all
8ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnercopies and that both that the copyright notice and this
9ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpermission notice and warranty disclaimer appear in supporting
10ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerdocumentation, and that the name Lucent Technologies or any of
11ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerits entities not be used in advertising or publicity pertaining
12ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerto distribution of the software without specific, written prior
13ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpermission.
14ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
15ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
17ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
18ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
20ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
22ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerTHIS SOFTWARE.
23ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner****************************************************************/
24ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
25ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%{
26ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner#include <stdio.h>
27ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner#include <string.h>
28ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner#include "awk.h"
29ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
30ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnervoid checkdup(Node *list, Cell *item);
31ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerint yywrap(void) { return(1); }
32ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
33ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerNode	*beginloc = 0;
34ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerNode	*endloc = 0;
35ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerint	infunc	= 0;	/* = 1 if in arglist or body of func */
36ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerint	inloop	= 0;	/* = 1 if in while, for, do */
37ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerchar	*curfname = 0;	/* current function name */
38ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerNode	*arglist = 0;	/* list of args for current function */
39ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%}
40ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
41ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%union {
42ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	Node	*p;
43ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	Cell	*cp;
44ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	int	i;
45ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	char	*s;
46ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner}
47ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
48ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	FIRSTTOKEN	/* must be first */
49ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<p>	PROGRAM PASTAT PASTAT2 XBEGIN XEND
50ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	NL ',' '{' '(' '|' ';' '/' ')' '}' '[' ']'
51ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	ARRAY
52ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	MATCH NOTMATCH MATCHOP
53ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	FINAL DOT ALL CCL NCCL CHAR OR STAR QUEST PLUS EMPTYRE
54ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	AND BOR APPEND EQ GE GT LE LT NE IN
55ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	ARG BLTIN BREAK CLOSE CONTINUE DELETE DO EXIT FOR FUNC
56ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	SUB GSUB IF INDEX LSUBSTR MATCHFCN NEXT NEXTFILE
57ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	ADD MINUS MULT DIVIDE MOD
58ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	ASSIGN ASGNOP ADDEQ SUBEQ MULTEQ DIVEQ MODEQ POWEQ
59ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	PRINT PRINTF SPRINTF
60ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<p>	ELSE INTEST CONDEXPR
61ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<i>	POSTINCR PREINCR POSTDECR PREDECR
62ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<cp>	VAR IVAR VARNF CALL NUMBER STRING
63ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	<s>	REGEXPR
64ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
65ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%type	<p>	pas pattern ppattern plist pplist patlist prarg term re
66ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%type	<p>	pa_pat pa_stat pa_stats
67ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%type	<s>	reg_expr
68ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%type	<p>	simple_stmt opt_simple_stmt stmt stmtlist
69ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%type	<p>	var varname funcname varlist
70ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%type	<p>	for if else while
71ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%type	<i>	do st
72ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%type	<i>	pst opt_pst lbrace rbrace rparen comma nl opt_nl and bor
73ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%type	<i>	subop print
74ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
75ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%right	ASGNOP
76ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%right	'?'
77ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%right	':'
78ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	BOR
79ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	AND
80ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	GETLINE
81ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%nonassoc APPEND EQ GE GT LE LT NE MATCHOP IN '|'
82ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	ARG BLTIN BREAK CALL CLOSE CONTINUE DELETE DO EXIT FOR FUNC
83ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	GSUB IF INDEX LSUBSTR MATCHFCN NEXT NUMBER
84ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	PRINT PRINTF RETURN SPLIT SPRINTF STRING SUB SUBSTR
85ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	REGEXPR VAR VARNF IVAR WHILE '('
86ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	CAT
87ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	'+' '-'
88ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	'*' '/' '%'
89ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	NOT UMINUS
90ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%right	POWER
91ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%right	DECR INCR
92ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%left	INDIRECT
93ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%token	LASTTOKEN	/* must be last */
94ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
95ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%%
96ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
97ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerprogram:
98ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  pas	{ if (errorflag==0)
99ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			winner = (Node *)stat3(PROGRAM, beginloc, $1, endloc); }
100ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| error	{ yyclearin; bracecheck(); SYNTAX("bailing out"); }
101ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
102ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
103ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerand:
104ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  AND | and NL
105ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
106ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
107ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerbor:
108ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  BOR | bor NL
109ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
110ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
111ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnercomma:
112ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  ',' | comma NL
113ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
114ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
115ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerdo:
116ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  DO | do NL
117ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
118ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
119ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerelse:
120ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  ELSE | else NL
121ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
122ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
123ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerfor:
124ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  FOR '(' opt_simple_stmt ';' opt_nl pattern ';' opt_nl opt_simple_stmt rparen {inloop++;} stmt
125ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ --inloop; $$ = stat4(FOR, $3, notnull($6), $9, $12); }
126ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| FOR '(' opt_simple_stmt ';'  ';' opt_nl opt_simple_stmt rparen {inloop++;} stmt
127ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ --inloop; $$ = stat4(FOR, $3, NIL, $7, $10); }
128ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| FOR '(' varname IN varname rparen {inloop++;} stmt
129ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ --inloop; $$ = stat3(IN, $3, makearr($5), $8); }
130ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
131ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
132ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerfuncname:
133ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  VAR	{ setfname($1); }
134ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| CALL	{ setfname($1); }
135ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
136ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
137ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerif:
138ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  IF '(' pattern rparen		{ $$ = notnull($3); }
139ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
140ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
141ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerlbrace:
142ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  '{' | lbrace NL
143ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
144ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
145ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnernl:
146ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  NL | nl NL
147ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
148ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
149ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turneropt_nl:
150ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  /* empty */	{ $$ = 0; }
151ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| nl
152ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
153ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
154ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turneropt_pst:
155ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  /* empty */	{ $$ = 0; }
156ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pst
157ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
158ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
159ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
160ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turneropt_simple_stmt:
161ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  /* empty */			{ $$ = 0; }
162ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| simple_stmt
163ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
164ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
165ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpas:
166ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  opt_pst			{ $$ = 0; }
167ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| opt_pst pa_stats opt_pst	{ $$ = $2; }
168ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
169ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
170ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpa_pat:
171ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  pattern	{ $$ = notnull($1); }
172ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
173ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
174ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpa_stat:
175ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  pa_pat			{ $$ = stat2(PASTAT, $1, stat2(PRINT, rectonode(), NIL)); }
176ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pa_pat lbrace stmtlist '}'	{ $$ = stat2(PASTAT, $1, $3); }
177ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pa_pat ',' pa_pat		{ $$ = pa2stat($1, $3, stat2(PRINT, rectonode(), NIL)); }
178ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pa_pat ',' pa_pat lbrace stmtlist '}'	{ $$ = pa2stat($1, $3, $5); }
179ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| lbrace stmtlist '}'		{ $$ = stat2(PASTAT, NIL, $2); }
180ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| XBEGIN lbrace stmtlist '}'
181ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ beginloc = linkum(beginloc, $3); $$ = 0; }
182ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| XEND lbrace stmtlist '}'
183ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ endloc = linkum(endloc, $3); $$ = 0; }
184ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| FUNC funcname '(' varlist rparen {infunc++;} lbrace stmtlist '}'
185ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ infunc--; curfname=0; defn((Cell *)$2, $4, $8); $$ = 0; }
186ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
187ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
188ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpa_stats:
189ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  pa_stat
190ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pa_stats opt_pst pa_stat	{ $$ = linkum($1, $3); }
191ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
192ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
193ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpatlist:
194ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  pattern
195ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| patlist comma pattern		{ $$ = linkum($1, $3); }
196ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
197ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
198ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerppattern:
199ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  var ASGNOP ppattern		{ $$ = op2($2, $1, $3); }
200ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ppattern '?' ppattern ':' ppattern %prec '?'
201ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	 	{ $$ = op3(CONDEXPR, notnull($1), $3, $5); }
202ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ppattern bor ppattern %prec BOR
203ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op2(BOR, notnull($1), notnull($3)); }
204ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ppattern and ppattern %prec AND
205ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op2(AND, notnull($1), notnull($3)); }
206ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ppattern MATCHOP reg_expr	{ $$ = op3($2, NIL, $1, (Node*)makedfa($3, 0)); }
207ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ppattern MATCHOP ppattern
208ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ if (constnode($3))
209ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op3($2, NIL, $1, (Node*)makedfa(strnode($3), 0));
210ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		  else
211ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op3($2, (Node *)1, $1, $3); }
212ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ppattern IN varname		{ $$ = op2(INTEST, $1, makearr($3)); }
213ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| '(' plist ')' IN varname	{ $$ = op2(INTEST, $2, makearr($5)); }
214ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ppattern term %prec CAT	{ $$ = op2(CAT, $1, $2); }
215ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| re
216ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| term
217ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
218ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
219ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpattern:
220ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  var ASGNOP pattern		{ $$ = op2($2, $1, $3); }
221ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern '?' pattern ':' pattern %prec '?'
222ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	 	{ $$ = op3(CONDEXPR, notnull($1), $3, $5); }
223ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern bor pattern %prec BOR
224ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op2(BOR, notnull($1), notnull($3)); }
225ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern and pattern %prec AND
226ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op2(AND, notnull($1), notnull($3)); }
227ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern EQ pattern		{ $$ = op2($2, $1, $3); }
228ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern GE pattern		{ $$ = op2($2, $1, $3); }
229ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern GT pattern		{ $$ = op2($2, $1, $3); }
230ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern LE pattern		{ $$ = op2($2, $1, $3); }
231ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern LT pattern		{ $$ = op2($2, $1, $3); }
232ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern NE pattern		{ $$ = op2($2, $1, $3); }
233ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern MATCHOP reg_expr	{ $$ = op3($2, NIL, $1, (Node*)makedfa($3, 0)); }
234ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern MATCHOP pattern
235ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ if (constnode($3))
236ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op3($2, NIL, $1, (Node*)makedfa(strnode($3), 0));
237ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		  else
238ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op3($2, (Node *)1, $1, $3); }
239ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern IN varname		{ $$ = op2(INTEST, $1, makearr($3)); }
240ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| '(' plist ')' IN varname	{ $$ = op2(INTEST, $2, makearr($5)); }
241ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern '|' GETLINE var	{
242ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			if (safe) SYNTAX("cmd | getline is unsafe");
243ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			else $$ = op3(GETLINE, $4, itonp($2), $1); }
244ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern '|' GETLINE		{
245ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			if (safe) SYNTAX("cmd | getline is unsafe");
246ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			else $$ = op3(GETLINE, (Node*)0, itonp($2), $1); }
247ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern term %prec CAT	{ $$ = op2(CAT, $1, $2); }
248ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| re
249ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| term
250ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
251ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
252ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerplist:
253ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  pattern comma pattern		{ $$ = linkum($1, $3); }
254ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| plist comma pattern		{ $$ = linkum($1, $3); }
255ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
256ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
257ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpplist:
258ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  ppattern
259ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pplist comma ppattern		{ $$ = linkum($1, $3); }
260ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
261ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
262ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerprarg:
263ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  /* empty */			{ $$ = rectonode(); }
264ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pplist
265ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| '(' plist ')'			{ $$ = $2; }
266ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
267ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
268ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerprint:
269ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  PRINT | PRINTF
270ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
271ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
272ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerpst:
273ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  NL | ';' | pst NL | pst ';'
274ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
275ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
276ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerrbrace:
277ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  '}' | rbrace NL
278ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
279ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
280ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerre:
281ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	   reg_expr
282ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op3(MATCH, NIL, rectonode(), (Node*)makedfa($1, 0)); }
283ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| NOT re	{ $$ = op1(NOT, notnull($2)); }
284ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
285ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
286ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerreg_expr:
287ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  '/' {startreg();} REGEXPR '/'		{ $$ = $3; }
288ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
289ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
290ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerrparen:
291ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  ')' | rparen NL
292ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
293ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
294ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnersimple_stmt:
295ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  print prarg '|' term		{
296ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			if (safe) SYNTAX("print | is unsafe");
297ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			else $$ = stat3($1, $2, itonp($3), $4); }
298ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| print prarg APPEND term	{
299ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			if (safe) SYNTAX("print >> is unsafe");
300ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			else $$ = stat3($1, $2, itonp($3), $4); }
301ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| print prarg GT term		{
302ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			if (safe) SYNTAX("print > is unsafe");
303ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			else $$ = stat3($1, $2, itonp($3), $4); }
304ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| print prarg			{ $$ = stat3($1, $2, NIL, NIL); }
305ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| DELETE varname '[' patlist ']' { $$ = stat2(DELETE, makearr($2), $4); }
306ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| DELETE varname		 { $$ = stat2(DELETE, makearr($2), 0); }
307ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| pattern			{ $$ = exptostat($1); }
308ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| error				{ yyclearin; SYNTAX("illegal statement"); }
309ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
310ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
311ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerst:
312ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  nl
313ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ';' opt_nl
314ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
315ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
316ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerstmt:
317ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  BREAK st		{ if (!inloop) SYNTAX("break illegal outside of loops");
318ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner				  $$ = stat1(BREAK, NIL); }
319ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| CONTINUE st		{  if (!inloop) SYNTAX("continue illegal outside of loops");
320ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner				  $$ = stat1(CONTINUE, NIL); }
321ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| do {inloop++;} stmt {--inloop;} WHILE '(' pattern ')' st
322ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = stat2(DO, $3, notnull($7)); }
323ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| EXIT pattern st	{ $$ = stat1(EXIT, $2); }
324ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| EXIT st		{ $$ = stat1(EXIT, NIL); }
325ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| for
326ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| if stmt else stmt	{ $$ = stat3(IF, $1, $2, $4); }
327ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| if stmt		{ $$ = stat3(IF, $1, $2, NIL); }
328ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| lbrace stmtlist rbrace { $$ = $2; }
329ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| NEXT st	{ if (infunc)
330ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner				SYNTAX("next is illegal inside a function");
331ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			  $$ = stat1(NEXT, NIL); }
332ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| NEXTFILE st	{ if (infunc)
333ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner				SYNTAX("nextfile is illegal inside a function");
334ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			  $$ = stat1(NEXTFILE, NIL); }
335ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| RETURN pattern st	{ $$ = stat1(RETURN, $2); }
336ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| RETURN st		{ $$ = stat1(RETURN, NIL); }
337ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| simple_stmt st
338ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| while {inloop++;} stmt	{ --inloop; $$ = stat2(WHILE, $1, $3); }
339ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ';' opt_nl		{ $$ = 0; }
340ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
341ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
342ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerstmtlist:
343ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  stmt
344ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| stmtlist stmt		{ $$ = linkum($1, $2); }
345ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
346ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
347ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnersubop:
348ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  SUB | GSUB
349ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
350ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
351ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerterm:
352ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner 	  term '/' ASGNOP term		{ $$ = op2(DIVEQ, $1, $4); }
353ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner 	| term '+' term			{ $$ = op2(ADD, $1, $3); }
354ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| term '-' term			{ $$ = op2(MINUS, $1, $3); }
355ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| term '*' term			{ $$ = op2(MULT, $1, $3); }
356ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| term '/' term			{ $$ = op2(DIVIDE, $1, $3); }
357ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| term '%' term			{ $$ = op2(MOD, $1, $3); }
358ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| term POWER term		{ $$ = op2(POWER, $1, $3); }
359ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| '-' term %prec UMINUS		{ $$ = op1(UMINUS, $2); }
360ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| '+' term %prec UMINUS		{ $$ = $2; }
361ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| NOT term %prec UMINUS		{ $$ = op1(NOT, notnull($2)); }
362ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| BLTIN '(' ')'			{ $$ = op2(BLTIN, itonp($1), rectonode()); }
363ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| BLTIN '(' patlist ')'		{ $$ = op2(BLTIN, itonp($1), $3); }
364ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| BLTIN				{ $$ = op2(BLTIN, itonp($1), rectonode()); }
365ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| CALL '(' ')'			{ $$ = op2(CALL, celltonode($1,CVAR), NIL); }
366ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| CALL '(' patlist ')'		{ $$ = op2(CALL, celltonode($1,CVAR), $3); }
367ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| CLOSE term			{ $$ = op1(CLOSE, $2); }
368ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| DECR var			{ $$ = op1(PREDECR, $2); }
369ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| INCR var			{ $$ = op1(PREINCR, $2); }
370ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| var DECR			{ $$ = op1(POSTDECR, $1); }
371ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| var INCR			{ $$ = op1(POSTINCR, $1); }
372ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| GETLINE var LT term		{ $$ = op3(GETLINE, $2, itonp($3), $4); }
373ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| GETLINE LT term		{ $$ = op3(GETLINE, NIL, itonp($2), $3); }
374ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| GETLINE var			{ $$ = op3(GETLINE, $2, NIL, NIL); }
375ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| GETLINE			{ $$ = op3(GETLINE, NIL, NIL, NIL); }
376ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| INDEX '(' pattern comma pattern ')'
377ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op2(INDEX, $3, $5); }
378ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| INDEX '(' pattern comma reg_expr ')'
379ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ SYNTAX("index() doesn't permit regular expressions");
380ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		  $$ = op2(INDEX, $3, (Node*)$5); }
381ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| '(' pattern ')'		{ $$ = $2; }
382ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| MATCHFCN '(' pattern comma reg_expr ')'
383ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op3(MATCHFCN, NIL, $3, (Node*)makedfa($5, 1)); }
384ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| MATCHFCN '(' pattern comma pattern ')'
385ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ if (constnode($5))
386ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op3(MATCHFCN, NIL, $3, (Node*)makedfa(strnode($5), 1));
387ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		  else
388ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op3(MATCHFCN, (Node *)1, $3, $5); }
389ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| NUMBER			{ $$ = celltonode($1, CCON); }
390ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| SPLIT '(' pattern comma varname comma pattern ')'     /* string */
391ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op4(SPLIT, $3, makearr($5), $7, (Node*)STRING); }
392ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| SPLIT '(' pattern comma varname comma reg_expr ')'    /* const /regexp/ */
393ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op4(SPLIT, $3, makearr($5), (Node*)makedfa($7, 1), (Node *)REGEXPR); }
394ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| SPLIT '(' pattern comma varname ')'
395ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op4(SPLIT, $3, makearr($5), NIL, (Node*)STRING); }  /* default */
396ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| SPRINTF '(' patlist ')'	{ $$ = op1($1, $3); }
397ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| STRING	 		{ $$ = celltonode($1, CCON); }
398ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| subop '(' reg_expr comma pattern ')'
399ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op4($1, NIL, (Node*)makedfa($3, 1), $5, rectonode()); }
400ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| subop '(' pattern comma pattern ')'
401ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ if (constnode($3))
402ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op4($1, NIL, (Node*)makedfa(strnode($3), 1), $5, rectonode());
403ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		  else
404ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op4($1, (Node *)1, $3, $5, rectonode()); }
405ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| subop '(' reg_expr comma pattern comma var ')'
406ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op4($1, NIL, (Node*)makedfa($3, 1), $5, $7); }
407ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| subop '(' pattern comma pattern comma var ')'
408ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ if (constnode($3))
409ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op4($1, NIL, (Node*)makedfa(strnode($3), 1), $5, $7);
410ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		  else
411ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			$$ = op4($1, (Node *)1, $3, $5, $7); }
412ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| SUBSTR '(' pattern comma pattern comma pattern ')'
413ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op3(SUBSTR, $3, $5, $7); }
414ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| SUBSTR '(' pattern comma pattern ')'
415ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		{ $$ = op3(SUBSTR, $3, $5, NIL); }
416ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| var
417ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
418ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
419ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnervar:
420ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  varname
421ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| varname '[' patlist ']'	{ $$ = op2(ARRAY, makearr($1), $3); }
422ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| IVAR				{ $$ = op1(INDIRECT, celltonode($1, CVAR)); }
423ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| INDIRECT term	 		{ $$ = op1(INDIRECT, $2); }
424ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
425ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
426ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnervarlist:
427ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  /* nothing */		{ arglist = $$ = 0; }
428ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| VAR			{ arglist = $$ = celltonode($1,CVAR); }
429ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| varlist comma VAR	{
430ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			checkdup($1, $3);
431ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			arglist = $$ = linkum($1,celltonode($3,CVAR)); }
432ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
433ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
434ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnervarname:
435ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  VAR			{ $$ = celltonode($1, CVAR); }
436ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| ARG 			{ $$ = op1(ARG, itonp($1)); }
437ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	| VARNF			{ $$ = op1(VARNF, (Node *) $1); }
438ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
439ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
440ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
441ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerwhile:
442ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	  WHILE '(' pattern rparen	{ $$ = notnull($3); }
443ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	;
444ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
445ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner%%
446ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
447ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnervoid setfname(Cell *p)
448ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner{
449ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	if (isarr(p))
450ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		SYNTAX("%s is an array, not a function", p->nval);
451ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	else if (isfcn(p))
452ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		SYNTAX("you can't define function %s more than once", p->nval);
453ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	curfname = p->nval;
454ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner}
455ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
456ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerint constnode(Node *p)
457ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner{
458ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	return isvalue(p) && ((Cell *) (p->narg[0]))->csub == CCON;
459ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner}
460ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
461ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnerchar *strnode(Node *p)
462ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner{
463ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	return ((Cell *)(p->narg[0]))->sval;
464ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner}
465ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
466ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David TurnerNode *notnull(Node *n)
467ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner{
468ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	switch (n->nobj) {
469ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	case LE: case LT: case EQ: case NE: case GT: case GE:
470ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	case BOR: case AND: case NOT:
471ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		return n;
472ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	default:
473ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		return op2(NE, n, nullnode);
474ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	}
475ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner}
476ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner
477ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turnervoid checkdup(Node *vl, Cell *cp)	/* check if name already in list */
478ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner{
479ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	char *s = cp->nval;
480ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	for ( ; vl; vl = vl->nnext) {
481ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		if (strcmp(s, ((Cell *)(vl->narg[0]))->nval) == 0) {
482ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			SYNTAX("duplicate argument %s", s);
483ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner			break;
484ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner		}
485ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner	}
486ce5707c0255040b895f1c90ac9a435d8a4b8f2d6David Turner}
487