xref: /csrg-svn/contrib/sc/gram.y (revision 45323)
1*45323Sbostic /*	SC	A Spreadsheet Calculator
2*45323Sbostic  *		Command and expression parser
3*45323Sbostic  *
4*45323Sbostic  *		original by James Gosling, September 1982
5*45323Sbostic  *		modified by Mark Weiser and Bruce Israel,
6*45323Sbostic  *			University of Maryland
7*45323Sbostic  *
8*45323Sbostic  * 		more mods Robert Bond 12/86
9*45323Sbostic  *
10*45323Sbostic  *		More mods by Alan Silverstein, 3/88, see list of changes.
11*45323Sbostic  *
12*45323Sbostic  *		$Revision: 6.8 $
13*45323Sbostic  */
14*45323Sbostic 
15*45323Sbostic 
16*45323Sbostic 
17*45323Sbostic %{
18*45323Sbostic #include <curses.h>
19*45323Sbostic #include "sc.h"
20*45323Sbostic 
21*45323Sbostic #define ENULL (struct enode *)0
22*45323Sbostic 
23*45323Sbostic char *strcpy();
24*45323Sbostic %}
25*45323Sbostic 
26*45323Sbostic %union {
27*45323Sbostic     int ival;
28*45323Sbostic     double fval;
29*45323Sbostic     struct ent_ptr ent;
30*45323Sbostic     struct enode *enode;
31*45323Sbostic     char *sval;
32*45323Sbostic     struct range_s rval;
33*45323Sbostic }
34*45323Sbostic 
35*45323Sbostic %type <ent> var
36*45323Sbostic %type <fval> num
37*45323Sbostic %type <rval> range
38*45323Sbostic %type <rval> var_or_range
39*45323Sbostic %type <sval> strarg
40*45323Sbostic %type <enode> e term expr_list
41*45323Sbostic %token <sval> STRING
42*45323Sbostic %token <ival> NUMBER
43*45323Sbostic %token <fval> FNUMBER
44*45323Sbostic %token <rval> RANGE
45*45323Sbostic %token <rval> VAR
46*45323Sbostic %token <sval> WORD
47*45323Sbostic %token <ival> COL
48*45323Sbostic %token S_FORMAT
49*45323Sbostic %token S_LABEL
50*45323Sbostic %token S_LEFTSTRING
51*45323Sbostic %token S_RIGHTSTRING
52*45323Sbostic %token S_GET
53*45323Sbostic %token S_PUT
54*45323Sbostic %token S_MERGE
55*45323Sbostic %token S_LET
56*45323Sbostic %token S_WRITE
57*45323Sbostic %token S_TBL
58*45323Sbostic %token S_COPY
59*45323Sbostic %token S_SHOW
60*45323Sbostic %token S_ERASE
61*45323Sbostic %token S_FILL
62*45323Sbostic %token S_GOTO
63*45323Sbostic %token S_DEFINE
64*45323Sbostic %token S_UNDEFINE
65*45323Sbostic %token S_VALUE
66*45323Sbostic %token S_MDIR
67*45323Sbostic %token S_HIDE
68*45323Sbostic %token S_SET
69*45323Sbostic 
70*45323Sbostic %token K_FIXED
71*45323Sbostic %token K_SUM
72*45323Sbostic %token K_PROD
73*45323Sbostic %token K_AVG
74*45323Sbostic %token K_STDDEV
75*45323Sbostic %token K_COUNT
76*45323Sbostic %token K_ABS
77*45323Sbostic %token K_ACOS
78*45323Sbostic %token K_ASIN
79*45323Sbostic %token K_ATAN
80*45323Sbostic %token K_ATAN2
81*45323Sbostic %token K_CEIL
82*45323Sbostic %token K_COS
83*45323Sbostic %token K_EXP
84*45323Sbostic %token K_FABS
85*45323Sbostic %token K_FLOOR
86*45323Sbostic %token K_HYPOT
87*45323Sbostic %token K_LN
88*45323Sbostic %token K_LOG
89*45323Sbostic %token K_PI
90*45323Sbostic %token K_POW
91*45323Sbostic %token K_SIN
92*45323Sbostic %token K_SQRT
93*45323Sbostic %token K_TAN
94*45323Sbostic %token K_DTR
95*45323Sbostic %token K_RTD
96*45323Sbostic %token K_MAX
97*45323Sbostic %token K_MIN
98*45323Sbostic %token K_RND
99*45323Sbostic %token K_ROUND
100*45323Sbostic %token K_IF
101*45323Sbostic 
102*45323Sbostic %token K_PV
103*45323Sbostic %token K_FV
104*45323Sbostic %token K_PMT
105*45323Sbostic 
106*45323Sbostic %token K_HOUR
107*45323Sbostic %token K_MINUTE
108*45323Sbostic %token K_SECOND
109*45323Sbostic %token K_MONTH
110*45323Sbostic %token K_DAY
111*45323Sbostic %token K_YEAR
112*45323Sbostic %token K_NOW
113*45323Sbostic %token K_DATE
114*45323Sbostic %token K_DTS
115*45323Sbostic %token K_TTS
116*45323Sbostic %token K_FMT
117*45323Sbostic %token K_SUBSTR
118*45323Sbostic %token K_STON
119*45323Sbostic %token K_EQS
120*45323Sbostic %token K_EXT
121*45323Sbostic %token K_NVAL
122*45323Sbostic %token K_SVAL
123*45323Sbostic %token K_LOOKUP
124*45323Sbostic %token K_HLOOKUP
125*45323Sbostic %token K_VLOOKUP
126*45323Sbostic %token K_INDEX
127*45323Sbostic %token K_STINDEX
128*45323Sbostic %token K_AUTO
129*45323Sbostic %token K_AUTOCALC
130*45323Sbostic %token K_BYROWS
131*45323Sbostic %token K_BYCOLS
132*45323Sbostic %token K_BYGRAPH
133*45323Sbostic %token K_ITERATIONS
134*45323Sbostic %token K_NUMERIC
135*45323Sbostic %token K_PRESCALE
136*45323Sbostic %token K_EXTFUN
137*45323Sbostic %token K_CELLCUR
138*45323Sbostic %token K_TOPROW
139*45323Sbostic %token K_TBLSTYLE
140*45323Sbostic %token K_TBL
141*45323Sbostic %token K_LATEX
142*45323Sbostic %token K_TEX
143*45323Sbostic 
144*45323Sbostic %left '?' ':'
145*45323Sbostic %left '|'
146*45323Sbostic %left '&'
147*45323Sbostic %nonassoc '<' '=' '>' '!'
148*45323Sbostic %left '+' '-' '#'
149*45323Sbostic %left '*' '/' '%'
150*45323Sbostic %left '^'
151*45323Sbostic 
152*45323Sbostic %%
153*45323Sbostic command:	S_LET var_or_range '=' e
154*45323Sbostic 				{ let($2.left.vp, $4); }
155*45323Sbostic 	|	S_LABEL var_or_range '=' e
156*45323Sbostic 				{ slet($2.left.vp, $4, 0); }
157*45323Sbostic 	|	S_LEFTSTRING var_or_range '=' e
158*45323Sbostic 				{ slet($2.left.vp, $4, -1); }
159*45323Sbostic 	|	S_RIGHTSTRING var_or_range '=' e
160*45323Sbostic 				{ slet($2.left.vp, $4, 1); }
161*45323Sbostic 	|	S_FORMAT COL ':' COL NUMBER NUMBER
162*45323Sbostic 				{ doformat($2,$4,$5,$6); }
163*45323Sbostic 	|	S_FORMAT COL NUMBER NUMBER
164*45323Sbostic 				{ doformat($2,$2,$3,$4); }
165*45323Sbostic 	|	S_GET strarg	{  /* This tmp hack is because readfile
166*45323Sbostic 				    * recurses back through yyparse. */
167*45323Sbostic 				  char *tmp;
168*45323Sbostic 				  tmp = $2;
169*45323Sbostic 				  readfile (tmp, 1);
170*45323Sbostic 				  xfree(tmp);
171*45323Sbostic 				}
172*45323Sbostic 	|	S_MERGE strarg	{
173*45323Sbostic 				  char *tmp;
174*45323Sbostic 				  tmp = $2;
175*45323Sbostic 				  readfile (tmp, 0);
176*45323Sbostic 				  xfree(tmp);
177*45323Sbostic 				}
178*45323Sbostic 	|	S_MDIR strarg
179*45323Sbostic 				{ if (mdir) xfree(mdir); mdir = $2; }
180*45323Sbostic 	|       S_PUT strarg range
181*45323Sbostic 				{ (void) writefile($2, ($3.left.vp)->row,
182*45323Sbostic 			 	($3.left.vp)->col, ($3.right.vp)->row,
183*45323Sbostic 			 	($3.right.vp)->col);
184*45323Sbostic 			 	xfree($2); }
185*45323Sbostic 	|	S_PUT strarg
186*45323Sbostic 				{ (void) writefile ($2, 0, 0, maxrow, maxcol);
187*45323Sbostic 			 	xfree($2); }
188*45323Sbostic 	|       S_WRITE strarg range { (void) printfile($2, ($3.left.vp)->row,
189*45323Sbostic 			 ($3.left.vp)->col, ($3.right.vp)->row,
190*45323Sbostic 			 ($3.right.vp)->col);
191*45323Sbostic 			 xfree($2); }
192*45323Sbostic 	|	S_WRITE strarg	{ (void) printfile ($2, 0, 0, maxrow, maxcol);
193*45323Sbostic 			 xfree($2); }
194*45323Sbostic 	|       S_TBL strarg range { (void) tblprintfile($2, ($3.left.vp)->row,
195*45323Sbostic 			 ($3.left.vp)->col, ($3.right.vp)->row,
196*45323Sbostic 			 ($3.right.vp)->col);
197*45323Sbostic 			 xfree($2); }
198*45323Sbostic 	|	S_TBL strarg	{ (void)tblprintfile ($2, 0, 0, maxrow, maxcol);
199*45323Sbostic 			 xfree($2); }
200*45323Sbostic 	|       S_SHOW COL ':' COL
201*45323Sbostic 					{ showcol( $2, $4); }
202*45323Sbostic 	|       S_SHOW NUMBER ':' NUMBER
203*45323Sbostic 					{ showrow( $2, $4); }
204*45323Sbostic  	|	S_HIDE COL
205*45323Sbostic  					{ hide_col( $2 ); }
206*45323Sbostic  	|	S_HIDE NUMBER
207*45323Sbostic  					{ hide_row( $2 ); }
208*45323Sbostic 	|	S_COPY range var_or_range
209*45323Sbostic 					{ copy($2.left.vp,$2.right.vp,
210*45323Sbostic 					$3.left.vp,$3.right.vp); }
211*45323Sbostic 	|	S_ERASE
212*45323Sbostic 					{ eraser(lookat(showsr, showsc),
213*45323Sbostic 				        lookat(currow, curcol)); }
214*45323Sbostic 	|	S_ERASE var_or_range
215*45323Sbostic 					{ eraser($2.left.vp, $2.right.vp); }
216*45323Sbostic 	|	S_VALUE       { valueize_area(showsr, showsc, currow, curcol);
217*45323Sbostic 				 modflg++; }
218*45323Sbostic 	|	S_VALUE var_or_range { valueize_area(($2.left.vp)->row,
219*45323Sbostic 				($2.left.vp)->col,
220*45323Sbostic 				($2.right.vp)->row,
221*45323Sbostic 				($2.right.vp)->col); modflg++; }
222*45323Sbostic 	|	S_FILL num num  { fill(lookat(showsr, showsc),
223*45323Sbostic 				      lookat(currow, curcol), $2, $3); }
224*45323Sbostic 	|	S_FILL var_or_range num num
225*45323Sbostic 				 { fill($2.left.vp, $2.right.vp, $3, $4); }
226*45323Sbostic 	|	S_GOTO var_or_range {moveto($2.left.vp->row, $2.left.vp->col);}
227*45323Sbostic 	|       S_GOTO num          {num_search($2);}
228*45323Sbostic 	|       S_GOTO STRING       {str_search($2);}
229*45323Sbostic 	|	S_GOTO              {go_last();}
230*45323Sbostic 	|	S_DEFINE strarg       { struct ent_ptr arg1, arg2;
231*45323Sbostic 					arg1.vp = lookat(showsr, showsc);
232*45323Sbostic 					arg1.vf = 0;
233*45323Sbostic 					arg2.vp = lookat(currow, curcol);
234*45323Sbostic 					arg2.vf = 0;
235*45323Sbostic 					add_range($2, arg1, arg2, 1); }
236*45323Sbostic 
237*45323Sbostic 	|	S_DEFINE strarg range { add_range($2, $3.left, $3.right, 1); }
238*45323Sbostic 	|	S_DEFINE strarg var   { add_range($2, $3, $3, 0); }
239*45323Sbostic 	|	S_UNDEFINE var_or_range { del_range($2.left.vp, $2.right.vp); }
240*45323Sbostic  	|	S_SET setlist
241*45323Sbostic 	|	/* nothing */
242*45323Sbostic 	|	error;
243*45323Sbostic 
244*45323Sbostic term: 		var		{ $$ = new_var('v', $1); }
245*45323Sbostic 	|	K_FIXED term	{ $$ = new ('f', ENULL, $2); }
246*45323Sbostic 	|       '@' K_SUM '(' var_or_range ')'
247*45323Sbostic 				{ $$ = new_range(REDUCE | '+', $4); }
248*45323Sbostic 	|       '@' K_PROD '(' var_or_range ')'
249*45323Sbostic 				{ $$ = new_range (REDUCE | '*', $4); }
250*45323Sbostic 	|       '@' K_AVG '(' var_or_range ')'
251*45323Sbostic 				{ $$ = new_range (REDUCE | 'a', $4); }
252*45323Sbostic 	|       '@' K_STDDEV '(' var_or_range ')'
253*45323Sbostic 				{ $$ = new_range (REDUCE | 's', $4); }
254*45323Sbostic 	|       '@' K_COUNT '(' var_or_range ')'
255*45323Sbostic 				{ $$ = new_range (REDUCE | 'c', $4); }
256*45323Sbostic 	|       '@' K_MAX '(' var_or_range ')'
257*45323Sbostic 				{ $$ = new_range (REDUCE | MAX, $4); }
258*45323Sbostic 	|	'@' K_MAX '(' e ',' expr_list ')'
259*45323Sbostic 				{ $$ = new(LMAX, $6, $4); }
260*45323Sbostic 	|       '@' K_MIN '(' var_or_range ')'
261*45323Sbostic 				{ $$ = new_range (REDUCE | MIN, $4); }
262*45323Sbostic 	|	'@' K_MIN '(' e ',' expr_list ')'
263*45323Sbostic 				{ $$ = new(LMIN, $6, $4); }
264*45323Sbostic 	| '@' K_ABS '(' e ')'	 { $$ = new(ABS, ENULL, $4); }
265*45323Sbostic 	| '@' K_ACOS '(' e ')'	 { $$ = new(ACOS, ENULL, $4); }
266*45323Sbostic 	| '@' K_ASIN '(' e ')'	 { $$ = new(ASIN, ENULL, $4); }
267*45323Sbostic 	| '@' K_ATAN '(' e ')'	 { $$ = new(ATAN, ENULL, $4); }
268*45323Sbostic 	| '@' K_ATAN2 '(' e ',' e ')' { $$ = new(ATAN2, $4, $6); }
269*45323Sbostic 	| '@' K_CEIL '(' e ')'	 { $$ = new(CEIL, ENULL, $4); }
270*45323Sbostic 	| '@' K_COS '(' e ')'	 { $$ = new(COS, ENULL, $4); }
271*45323Sbostic 	| '@' K_EXP '(' e ')'	 { $$ = new(EXP, ENULL, $4); }
272*45323Sbostic 	| '@' K_FABS '(' e ')'	 { $$ = new(FABS, ENULL, $4); }
273*45323Sbostic 	| '@' K_FLOOR '(' e ')'	 { $$ = new(FLOOR, ENULL, $4); }
274*45323Sbostic 	| '@' K_HYPOT '(' e ',' e ')'	{ $$ = new(HYPOT, $4, $6); }
275*45323Sbostic 	| '@' K_LN '(' e ')'	 { $$ = new(LOG, ENULL, $4); }
276*45323Sbostic 	| '@' K_LOG '(' e ')'	 { $$ = new(LOG10, ENULL, $4); }
277*45323Sbostic 	| '@' K_POW '(' e ',' e ')'	{ $$ = new(POW, $4, $6); }
278*45323Sbostic 	| '@' K_SIN '(' e ')'	 { $$ = new(SIN, ENULL, $4); }
279*45323Sbostic 	| '@' K_SQRT '(' e ')'	 { $$ = new(SQRT, ENULL, $4); }
280*45323Sbostic 	| '@' K_TAN '(' e ')'	 { $$ = new(TAN, ENULL, $4); }
281*45323Sbostic 	| '@' K_DTR '(' e ')'	 { $$ = new(DTR, ENULL, $4); }
282*45323Sbostic 	| '@' K_RTD '(' e ')'	 { $$ = new(RTD, ENULL, $4); }
283*45323Sbostic 	| '@' K_RND '(' e ')'	 { $$ = new(RND, ENULL, $4); }
284*45323Sbostic 	| '@' K_ROUND '(' e ',' e ')'	 { $$ = new(ROUND, $4, $6); }
285*45323Sbostic 	| '@' K_IF  '(' e ',' e ',' e ')' { $$ = new(IF,  $4,new(',',$6,$8)); }
286*45323Sbostic 
287*45323Sbostic 	| '@' K_PV  '(' e ',' e ',' e ')' { $$ = new(PV,  $4,new(':',$6,$8)); }
288*45323Sbostic  	| '@' K_FV  '(' e ',' e ',' e ')' { $$ = new(FV,  $4,new(':',$6,$8)); }
289*45323Sbostic  	| '@' K_PMT '(' e ',' e ',' e ')' { $$ = new(PMT, $4,new(':',$6,$8)); }
290*45323Sbostic 
291*45323Sbostic 	| '@' K_HOUR '(' e ')' 	 { $$ = new(HOUR,ENULL, $4); }
292*45323Sbostic 	| '@' K_MINUTE '(' e ')' { $$ = new(MINUTE,ENULL, $4); }
293*45323Sbostic 	| '@' K_SECOND '(' e ')' { $$ = new(SECOND,ENULL, $4); }
294*45323Sbostic 	| '@' K_MONTH '(' e ')'	 { $$ = new(MONTH,ENULL,$4); }
295*45323Sbostic 	| '@' K_DAY '(' e ')'    { $$ = new(DAY, ENULL, $4); }
296*45323Sbostic 	| '@' K_YEAR '(' e ')'   { $$ = new(YEAR, ENULL, $4); }
297*45323Sbostic 	| '@' K_NOW              { $$ = new(NOW, ENULL, ENULL);}
298*45323Sbostic 	| '@' K_DTS '(' e ',' e ',' e ')'
299*45323Sbostic 		  		 { $$ = new(DTS, $4, new(',', $6, $8));}
300*45323Sbostic 	| '@' K_TTS '(' e ',' e ',' e ')'
301*45323Sbostic 		  		 { $$ = new(TTS, $4, new(',', $6, $8));}
302*45323Sbostic 	| '@' K_STON '(' e ')'   { $$ = new(STON, ENULL, $4); }
303*45323Sbostic 	| '@' K_EQS '(' e ',' e ')' { $$ = new (EQS, $4, $6); }
304*45323Sbostic 	| '@' K_DATE '(' e ')'	 { $$ = new(DATE, ENULL, $4); }
305*45323Sbostic 	| '@' K_FMT  '(' e ',' e ')' { $$ = new(FMT, $4, $6); }
306*45323Sbostic 	| '@' K_INDEX  '(' e ',' var_or_range ')'
307*45323Sbostic 		 { $$ = new(INDEX, $4, new_range(REDUCE | INDEX, $6)); }
308*45323Sbostic 	| '@' K_LOOKUP  '(' e ',' var_or_range ')'
309*45323Sbostic 		 { $$ = new(LOOKUP, $4, new_range(REDUCE | LOOKUP, $6)); }
310*45323Sbostic 	| '@' K_HLOOKUP  '(' e ',' var_or_range ',' e ')'
311*45323Sbostic 		 { $$ = new(HLOOKUP, new(',', $4, $8),
312*45323Sbostic 		    new_range(REDUCE | HLOOKUP, $6)); }
313*45323Sbostic 	| '@' K_VLOOKUP  '(' e ',' var_or_range ',' e ')'
314*45323Sbostic 		 { $$ = new(VLOOKUP, new(',', $4, $8),
315*45323Sbostic 		    new_range(REDUCE | VLOOKUP, $6)); }
316*45323Sbostic 	| '@' K_STINDEX  '(' e ',' var_or_range ')'
317*45323Sbostic 		 { $$ = new(STINDEX, $4, new_range(REDUCE | STINDEX, $6)); }
318*45323Sbostic 	| '@' K_EXT  '(' e ',' e ')' { $$ = new(EXT, $4, $6); }
319*45323Sbostic 	| '@' K_NVAL '(' e ',' e ')' { $$ = new(NVAL, $4, $6); }
320*45323Sbostic 	| '@' K_SVAL '(' e ',' e ')' { $$ = new(SVAL, $4, $6); }
321*45323Sbostic 	| '@' K_SUBSTR '(' e ',' e ',' e ')'
322*45323Sbostic 				 { $$ = new(SUBSTR, $4, new(',', $6, $8)); }
323*45323Sbostic 	|	'(' e ')'	 { $$ = $2; }
324*45323Sbostic 	|	'+' term	 { $$ = $2; }
325*45323Sbostic 	|	'-' term	 { $$ = new ('m', ENULL, $2); }
326*45323Sbostic 	|	NUMBER		 { $$ = new_const('k', (double) $1); }
327*45323Sbostic 	|	FNUMBER		 { $$ = new_const('k', $1); }
328*45323Sbostic 	|	K_PI	{ $$ = new_const('k', (double)3.14159265358979323846); }
329*45323Sbostic 	|	STRING	         { $$ = new_str($1); }
330*45323Sbostic 	|	'~' term	 { $$ = new ('~', ENULL, $2); }
331*45323Sbostic 	|	'!' term	 { $$ = new ('~', ENULL, $2); }
332*45323Sbostic 	;
333*45323Sbostic 
334*45323Sbostic e:		e '+' e		{ $$ = new ('+', $1, $3); }
335*45323Sbostic 	|	e '-' e		{ $$ = new ('-', $1, $3); }
336*45323Sbostic 	|	e '*' e		{ $$ = new ('*', $1, $3); }
337*45323Sbostic 	|	e '/' e		{ $$ = new ('/', $1, $3); }
338*45323Sbostic 	|	e '%' e		{ $$ = new ('%', $1, $3); }
339*45323Sbostic 	|	e '^' e		{ $$ = new ('^', $1, $3); }
340*45323Sbostic 	|	term
341*45323Sbostic 	|	e '?' e ':' e	{ $$ = new ('?', $1, new(':', $3, $5)); }
342*45323Sbostic 	|	e '<' e		{ $$ = new ('<', $1, $3); }
343*45323Sbostic 	|	e '=' e		{ $$ = new ('=', $1, $3); }
344*45323Sbostic 	|	e '>' e		{ $$ = new ('>', $1, $3); }
345*45323Sbostic 	|	e '&' e		{ $$ = new ('&', $1, $3); }
346*45323Sbostic 	|	e '|' e		{ $$ = new ('|', $1, $3); }
347*45323Sbostic 	|	e '<' '=' e	{ $$ = new ('~', ENULL, new ('>', $1, $4)); }
348*45323Sbostic 	|	e '!' '=' e	{ $$ = new ('~', ENULL, new ('=', $1, $4)); }
349*45323Sbostic 	|	e '>' '=' e	{ $$ = new ('~', ENULL, new ('<', $1, $4)); }
350*45323Sbostic 	|	e '#' e		{ $$ = new ('#', $1, $3); }
351*45323Sbostic 	;
352*45323Sbostic 
353*45323Sbostic expr_list:	e		{ $$ = new(ELIST, ENULL, $1); }
354*45323Sbostic 	|	expr_list ',' e	{ $$ = new(ELIST, $1, $3); }
355*45323Sbostic 	;
356*45323Sbostic 
357*45323Sbostic range:		var ':' var	{ $$.left = $1; $$.right = $3; }
358*45323Sbostic 	| 	RANGE		{ $$ = $1; }
359*45323Sbostic 	;
360*45323Sbostic 
361*45323Sbostic var:		COL NUMBER	{ $$.vp = lookat($2 , $1); $$.vf = 0;}
362*45323Sbostic 	|	'$' COL NUMBER	{ $$.vp = lookat($3 , $2);
363*45323Sbostic 					$$.vf = FIX_COL;}
364*45323Sbostic 	|	COL '$' NUMBER	{ $$.vp = lookat($3 , $1);
365*45323Sbostic 					$$.vf = FIX_ROW;}
366*45323Sbostic 	|	'$' COL '$' NUMBER { $$.vp = lookat($4 , $2);
367*45323Sbostic 					$$.vf = FIX_ROW | FIX_COL;}
368*45323Sbostic 	|	VAR		{ $$ = $1.left; }
369*45323Sbostic 	;
370*45323Sbostic 
371*45323Sbostic var_or_range:	range		{ $$ = $1; }
372*45323Sbostic 	|	var		{ $$.left = $1; $$.right = $1; }
373*45323Sbostic 	;
374*45323Sbostic 
375*45323Sbostic num:		NUMBER		{ $$ = (double) $1; }
376*45323Sbostic 	|	FNUMBER		{ $$ = $1; }
377*45323Sbostic 	|	'-' num		{ $$ = -$2; }
378*45323Sbostic 	|	'+' num		{ $$ = $2; }
379*45323Sbostic 	;
380*45323Sbostic 
381*45323Sbostic strarg:		STRING		{ $$ = $1; }
382*45323Sbostic 	|	var		{
383*45323Sbostic 				    char *s, *s1;
384*45323Sbostic 				    s1 = $1.vp->label;
385*45323Sbostic 				    if (!s1)
386*45323Sbostic 					s1 = "NULL_STRING";
387*45323Sbostic 				    s = xmalloc((unsigned)strlen(s1)+1);
388*45323Sbostic 				    (void) strcpy(s, s1);
389*45323Sbostic 				    $$ = s;
390*45323Sbostic 				}
391*45323Sbostic   	;
392*45323Sbostic 
393*45323Sbostic setlist :
394*45323Sbostic 	|	setlist setitem
395*45323Sbostic 	;
396*45323Sbostic 
397*45323Sbostic setitem	:	K_AUTO		{ setauto(1); }
398*45323Sbostic 	|	K_AUTOCALC	{ setauto(1); }
399*45323Sbostic 	|	'~' K_AUTO	{ setauto(0); }
400*45323Sbostic 	|	'~' K_AUTOCALC	{ setauto(0); }
401*45323Sbostic 	|	'!' K_AUTO	{ setauto(0); }
402*45323Sbostic 	|	'!' K_AUTOCALC	{ setauto(0); }
403*45323Sbostic 	|	K_BYCOLS	{ setorder(BYCOLS); }
404*45323Sbostic 	|	K_BYROWS	{ setorder(BYROWS); }
405*45323Sbostic 	|	K_BYGRAPH	{ setorder(BYGRAPH); }
406*45323Sbostic 	|	K_NUMERIC	{ numeric = 1; }
407*45323Sbostic 	|	'!' K_NUMERIC	{ numeric = 0; }
408*45323Sbostic 	|	K_PRESCALE	{ prescale = 0.01; }
409*45323Sbostic 	|	'!' K_PRESCALE	{ prescale = 1.0; }
410*45323Sbostic 	|	K_EXTFUN	{ extfunc = 1; }
411*45323Sbostic 	|	'!' K_EXTFUN	{ extfunc = 0; }
412*45323Sbostic 	|	K_CELLCUR	{ showcell = 1; }
413*45323Sbostic 	|	'!' K_CELLCUR	{ showcell = 0; }
414*45323Sbostic 	|	K_TOPROW	{ showtop = 1; }
415*45323Sbostic 	|	'!' K_TOPROW	{ showtop = 0; }
416*45323Sbostic 	|	K_ITERATIONS '=' NUMBER	{ setiterations($3); }
417*45323Sbostic 	|	K_TBLSTYLE '=' NUMBER	{ tbl_style = $3; }
418*45323Sbostic 	|	K_TBLSTYLE '=' K_TBL	{ tbl_style = TBL; }
419*45323Sbostic 	|	K_TBLSTYLE '=' K_LATEX	{ tbl_style = LATEX; }
420*45323Sbostic 	|	K_TBLSTYLE '=' K_TEX	{ tbl_style = TEX; }
421*45323Sbostic   	;
422