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