eqn.y revision 75584
175584Sru/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. 275584Sru Written by James Clark (jjc@jclark.com) 375584Sru 475584SruThis file is part of groff. 575584Sru 675584Srugroff is free software; you can redistribute it and/or modify it under 775584Sruthe terms of the GNU General Public License as published by the Free 875584SruSoftware Foundation; either version 2, or (at your option) any later 975584Sruversion. 1075584Sru 1175584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY 1275584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or 1375584SruFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1475584Srufor more details. 1575584Sru 1675584SruYou should have received a copy of the GNU General Public License along 1775584Sruwith groff; see the file COPYING. If not, write to the Free Software 1875584SruFoundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 1975584Sru%{ 2075584Sru#include <stdio.h> 2175584Sru#include <string.h> 2275584Sru#include <stdlib.h> 2375584Sru 2475584Sru#include "lib.h" 2575584Sru#include "box.h" 2675584Sruextern int non_empty_flag; 2775584Sruchar *strsave(const char *); 2875584Sruint yylex(); 2975584Sruvoid yyerror(const char *); 3075584Sru%} 3175584Sru 3275584Sru%union { 3375584Sru char *str; 3475584Sru box *b; 3575584Sru pile_box *pb; 3675584Sru matrix_box *mb; 3775584Sru int n; 3875584Sru column *col; 3975584Sru} 4075584Sru 4175584Sru%token OVER 4275584Sru%token SMALLOVER 4375584Sru%token SQRT 4475584Sru%token SUB 4575584Sru%token SUP 4675584Sru%token LPILE 4775584Sru%token RPILE 4875584Sru%token CPILE 4975584Sru%token PILE 5075584Sru%token LEFT 5175584Sru%token RIGHT 5275584Sru%token TO 5375584Sru%token FROM 5475584Sru%token SIZE 5575584Sru%token FONT 5675584Sru%token ROMAN 5775584Sru%token BOLD 5875584Sru%token ITALIC 5975584Sru%token FAT 6075584Sru%token ACCENT 6175584Sru%token BAR 6275584Sru%token UNDER 6375584Sru%token ABOVE 6475584Sru%token <str> TEXT 6575584Sru%token <str> QUOTED_TEXT 6675584Sru%token FWD 6775584Sru%token BACK 6875584Sru%token DOWN 6975584Sru%token UP 7075584Sru%token MATRIX 7175584Sru%token COL 7275584Sru%token LCOL 7375584Sru%token RCOL 7475584Sru%token CCOL 7575584Sru%token MARK 7675584Sru%token LINEUP 7775584Sru%token TYPE 7875584Sru%token VCENTER 7975584Sru%token PRIME 8075584Sru%token SPLIT 8175584Sru%token NOSPLIT 8275584Sru%token UACCENT 8375584Sru%token SPECIAL 8475584Sru 8575584Sru/* these are handled in the lexer */ 8675584Sru%token SPACE 8775584Sru%token GFONT 8875584Sru%token GSIZE 8975584Sru%token DEFINE 9075584Sru%token NDEFINE 9175584Sru%token TDEFINE 9275584Sru%token SDEFINE 9375584Sru%token UNDEF 9475584Sru%token IFDEF 9575584Sru%token INCLUDE 9675584Sru%token DELIM 9775584Sru%token CHARTYPE 9875584Sru%token SET 9975584Sru%token GRFONT 10075584Sru%token GBFONT 10175584Sru 10275584Sru/* The original eqn manual says that `left' is right associative. It's lying. 10375584SruConsider `left ( ~ left ( ~ right ) right )'. */ 10475584Sru 10575584Sru%right LEFT 10675584Sru%left RIGHT 10775584Sru%right LPILE RPILE CPILE PILE TEXT QUOTED_TEXT MATRIX MARK LINEUP '^' '~' '\t' '{' SPLIT NOSPLIT 10875584Sru%right FROM TO 10975584Sru%left SQRT OVER SMALLOVER 11075584Sru%right SUB SUP 11175584Sru%right ROMAN BOLD ITALIC FAT FONT SIZE FWD BACK DOWN UP TYPE VCENTER SPECIAL 11275584Sru%right BAR UNDER PRIME 11375584Sru%left ACCENT UACCENT 11475584Sru 11575584Sru%type <b> mark from_to sqrt_over script simple equation nonsup 11675584Sru%type <n> number 11775584Sru%type <str> text delim 11875584Sru%type <pb> pile_element_list pile_arg 11975584Sru%type <mb> column_list 12075584Sru%type <col> column column_arg column_element_list 12175584Sru 12275584Sru%% 12375584Srutop: 12475584Sru /* empty */ 12575584Sru | equation 12675584Sru { $1->top_level(); non_empty_flag = 1; } 12775584Sru ; 12875584Sru 12975584Sruequation: 13075584Sru mark 13175584Sru { $$ = $1; } 13275584Sru | equation mark 13375584Sru { 13475584Sru list_box *lb = $1->to_list_box(); 13575584Sru if (!lb) 13675584Sru lb = new list_box($1); 13775584Sru lb->append($2); 13875584Sru $$ = lb; 13975584Sru } 14075584Sru ; 14175584Sru 14275584Srumark: 14375584Sru from_to 14475584Sru { $$ = $1; } 14575584Sru | MARK mark 14675584Sru { $$ = make_mark_box($2); } 14775584Sru | LINEUP mark 14875584Sru { $$ = make_lineup_box($2); } 14975584Sru ; 15075584Sru 15175584Srufrom_to: 15275584Sru sqrt_over %prec FROM 15375584Sru { $$ = $1; } 15475584Sru | sqrt_over TO from_to 15575584Sru { $$ = make_limit_box($1, 0, $3); } 15675584Sru | sqrt_over FROM sqrt_over 15775584Sru { $$ = make_limit_box($1, $3, 0); } 15875584Sru | sqrt_over FROM sqrt_over TO from_to 15975584Sru { $$ = make_limit_box($1, $3, $5); } 16075584Sru | sqrt_over FROM sqrt_over FROM from_to 16175584Sru { $$ = make_limit_box($1, make_limit_box($3, $5, 0), 0); } 16275584Sru ; 16375584Sru 16475584Srusqrt_over: 16575584Sru script 16675584Sru { $$ = $1; } 16775584Sru | SQRT sqrt_over 16875584Sru { $$ = make_sqrt_box($2); } 16975584Sru | sqrt_over OVER sqrt_over 17075584Sru { $$ = make_over_box($1, $3); } 17175584Sru | sqrt_over SMALLOVER sqrt_over 17275584Sru { $$ = make_small_over_box($1, $3); } 17375584Sru ; 17475584Sru 17575584Sruscript: 17675584Sru nonsup 17775584Sru { $$ = $1; } 17875584Sru | simple SUP script 17975584Sru { $$ = make_script_box($1, 0, $3); } 18075584Sru ; 18175584Sru 18275584Srunonsup: 18375584Sru simple %prec SUP 18475584Sru { $$ = $1; } 18575584Sru | simple SUB nonsup 18675584Sru { $$ = make_script_box($1, $3, 0); } 18775584Sru | simple SUB simple SUP script 18875584Sru { $$ = make_script_box($1, $3, $5); } 18975584Sru ; 19075584Sru 19175584Srusimple: 19275584Sru TEXT 19375584Sru { $$ = split_text($1); } 19475584Sru | QUOTED_TEXT 19575584Sru { $$ = new quoted_text_box($1); } 19675584Sru | SPLIT QUOTED_TEXT 19775584Sru { $$ = split_text($2); } 19875584Sru | NOSPLIT TEXT 19975584Sru { $$ = new quoted_text_box($2); } 20075584Sru | '^' 20175584Sru { $$ = new half_space_box; } 20275584Sru | '~' 20375584Sru { $$ = new space_box; } 20475584Sru | '\t' 20575584Sru { $$ = new tab_box; } 20675584Sru | '{' equation '}' 20775584Sru { $$ = $2; } 20875584Sru | PILE pile_arg 20975584Sru { $2->set_alignment(CENTER_ALIGN); $$ = $2; } 21075584Sru | LPILE pile_arg 21175584Sru { $2->set_alignment(LEFT_ALIGN); $$ = $2; } 21275584Sru | RPILE pile_arg 21375584Sru { $2->set_alignment(RIGHT_ALIGN); $$ = $2; } 21475584Sru | CPILE pile_arg 21575584Sru { $2->set_alignment(CENTER_ALIGN); $$ = $2; } 21675584Sru | MATRIX '{' column_list '}' 21775584Sru { $$ = $3; } 21875584Sru | LEFT delim equation RIGHT delim 21975584Sru { $$ = make_delim_box($2, $3, $5); } 22075584Sru | LEFT delim equation 22175584Sru { $$ = make_delim_box($2, $3, 0); } 22275584Sru | simple BAR 22375584Sru { $$ = make_overline_box($1); } 22475584Sru | simple UNDER 22575584Sru { $$ = make_underline_box($1); } 22675584Sru | simple PRIME 22775584Sru { $$ = make_prime_box($1); } 22875584Sru | simple ACCENT simple 22975584Sru { $$ = make_accent_box($1, $3); } 23075584Sru | simple UACCENT simple 23175584Sru { $$ = make_uaccent_box($1, $3); } 23275584Sru | ROMAN simple 23375584Sru { $$ = new font_box(strsave(get_grfont()), $2); } 23475584Sru | BOLD simple 23575584Sru { $$ = new font_box(strsave(get_gbfont()), $2); } 23675584Sru | ITALIC simple 23775584Sru { $$ = new font_box(strsave(get_gfont()), $2); } 23875584Sru | FAT simple 23975584Sru { $$ = new fat_box($2); } 24075584Sru | FONT text simple 24175584Sru { $$ = new font_box($2, $3); } 24275584Sru | SIZE text simple 24375584Sru { $$ = new size_box($2, $3); } 24475584Sru | FWD number simple 24575584Sru { $$ = new hmotion_box($2, $3); } 24675584Sru | BACK number simple 24775584Sru { $$ = new hmotion_box(-$2, $3); } 24875584Sru | UP number simple 24975584Sru { $$ = new vmotion_box($2, $3); } 25075584Sru | DOWN number simple 25175584Sru { $$ = new vmotion_box(-$2, $3); } 25275584Sru | TYPE text simple 25375584Sru { $3->set_spacing_type($2); $$ = $3; } 25475584Sru | VCENTER simple 25575584Sru { $$ = new vcenter_box($2); } 25675584Sru | SPECIAL text simple 25775584Sru { $$ = make_special_box($2, $3); } 25875584Sru ; 25975584Sru 26075584Srunumber: 26175584Sru text 26275584Sru { 26375584Sru int n; 26475584Sru if (sscanf($1, "%d", &n) == 1) 26575584Sru $$ = n; 26675584Sru a_delete $1; 26775584Sru } 26875584Sru ; 26975584Sru 27075584Srupile_element_list: 27175584Sru equation 27275584Sru { $$ = new pile_box($1); } 27375584Sru | pile_element_list ABOVE equation 27475584Sru { $1->append($3); $$ = $1; } 27575584Sru ; 27675584Sru 27775584Srupile_arg: 27875584Sru '{' pile_element_list '}' 27975584Sru { $$ = $2; } 28075584Sru | number '{' pile_element_list '}' 28175584Sru { $3->set_space($1); $$ = $3; } 28275584Sru ; 28375584Sru 28475584Srucolumn_list: 28575584Sru column 28675584Sru { $$ = new matrix_box($1); } 28775584Sru | column_list column 28875584Sru { $1->append($2); $$ = $1; } 28975584Sru ; 29075584Sru 29175584Srucolumn_element_list: 29275584Sru equation 29375584Sru { $$ = new column($1); } 29475584Sru | column_element_list ABOVE equation 29575584Sru { $1->append($3); $$ = $1; } 29675584Sru ; 29775584Sru 29875584Srucolumn_arg: 29975584Sru '{' column_element_list '}' 30075584Sru { $$ = $2; } 30175584Sru | number '{' column_element_list '}' 30275584Sru { $3->set_space($1); $$ = $3; } 30375584Sru ; 30475584Sru 30575584Srucolumn: 30675584Sru COL column_arg 30775584Sru { $2->set_alignment(CENTER_ALIGN); $$ = $2; } 30875584Sru | LCOL column_arg 30975584Sru { $2->set_alignment(LEFT_ALIGN); $$ = $2; } 31075584Sru | RCOL column_arg 31175584Sru { $2->set_alignment(RIGHT_ALIGN); $$ = $2; } 31275584Sru | CCOL column_arg 31375584Sru { $2->set_alignment(CENTER_ALIGN); $$ = $2; } 31475584Sru ; 31575584Sru 31675584Srutext: TEXT 31775584Sru { $$ = $1; } 31875584Sru | QUOTED_TEXT 31975584Sru { $$ = $1; } 32075584Sru ; 32175584Sru 32275584Srudelim: 32375584Sru text 32475584Sru { $$ = $1; } 32575584Sru | '{' 32675584Sru { $$ = strsave("{"); } 32775584Sru | '}' 32875584Sru { $$ = strsave("}"); } 32975584Sru ; 33075584Sru 33175584Sru%% 332