xref: /titanic_52/usr/src/cmd/eqn/e.y (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate %{
2*7c478bd9Sstevel@tonic-gate /*
3*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate  * with the License.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
14*7c478bd9Sstevel@tonic-gate  *
15*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate  *
21*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate  */
23*7c478bd9Sstevel@tonic-gate %}
24*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
25*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate %{#
29*7c478bd9Sstevel@tonic-gate # ident	"%Z%%M%	%I%	%E% SMI"	/* "@(#)ucbeqn:e.y 1.1" */
30*7c478bd9Sstevel@tonic-gate #include "e.h"
31*7c478bd9Sstevel@tonic-gate #include <locale.h>
32*7c478bd9Sstevel@tonic-gate #
33*7c478bd9Sstevel@tonic-gate int	fromflg;
34*7c478bd9Sstevel@tonic-gate %}
35*7c478bd9Sstevel@tonic-gate %term	CONTIG QTEXT SPACE THIN TAB
36*7c478bd9Sstevel@tonic-gate %term	MATRIX LCOL CCOL RCOL COL
37*7c478bd9Sstevel@tonic-gate %term	MARK LINEUP
38*7c478bd9Sstevel@tonic-gate %term	SUM INT PROD UNION INTER
39*7c478bd9Sstevel@tonic-gate %term	LPILE PILE CPILE RPILE ABOVE
40*7c478bd9Sstevel@tonic-gate %term	DEFINE TDEFINE NDEFINE DELIM GSIZE GFONT INCLUDE
41*7c478bd9Sstevel@tonic-gate %right	FROM TO
42*7c478bd9Sstevel@tonic-gate %left	OVER SQRT
43*7c478bd9Sstevel@tonic-gate %right	SUP SUB
44*7c478bd9Sstevel@tonic-gate %right	SIZE FONT ROMAN ITALIC BOLD FAT
45*7c478bd9Sstevel@tonic-gate %right	UP DOWN BACK FWD
46*7c478bd9Sstevel@tonic-gate %left	LEFT RIGHT
47*7c478bd9Sstevel@tonic-gate %right	DOT DOTDOT HAT TILDE BAR UNDER VEC DYAD
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate %%
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate stuff	: eqn 	{ putout($1); }
52*7c478bd9Sstevel@tonic-gate 	| error	{ error(!FATAL, gettext("syntax error")); }
53*7c478bd9Sstevel@tonic-gate 	|	{ eqnreg = 0; }
54*7c478bd9Sstevel@tonic-gate 	;
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate eqn	: box
57*7c478bd9Sstevel@tonic-gate 	| eqn box	{ eqnbox($1, $2, 0); }
58*7c478bd9Sstevel@tonic-gate 	| eqn lineupbox	{ eqnbox($1, $2, 1); }
59*7c478bd9Sstevel@tonic-gate 	| LINEUP	{ lineup(0); }
60*7c478bd9Sstevel@tonic-gate 	;
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate lineupbox: LINEUP box	{ $$ = $2; lineup(1); }
63*7c478bd9Sstevel@tonic-gate 	;
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate matrix	: MATRIX	{ $$ = ct; } ;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate collist	: column
68*7c478bd9Sstevel@tonic-gate 	| collist column
69*7c478bd9Sstevel@tonic-gate 	;
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate column	: lcol '{' list '}'	{ column('L', $1); }
72*7c478bd9Sstevel@tonic-gate 	| ccol '{' list '}'	{ column('C', $1); }
73*7c478bd9Sstevel@tonic-gate 	| rcol '{' list '}'	{ column('R', $1); }
74*7c478bd9Sstevel@tonic-gate 	| col '{' list '}'	{ column('-', $1); }
75*7c478bd9Sstevel@tonic-gate 	;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate lcol	: LCOL		{ $$ = ct++; } ;
78*7c478bd9Sstevel@tonic-gate ccol	: CCOL		{ $$ = ct++; } ;
79*7c478bd9Sstevel@tonic-gate rcol	: RCOL		{ $$ = ct++; } ;
80*7c478bd9Sstevel@tonic-gate col	: COL		{ $$ = ct++; } ;
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate sbox	: sup box	%prec SUP	{ $$ = $2; }
83*7c478bd9Sstevel@tonic-gate 	;
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate tbox	: to box	%prec TO	{ $$ = $2; }
86*7c478bd9Sstevel@tonic-gate 	|		%prec FROM	{ $$ = 0; }
87*7c478bd9Sstevel@tonic-gate 	;
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate box	: box OVER box	{ boverb($1, $3); }
90*7c478bd9Sstevel@tonic-gate 	| MARK box	{ mark($2); }
91*7c478bd9Sstevel@tonic-gate 	| size box	%prec SIZE	{ size($1, $2); }
92*7c478bd9Sstevel@tonic-gate 	| font box	%prec FONT	{ font($1, $2); }
93*7c478bd9Sstevel@tonic-gate 	| FAT box	{ fatbox($2); }
94*7c478bd9Sstevel@tonic-gate 	| SQRT box	{ sqrt($2); }
95*7c478bd9Sstevel@tonic-gate 	| lpile '{' list '}'	{ lpile('L', $1, ct); ct = $1; }
96*7c478bd9Sstevel@tonic-gate 	| cpile '{' list '}'	{ lpile('C', $1, ct); ct = $1; }
97*7c478bd9Sstevel@tonic-gate 	| rpile '{' list '}'	{ lpile('R', $1, ct); ct = $1; }
98*7c478bd9Sstevel@tonic-gate 	| pile '{' list '}'	{ lpile('-', $1, ct); ct = $1; }
99*7c478bd9Sstevel@tonic-gate 	| box sub box sbox	%prec SUB	{ shift2($1, $3, $4); }
100*7c478bd9Sstevel@tonic-gate 	| box sub box		%prec SUB	{ bshiftb($1, $2, $3); }
101*7c478bd9Sstevel@tonic-gate 	| box sup box		%prec SUP	{ bshiftb($1, $2, $3); }
102*7c478bd9Sstevel@tonic-gate 	| int sub box sbox	%prec SUB	{ integral($1, $3, $4); }
103*7c478bd9Sstevel@tonic-gate 	| int sub box		%prec SUB	{ integral($1, $3, 0); }
104*7c478bd9Sstevel@tonic-gate 	| int sup box		%prec SUP	{ integral($1, 0, $3); }
105*7c478bd9Sstevel@tonic-gate 	| int					{ integral($1, 0, 0); }
106*7c478bd9Sstevel@tonic-gate 	| left eqn right	{ paren($1, $2, $3); }
107*7c478bd9Sstevel@tonic-gate 	| pbox
108*7c478bd9Sstevel@tonic-gate 	| box from box tbox	%prec FROM	{ fromto($1, $3, $4); fromflg=0; }
109*7c478bd9Sstevel@tonic-gate 	| box to box	%prec TO	{ fromto($1, 0, $3); }
110*7c478bd9Sstevel@tonic-gate 	| box diacrit	{ diacrit($1, $2); }
111*7c478bd9Sstevel@tonic-gate 	| fwd box	%prec UP	{ move(FWD, $1, $2); }
112*7c478bd9Sstevel@tonic-gate 	| up box	%prec UP	{ move(UP, $1, $2); }
113*7c478bd9Sstevel@tonic-gate 	| back box	%prec UP	{ move(BACK, $1, $2); }
114*7c478bd9Sstevel@tonic-gate 	| down box	%prec UP	{ move(DOWN, $1, $2); }
115*7c478bd9Sstevel@tonic-gate 	| matrix '{' collist '}'	{ matrix($1); }
116*7c478bd9Sstevel@tonic-gate 	;
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate int	: INT	{ setintegral(); }
119*7c478bd9Sstevel@tonic-gate 	;
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate fwd	: FWD text	{ $$ = atoi((char *) $1); } ;
122*7c478bd9Sstevel@tonic-gate up	: UP text	{ $$ = atoi((char *) $1); } ;
123*7c478bd9Sstevel@tonic-gate back	: BACK text	{ $$ = atoi((char *) $1); } ;
124*7c478bd9Sstevel@tonic-gate down	: DOWN text	{ $$ = atoi((char *) $1); } ;
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate diacrit	: HAT	{ $$ = HAT; }
127*7c478bd9Sstevel@tonic-gate 	| VEC	{ $$ = VEC; }
128*7c478bd9Sstevel@tonic-gate 	| DYAD	{ $$ = DYAD; }
129*7c478bd9Sstevel@tonic-gate 	| BAR	{ $$ = BAR; }
130*7c478bd9Sstevel@tonic-gate 	| UNDER	{ $$ = UNDER; }	/* under bar */
131*7c478bd9Sstevel@tonic-gate 	| DOT	{ $$ = DOT; }
132*7c478bd9Sstevel@tonic-gate 	| TILDE	{ $$ = TILDE; }
133*7c478bd9Sstevel@tonic-gate 	| DOTDOT	{ $$ = DOTDOT; } /* umlaut = double dot */
134*7c478bd9Sstevel@tonic-gate 	;
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate from	: FROM	{ $$=ps; ps -= 3; fromflg = 1;
137*7c478bd9Sstevel@tonic-gate 		if(dbg)printf(".\tfrom: old ps %d, new ps %d, fflg %d\n", $$, ps, fromflg);
138*7c478bd9Sstevel@tonic-gate 		}
139*7c478bd9Sstevel@tonic-gate 	;
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate to	: TO	{ $$=ps; if(fromflg==0)ps -= 3;
142*7c478bd9Sstevel@tonic-gate 			if(dbg)printf(".\tto: old ps %d, new ps %d\n", $$, ps);
143*7c478bd9Sstevel@tonic-gate 		}
144*7c478bd9Sstevel@tonic-gate 	;
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate left	: LEFT text	{ $$ = ((char *)$2)[0]; }
147*7c478bd9Sstevel@tonic-gate 	| LEFT '{'	{ $$ = '{'; }
148*7c478bd9Sstevel@tonic-gate 	;
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate right	: RIGHT text	{ $$ = ((char *)$2)[0]; }
151*7c478bd9Sstevel@tonic-gate 	| RIGHT '}'	{ $$ = '}'; }
152*7c478bd9Sstevel@tonic-gate 	|		{ $$ = 0; }
153*7c478bd9Sstevel@tonic-gate 	;
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate list	: eqn	{ lp[ct++] = $1; }
156*7c478bd9Sstevel@tonic-gate 	| list ABOVE eqn	{ lp[ct++] = $3; }
157*7c478bd9Sstevel@tonic-gate 	;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate lpile	: LPILE	{ $$ = ct; } ;
160*7c478bd9Sstevel@tonic-gate cpile	: CPILE	{ $$ = ct; } ;
161*7c478bd9Sstevel@tonic-gate pile	: PILE	{ $$ = ct; } ;
162*7c478bd9Sstevel@tonic-gate rpile	: RPILE	{ $$ = ct; } ;
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate size	: SIZE text	{ $$ = ps; setsize((char *) $2); }
165*7c478bd9Sstevel@tonic-gate 	;
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate font	: ROMAN		{ setfont(ROM); }
168*7c478bd9Sstevel@tonic-gate 	| ITALIC	{ setfont(ITAL); }
169*7c478bd9Sstevel@tonic-gate 	| BOLD		{ setfont(BLD); }
170*7c478bd9Sstevel@tonic-gate 	| FONT text	{ setfont(((char *)$2)[0]); }
171*7c478bd9Sstevel@tonic-gate 	;
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate sub	: SUB	{ shift(SUB); }
174*7c478bd9Sstevel@tonic-gate 	;
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate sup	: SUP	{ shift(SUP); }
177*7c478bd9Sstevel@tonic-gate 	;
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate pbox	: '{' eqn '}'	{ $$ = $2; }
180*7c478bd9Sstevel@tonic-gate 	| QTEXT		{ text(QTEXT, (char *) $1); }
181*7c478bd9Sstevel@tonic-gate 	| CONTIG	{ text(CONTIG, (char *) $1); }
182*7c478bd9Sstevel@tonic-gate 	| SPACE		{ text(SPACE, 0); }
183*7c478bd9Sstevel@tonic-gate 	| THIN		{ text(THIN, 0); }
184*7c478bd9Sstevel@tonic-gate 	| TAB		{ text(TAB, 0); }
185*7c478bd9Sstevel@tonic-gate 	| SUM		{ funny(SUM); }
186*7c478bd9Sstevel@tonic-gate 	| PROD		{ funny(PROD); }
187*7c478bd9Sstevel@tonic-gate 	| UNION		{ funny(UNION); }
188*7c478bd9Sstevel@tonic-gate 	| INTER		{ funny(INTER); }	/* intersection */
189*7c478bd9Sstevel@tonic-gate 	;
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate text	: CONTIG
192*7c478bd9Sstevel@tonic-gate 	| QTEXT
193*7c478bd9Sstevel@tonic-gate 	;
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate %%
196