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