No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / groff / src / preproc / eqn / eqn.y
blob74e216555fa3fbb92ed4d984b4dba054328fad07
1 /* $NetBSD$ */
3 /* Copyright (C) 1989, 1990, 1991, 1992, 2004 Free Software Foundation, Inc.
4 Written by James Clark (jjc@jclark.com)
6 This file is part of groff.
8 groff is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License along
19 with groff; see the file COPYING. If not, write to the Free Software
20 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
26 #include "lib.h"
27 #include "box.h"
28 extern int non_empty_flag;
29 int yylex();
30 void yyerror(const char *);
33 %union {
34 char *str;
35 box *b;
36 pile_box *pb;
37 matrix_box *mb;
38 int n;
39 column *col;
42 %token OVER
43 %token SMALLOVER
44 %token SQRT
45 %token SUB
46 %token SUP
47 %token LPILE
48 %token RPILE
49 %token CPILE
50 %token PILE
51 %token LEFT
52 %token RIGHT
53 %token TO
54 %token FROM
55 %token SIZE
56 %token FONT
57 %token ROMAN
58 %token BOLD
59 %token ITALIC
60 %token FAT
61 %token ACCENT
62 %token BAR
63 %token UNDER
64 %token ABOVE
65 %token <str> TEXT
66 %token <str> QUOTED_TEXT
67 %token FWD
68 %token BACK
69 %token DOWN
70 %token UP
71 %token MATRIX
72 %token COL
73 %token LCOL
74 %token RCOL
75 %token CCOL
76 %token MARK
77 %token LINEUP
78 %token TYPE
79 %token VCENTER
80 %token PRIME
81 %token SPLIT
82 %token NOSPLIT
83 %token UACCENT
84 %token SPECIAL
86 /* these are handled in the lexer */
87 %token SPACE
88 %token GFONT
89 %token GSIZE
90 %token DEFINE
91 %token NDEFINE
92 %token TDEFINE
93 %token SDEFINE
94 %token UNDEF
95 %token IFDEF
96 %token INCLUDE
97 %token DELIM
98 %token CHARTYPE
99 %token SET
100 %token GRFONT
101 %token GBFONT
103 /* The original eqn manual says that `left' is right associative. It's lying.
104 Consider `left ( ~ left ( ~ right ) right )'. */
106 %right LEFT
107 %left RIGHT
108 %right LPILE RPILE CPILE PILE TEXT QUOTED_TEXT MATRIX MARK LINEUP '^' '~' '\t' '{' SPLIT NOSPLIT
109 %right FROM TO
110 %left SQRT OVER SMALLOVER
111 %right SUB SUP
112 %right ROMAN BOLD ITALIC FAT FONT SIZE FWD BACK DOWN UP TYPE VCENTER SPECIAL
113 %right BAR UNDER PRIME
114 %left ACCENT UACCENT
116 %type <b> mark from_to sqrt_over script simple equation nonsup
117 %type <n> number
118 %type <str> text delim
119 %type <pb> pile_element_list pile_arg
120 %type <mb> column_list
121 %type <col> column column_arg column_element_list
124 top:
125 /* empty */
126 | equation
127 { $1->top_level(); non_empty_flag = 1; }
130 equation:
131 mark
132 { $$ = $1; }
133 | equation mark
135 list_box *lb = $1->to_list_box();
136 if (!lb)
137 lb = new list_box($1);
138 lb->append($2);
139 $$ = lb;
143 mark:
144 from_to
145 { $$ = $1; }
146 | MARK mark
147 { $$ = make_mark_box($2); }
148 | LINEUP mark
149 { $$ = make_lineup_box($2); }
152 from_to:
153 sqrt_over %prec FROM
154 { $$ = $1; }
155 | sqrt_over TO from_to
156 { $$ = make_limit_box($1, 0, $3); }
157 | sqrt_over FROM sqrt_over
158 { $$ = make_limit_box($1, $3, 0); }
159 | sqrt_over FROM sqrt_over TO from_to
160 { $$ = make_limit_box($1, $3, $5); }
161 | sqrt_over FROM sqrt_over FROM from_to
162 { $$ = make_limit_box($1, make_limit_box($3, $5, 0), 0); }
165 sqrt_over:
166 script
167 { $$ = $1; }
168 | SQRT sqrt_over
169 { $$ = make_sqrt_box($2); }
170 | sqrt_over OVER sqrt_over
171 { $$ = make_over_box($1, $3); }
172 | sqrt_over SMALLOVER sqrt_over
173 { $$ = make_small_over_box($1, $3); }
176 script:
177 nonsup
178 { $$ = $1; }
179 | simple SUP script
180 { $$ = make_script_box($1, 0, $3); }
183 nonsup:
184 simple %prec SUP
185 { $$ = $1; }
186 | simple SUB nonsup
187 { $$ = make_script_box($1, $3, 0); }
188 | simple SUB simple SUP script
189 { $$ = make_script_box($1, $3, $5); }
192 simple:
193 TEXT
194 { $$ = split_text($1); }
195 | QUOTED_TEXT
196 { $$ = new quoted_text_box($1); }
197 | SPLIT QUOTED_TEXT
198 { $$ = split_text($2); }
199 | NOSPLIT TEXT
200 { $$ = new quoted_text_box($2); }
201 | '^'
202 { $$ = new half_space_box; }
203 | '~'
204 { $$ = new space_box; }
205 | '\t'
206 { $$ = new tab_box; }
207 | '{' equation '}'
208 { $$ = $2; }
209 | PILE pile_arg
210 { $2->set_alignment(CENTER_ALIGN); $$ = $2; }
211 | LPILE pile_arg
212 { $2->set_alignment(LEFT_ALIGN); $$ = $2; }
213 | RPILE pile_arg
214 { $2->set_alignment(RIGHT_ALIGN); $$ = $2; }
215 | CPILE pile_arg
216 { $2->set_alignment(CENTER_ALIGN); $$ = $2; }
217 | MATRIX '{' column_list '}'
218 { $$ = $3; }
219 | LEFT delim equation RIGHT delim
220 { $$ = make_delim_box($2, $3, $5); }
221 | LEFT delim equation
222 { $$ = make_delim_box($2, $3, 0); }
223 | simple BAR
224 { $$ = make_overline_box($1); }
225 | simple UNDER
226 { $$ = make_underline_box($1); }
227 | simple PRIME
228 { $$ = make_prime_box($1); }
229 | simple ACCENT simple
230 { $$ = make_accent_box($1, $3); }
231 | simple UACCENT simple
232 { $$ = make_uaccent_box($1, $3); }
233 | ROMAN simple
234 { $$ = new font_box(strsave(get_grfont()), $2); }
235 | BOLD simple
236 { $$ = new font_box(strsave(get_gbfont()), $2); }
237 | ITALIC simple
238 { $$ = new font_box(strsave(get_gfont()), $2); }
239 | FAT simple
240 { $$ = new fat_box($2); }
241 | FONT text simple
242 { $$ = new font_box($2, $3); }
243 | SIZE text simple
244 { $$ = new size_box($2, $3); }
245 | FWD number simple
246 { $$ = new hmotion_box($2, $3); }
247 | BACK number simple
248 { $$ = new hmotion_box(-$2, $3); }
249 | UP number simple
250 { $$ = new vmotion_box($2, $3); }
251 | DOWN number simple
252 { $$ = new vmotion_box(-$2, $3); }
253 | TYPE text simple
254 { $3->set_spacing_type($2); $$ = $3; }
255 | VCENTER simple
256 { $$ = new vcenter_box($2); }
257 | SPECIAL text simple
258 { $$ = make_special_box($2, $3); }
261 number:
262 text
264 int n;
265 if (sscanf($1, "%d", &n) == 1)
266 $$ = n;
267 a_delete $1;
271 pile_element_list:
272 equation
273 { $$ = new pile_box($1); }
274 | pile_element_list ABOVE equation
275 { $1->append($3); $$ = $1; }
278 pile_arg:
279 '{' pile_element_list '}'
280 { $$ = $2; }
281 | number '{' pile_element_list '}'
282 { $3->set_space($1); $$ = $3; }
285 column_list:
286 column
287 { $$ = new matrix_box($1); }
288 | column_list column
289 { $1->append($2); $$ = $1; }
292 column_element_list:
293 equation
294 { $$ = new column($1); }
295 | column_element_list ABOVE equation
296 { $1->append($3); $$ = $1; }
299 column_arg:
300 '{' column_element_list '}'
301 { $$ = $2; }
302 | number '{' column_element_list '}'
303 { $3->set_space($1); $$ = $3; }
306 column:
307 COL column_arg
308 { $2->set_alignment(CENTER_ALIGN); $$ = $2; }
309 | LCOL column_arg
310 { $2->set_alignment(LEFT_ALIGN); $$ = $2; }
311 | RCOL column_arg
312 { $2->set_alignment(RIGHT_ALIGN); $$ = $2; }
313 | CCOL column_arg
314 { $2->set_alignment(CENTER_ALIGN); $$ = $2; }
317 text: TEXT
318 { $$ = $1; }
319 | QUOTED_TEXT
320 { $$ = $1; }
323 delim:
324 text
325 { $$ = $1; }
326 | '{'
327 { $$ = strsave("{"); }
328 | '}'
329 { $$ = strsave("}"); }