Interdata_v6/usr/source/troff/neqn/src.a

Find at most related files.
including files from this version of Unix.

ene.g~Q
\{#
#
int	fromflg	0;
\}
%term	CONTIG QTEXT  SPACE THIN TAB
%term	MATRIX LCOL CCOL RCOL COL
%term	MARK LINEUP
%term	SUM INT PROD UNION INTER
%term	LPILE PILE CPILE RPILE ABOVE
%term	DEFINE TDEFINE NDEFINE DELIM  GSIZE GFONT
%right	FROM TO
%left	OVER SQRT
%right	SUP SUB
%right	SIZE FONT ROMAN ITALIC BOLD FAT
%right	UP DOWN BACK FWD
%left	MQ MQ1
%left	LEFT RIGHT
%right	DOT DOTDOT HAT TILDE BAR UNDER VEC DYAD

%%

stuff	: eqn 	={ putout($1); }
	| error	={ error(!FATAL, "syntax error in equation %d", first);  }
	|	={ eqnreg = 0; }
	;

eqn	: box	={ if(dbg)printf(".\teqn: S%d\n",$1); }
	| eqn box	={ eqnbox($1,$2); }
	| eqn MARK	={ mark($1); }
	| MARK	={ mark(0); }
	| eqn LINEUP	={ lineup($1); }
	| LINEUP	={ lineup(0); }
	;

matrix	: MATRIX	={ $$ = ct; } ;

collist	: column
	| collist column
	;

column	: lcol MQ list MQ1	={ column('L',$1,$3); }
	| ccol MQ list MQ1	={ column('C',$1,$3); }
	| rcol MQ list MQ1	={ column('R',$1,$3); }
	| col MQ list MQ1	={ column('-',$1,$3); }
	;

lcol	: LCOL	={ $$ = ct++; } ;
ccol	: CCOL	={ $$ = ct++; } ;
rcol	: RCOL	={ $$ = ct++; } ;
col	: COL	={ $$ = ct++; } ;

sbox	: sup box	%prec SUP	={ $$ = $2; }
	;

tbox	: to box	%prec TO	={ $$ = $2; }
	|	%prec FROM	={ $$ = 0; }
	;

box	: box OVER box	={ boverb($1,$3); }
	| size box	%prec SIZE	={ size($1, $2); }
	| font box	%prec FONT	={ font($1, $2); }
	| FAT box	={ $$ = $2; }
	| SQRT box	={ sqrt($2); }
	| lpile MQ list MQ1	={ lpile('L', $1, ct); ct = $1; }
	| cpile MQ list MQ1	={ lpile('C', $1, ct); ct = $1; }
	| rpile MQ list MQ1	={ lpile('R', $1, ct); ct = $1; }
	| pile MQ list MQ1	={ lpile('-', $1, ct); ct = $1; }
	| box sub box sbox	%prec SUB
		={ if(dbg)printf(".\t sub box %d %d %d\n",$1,$3,$4);
			shift2($1, $3, $4);
		}
	| box sub box	%prec SUB	={ bshiftb($1, $2, $3); }
	| box sup box	%prec SUP	={ bshiftb($1, $2, $3); }
	| left eqn right	={ paren($1, $2, $3); }
	| pbox
	| box from box tbox	%prec FROM
		={ fromto($1,$3,$4); fromflg=0; }
	| box to box	%prec TO	={ fromto($1, 0, $3); }
	| box diacrit	={ diacrit($1,$2); }
	| fwd box	%prec UP	={ move(0,$1,$2); }
	| up box	%prec UP	={ move(1,$1,$2); }
	| back box	%prec UP	={ move(2,$1,$2); }
	| down box	%prec UP	={ move(3,$1,$2); }
	| matrix MQ collist MQ1	={ matrix($1,$3); }
	;

fwd	: FWD text	={ $$ = numb($1); } ;
up	: UP text	={ $$ = numb($1); } ;
back	: BACK text	={ $$ = numb($1); } ;
down	: DOWN text	={ $$ = numb($1); } ;

diacrit	: HAT	={ $$ = 'H'; }
	| VEC	={ $$ = 'V'; }
	| DYAD	={ $$ = 'Y'; }
	| BAR	={ $$ = 'B'; }
	| UNDER	={ $$ = 'N'; }	/* under bar */
	| DOT	={ $$ = 'D'; }
	| TILDE	={ $$ = 'T'; }
	| DOTDOT	={ $$ = 'U'; } /* umlaut = double dot */
	;

from	: FROM
	;
to	: TO
	;

left	: LEFT text	={ $$ = $2->c1; }
	| LEFT MQ	={ $$ = '{'; }
	;

right	: RIGHT text	={ $$ = $2->c1; }
	| RIGHT MQ1	={ $$ = '}'; }
	|		={ $$ = 0; }
	;

list	: eqn	={ lp[ct++] = $1; }
	| list ABOVE eqn	={ lp[ct++] = $3; }
	;

lpile	: LPILE	={ $$=ct; } ;
cpile	: CPILE	={ $$=ct; } ;
pile	: PILE	={ $$=ct; } ;
rpile	: RPILE	={ $$=ct; } ;

size	: SIZE text
	;

font	: ROMAN
	| ITALIC
	| BOLD
	| FONT text
	;

sub	: SUB	={ shift(1); } ;

sup	: SUP	={ shift(-1); } ;

pbox	: MQ eqn MQ1	={ $$ = $2; }
	| QTEXT	={ text('q',$1); }
	| CONTIG	={ text('c',$1); }
	| SPACE	={ text('~', $1); }
	| THIN	={ text('^', $1); }
	| TAB	={ text('\t', $1); }
	| SUM	={ funny('S'); }
	| PROD	={ funny('P'); }
	| INT	={ funny('I'); }
	| UNION	={ funny('U'); }
	| INTER	={ funny('A'); }	/* intersection */
	;

text	: CONTIG
	| QTEXT
	| SPACE	={ $$ = & "\\|\\|"; }
	| THIN	={ $$ = & "\\|"; }
	;

%%
tne.h~S#define	FATAL	1
#ifdef gcos
#define fout cout
#define fin cin
#define close cclose
#define exit cexit
#define signal wdleng
#define flush wdleng
#define dup(n) n
#define alloc(n) calloc(n, 1)
#define free(p) cfree(p, 0, 0)
#define open(f,m) copen(f, m==1 ? 'w' : 'r')
#endif

#define	VERT(n)	(20*n)

extern int	dbg;
extern int	ct;
extern int	lp[40];
extern int	used[100];	/* available registers */
extern int	ps;	/* dflt init pt size */
extern int	ft;	/* dflt font */
extern int	first;
extern int	fout, fin;
extern int	ifile;
extern int	linect;	/* line number in file */
extern int	eqline;	/* line where eqn started */
extern int	svargc;
extern char	**svargv;
extern int	eht[100];
extern int	ebase[100];
struct { char c1; char c2; };
extern int	yyval;
extern int	*yypv;
extern int	yylval;
extern int	tht[30];
extern int	tbase[30];
extern int	ptr;
extern struct	{
	char *nptr;
	char *sptr;
} deftab[100];
extern int	eqnreg, eqnht;
extern int	lefteq, righteq;
extern int	lastchar;	/* last character read by lex */
ne0.c~U#int	dbg;
int	lp[40];	/* stack for things like piles and matrices */
int	ct;	/* pointer to lp */
int	used[100];	/* available registers */
int	ps;	/* dflt init pt size */
int	ft;	/* dflt font */
int	first;
extern	int	fout, fin;
int	ifile;
int	linect;	/* line number in file */
int	eqline;	/* line where eqn started */
int	svargc;
char	**svargv;
int	eht[100];
int	ebase[100];
int	tht[30];
int	tbase[30];
int	ptr;
struct	{
	char *nptr;
	char *sptr;
} deftab[100];
int	eqnreg, eqnht;
int	lefteq, righteq;
int	lastchar;	/* last character read by lex */
hne1.c~W# include "ne.h"

boverb(p1, p2) int p1, p2; {
	int h, b, treg;
	treg = oalloc();
	yyval = p1;
	h = eht[p1] + eht[p2];
	b = eht[p2] - VERT(1);
	if(dbg)printf(".\tb:bob: S%d <- S%d over S%d; b=%d, h=%d\n", 
		yyval, p1, p2, b, h);
	nrwid(p1, ps, p1);
	nrwid(p2, ps, p2);
	printf(".nr %d \\n(%d\n", treg, p1);
	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
	printf(".ds %d \\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d\\\n", 
		yyval, eht[p2]-ebase[p2]-VERT(1), treg, p2, p2);
	printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%du'\\*(%d\\\n", 
		p2, p1, -eht[p2]+ebase[p2]-ebase[p1], p1);
	printf("\\h'-\\n(%du-\\n(%du-2u/2u'\\v'%du'\\l'\\n(%du'\\v'%du'\n", 
		 treg, p1, ebase[p1], treg, VERT(1));
	ebase[yyval] = b;
	eht[yyval] = h;
	ofree(p2);
	ofree(treg);
}

bshiftb(p1, dir, p2) int p1, dir, p2; {
	int shval, sh1, sh2, effps, effps2, d1, h1, b1, h2, b2, h;
	int diffps;
	yyval = p1;
	h1 = eht[p1]; b1 = ebase[p1];
	h2 = eht[p2]; b2 = ebase[p2];
	if( dir > 0 ) {	/* subscript */
		d1 = VERT(1);
		shval = - d1 + h2 - b2;
		if( d1+b1 > h2 ) /* move little sub down */
			shval = b1-b2;
		ebase[yyval] = b1 + max(0, h2-b1-d1);
		eht[yyval] = h1 + max(0, h2-b1-d1);
	} else {	/* superscript */
		d1 = VERT(1);
		ebase[yyval] = b1;
		shval = -VERT(1) - b2;
		if( VERT(1) + h2 < h1-b1 )	/* raise little super */
			shval = -(h1-b1) + h2-b2 - d1;
		eht[yyval] = h1 + max(0, h2 - VERT(1));
	}
	if(dbg)printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; b=%d, h=%d\n", 
		yyval, p1, shval, p2, -shval, ebase[yyval], eht[yyval]);
	printf(".as %d \\v'%du'\\*(%d\\v'%du'\n", 
		yyval, shval, p2, -shval);
	ofree(p2);
}

eqnbox(p1, p2) int p1, p2; {
	int b, h;
	yyval = p1;
	b = max(ebase[p1], ebase[p2]);
	eht[yyval] = h = b + max(eht[p1]-ebase[p1], 
		eht[p2]-ebase[p2]);
	ebase[yyval] = b;
	if(dbg)printf(".\te:eb: S%d <- S%d S%d; b=%d, h=%d\n", 
		yyval, p1, p2, b, h);
	printf(".as %d \"\\*(%d\n", yyval, p2);
	ofree(p2);
}

size(p1, p2) {
	yyval = p2;
}

numb(p1) char *p1; {
	int i, n, c;
	for(i=n=0; (c=p1[i++])!='\0'; )
		if( c>='0' && c<='9' )
			n = n*10 + c-'0';
	if(dbg)printf(".\tnumb: %s %d\n", p1, n);
	return( n );
}

font(p1, p2) {
	yyval = p2;
}

shift(p1) int p1; {
	yyval = p1;
	if(dbg)printf(".\tshift: %d;ps=%d\n", yyval, ps);
}

sqrt(p2) int p2; {
	yyval = p2;
	nrwid(p2, ps, p2);
	printf(".ds %d \\v'%du'\\e\\L'%du'\\l'\\n(%du'",
		p2, ebase[p2], -eht[p2], p2);
	printf("\\v'%du'\\h'-\\n(%du'\\*(%d\n", eht[p2]-ebase[p2], p2, p2);
	eht[p2] =+ VERT(1);
	if(dbg)printf(".\tsqrt: S%d <- S%d;b=%d, h=%d\n", 
		p2, p2, ebase[p2], eht[p2]);
}

lpile(type, p1, p2) int type, p1, p2; {
	int bi, hi, i, gap, h, b, j, nlist, nlist2, mid;
	yyval = oalloc();
	gap = VERT(1);
	if( type=='-' ) gap = 0;
	nlist = p2 - p1;
	nlist2 = (nlist+1)/2;
	mid = p1 + nlist2 -1;
	h = 0;
	for( i=p1; i<p2; i++ )
		h =+ eht[lp[i]];
	eht[yyval] = h + (nlist-1)*gap;
	b = 0;
	for( i=p2-1; i>mid; i-- )
		b =+ eht[lp[i]] + gap;
	ebase[yyval] = (nlist%2) ? b + ebase[lp[mid]]
			: b - VERT(1) - gap;
	if(dbg) {
		printf(".\tS%d <- %c pile of:", yyval, type);
		for( i=p1; i<p2; i++)
			printf(" S%d", lp[i]);
		printf(";h=%d b=%d\n", eht[yyval], ebase[yyval]);
	}
	nrwid(lp[p1], ps, lp[p1]);
	printf(".nr %d \\n(%d\n", yyval, lp[p1]);
	for( i = p1+1; i<p2; i++ ) {
		nrwid(lp[i], ps, lp[i]);
		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", 
			lp[i], yyval, yyval, lp[i]);
	}
	printf(".ds %d \\v'%du'\\h'%du*\\n(%du'\\\n", yyval, ebase[yyval], 
		type=='R' ? 1 : 0, yyval);
	for(i = p2-1; i >=p1; i--) {
		hi = eht[lp[i]]; 
		bi = ebase[lp[i]];
	switch(type) {

	case 'L':
		printf("\\v'%du'\\*(%d\\h'-\\n(%du'\\v'0-%du'\\\n", 
			-bi, lp[i], lp[i], hi-bi+gap);
		continue;
	case 'R':
		printf("\\v'%du'\\h'-\\n(%du'\\*(%d\\v'0-%du'\\\n", 
			-bi, lp[i], lp[i], hi-bi+gap);
		continue;
	case 'C':
	case '-':
		printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d", 
			-bi, yyval, lp[i], lp[i]);
		printf("\\h'-\\n(%du-\\n(%du/2u'\\v'0-%du'\\\n", 
			yyval, lp[i], hi-bi+gap);
		continue;
		}
	}
	printf("\\v'%du'\\h'%du*\\n(%du'\n", eht[yyval]-ebase[yyval]+gap, 
		type!='R' ? 1 : 0, yyval);
	for( i=p1; i<p2; i++ )
		ofree(lp[i]);
}

shift2(p1, p2, p3) int p1, p2, p3; {
	int effps, effps2, h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh;
	int treg;
	treg = oalloc();
	yyval = p1;
	if(dbg)printf(".\tshift2 s%d <- %d %d %d\n", yyval, p1, p2, p3);
	h1 = eht[p1]; b1 = ebase[p1];
	h2 = eht[p2]; b2 = ebase[p2];
	h3 = eht[p3]; b3 = ebase[p3];
	d1 = VERT(1);
	subsh = -d1+h2-b2;
	if( d1+b1 > h2 ) /* move little sub down */
		subsh = b1-b2;
	supsh = - VERT(1) - b3;
	d2 = VERT(1);
	if( VERT(1)+h3 < h1-b1 )
		supsh = -(h1-b1) + (h3-b3) - d2;
	eht[yyval] = h1 + max(0, h3-VERT(1)) + max(0, h2-b1-d1);
	ebase[yyval] = b1+max(0, h2-b1-d1);
	nrwid(p2, effps, p2);
	nrwid(p3, effps, p3);
	printf(".nr %d \\n(%d\n", treg, p3);
	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
	printf(".as %d \\v'%du'\\*(%d\\h'-\\n(%du'\\v'%du'\\\n", 
		p1, subsh, p2, p2, -subsh+supsh);
	printf("\\*(%d\\h'-\\n(%du+\\n(%du'\\v'%du'\n", 
		p3, p3, treg, -supsh);
	ps =+ 2;
	ofree(p2); ofree(p3); ofree(treg);
}
ne2.c~Y
# include "ne.h"

fromto(p1, p2, p3) int p1, p2, p3; {
	int h, b, h1, b1, pss;
	yyval = oalloc();
	h1 = eht[yyval] = eht[p1];
	b1 = ebase[p1];
	b = 0;
	nrwid(p1, ps, p1);
	printf(".nr %d \\n(%d\n", yyval, p1);
	if( p2>0 ) {
		nrwid(p2, pss, p2);
		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, yyval, yyval, p2);
		eht[yyval] =+ eht[p2];
		b = eht[p2];
	}
	if( p3>0 ) {
		nrwid(p3, pss, p3);
		printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p3, yyval, yyval, p3);
		eht[yyval] =+ eht[p3];
	}
	printf(".ds %d ", yyval);	/* bottom of middle box */
	if( p2>0 ) {
		printf("\\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d", 
			eht[p2]-ebase[p2]+b1, yyval, p2, p2);
		printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%du'\\\n", 
			yyval, p2, -(eht[p2]-ebase[p2]+b1));
	}
	printf("\\h'\\n(%du-\\n(%du/2u'\\*(%d\\h'\\n(%du-\\n(%du+2u/2u'\\\n", 
		yyval, p1, p1, yyval, p1);
	if( p3>0 ) {
		printf("\\v'%du'\\h'-\\n(%du-\\n(%du/2u'\\*(%d\\h'\\n(%du-\\n(%du/2u'\\v'%du'\\\n", 
			-(h1-b1+ebase[p3]), yyval, p3, p3, yyval, p3, (h1-b1+ebase[p3]));
	}
	printf("\n");
	ebase[yyval] = b + b1;
	if(dbg)printf(".\tfrom to: S%d <- %d f %d t %d; h=%d b=%d\n", 
		yyval, p1, p2, p3, eht[yyval], ebase[yyval]);
	ofree(p1);
	if( p2>0 ) ofree(p2);
	if( p3>0 ) ofree(p3);
}

paren(leftc, p1, rightc) int p1, leftc, rightc; {
	int n, m, h1, j, b1, v;
	h1 = eht[p1]; b1 = ebase[p1];
	yyval = p1;
	n = max(b1+VERT(1), h1-b1-VERT(1)) / VERT(1);
	if( n<2 ) n=2;
	m = n-2;
	if (leftc=='{' || rightc == '}'){
		n = n%2 ? n : ++n;
		if( n<3 ) n=3;
		m = n - 3;
	}
	eht[yyval] = VERT(2 * n);
	ebase[yyval] = (n)/2 * VERT(2);
	if (n%2 == 0)
		ebase[yyval] =- VERT(1);
	v = b1 - h1/2 + VERT(1);
	printf(".ds %d \\v'%du'", yyval, v);
	switch( leftc ) {
		case 'n':	/* nothing */
		case '\0':
			break;
		case 'f':	/* floor */
			brack(m, "\\(bv", "\\(bv", "\\(lf");
			break;
		case 'c':	/* ceiling */
			brack(m, "\\(lc", "\\(bv", "\\(bv");
			break;
		case '{':
			printf("\\b'\\(lt");
			for(j = 0; j < m; j =+ 2) printf("\\(bv");
			printf("\\(lk");
			for(j = 0; j < m; j =+ 2) printf("\\(bv");
			printf("\\(lb'");
			break;
		case '(':
			brack(m, "\\(lt", "\\(bv", "\\(lb");
			break;
		case '[':
			brack(m, "\\(lc", "\\(bv", "\\(lf");
			break;
		default:
			brack(m, &leftc, &leftc, &leftc);
			break;
		}
	printf("\\v'%du'\\*(%d", -v, p1);
	if( rightc ) {
		printf("\\v'%du'", v);
		switch( rightc ) {
			case 'f':	/* floor */
				brack(m, "\\(bv", "\\(bv", "\\(rf");
				break;
			case 'c':	/* ceiling */
				brack(m, "\\(rc", "\\(bv", "\\(bv");
				break;
			case '}':
				printf("\\b'\\(rt");
				for(j = 0; j< m; j =+ 2)printf("\\(bv");
				printf("\\(rk");
				for(j = 0; j< m; j =+ 2) printf("\\(bv");
				printf("\\(rb'");
				break;
			case ']':
				brack(m, "\\(rc", "\\(bv", "\\(rf");
				break;
			case ')':
				brack(m, "\\(rt", "\\(bv", "\\(rb");
				break;
			default:
				brack(m, &rightc, &rightc, &rightc);
				break;
		}
		printf("\\v'%du'", -v);
	}
	printf("\n");
	if(dbg)printf(".\tcurly: h=%d b=%d n=%d v=%d l=%c, r=%c\n", 
		eht[yyval], ebase[yyval], n, v, leftc, rightc);
}

brack(m, t, c, b) int m; char *t, *c, *b; {
	int j;
	printf("\\b'%s", t);
	for( j=0; j<m; j++)
		printf("%s", c);
	printf("%s'", b);
}

diacrit(p1, type) int p1, type; {
	int c, t;
	if(dbg)printf(".\tdiacrit: %ctype over S%d\n", type, p1);
	c = oalloc();
	t = oalloc();
	nrwid(p1, ps, p1);
	switch(type) {
		case 'V':	/* vec */
		case 'Y':	/* dyad */
			printf(".ds %d \\v'-1'_\\v'1'\n", c);
			break;
		case 'H':
			printf(".ds %d ^\n", c);
			break;
		case 'T':
			printf(".ds %d ~\n", c);
			break;
		case 'D':
			printf(".ds %d \\v'-1'.\\v'1'\n", c);
			break;
		case 'U':
			printf(".ds %d \\v'-1'..\\v'1'\n", c);
			break;
		case 'B':
			printf(".ds %d \\v'-1'\\l'\\n(%du'\\v'1'\n", 
				c, p1);
			break;
		case 'N':
			printf(".ds %d \\l'\\n(%du'\n", c, p1);
			break;
		}
	nrwid(c, ps, c);
	printf(".as %d \\h'-\\n(%du-\\n(%du/2u'\\*(%d", 
		p1, p1, c, c);
	printf("\\h'-\\n(%du+\\n(%du/2u'\n", c, p1);
	eht[p1] =+ VERT(1);
	ofree(c); ofree(t);
}

move(dir, amt, p) int dir, amt; char *p; {
	/* 0=fwd, 1=up, 2=back, 3=down */
	int a, a1, a2;
	yyval = p;
	a1 = amt/100;
	a2 = amt%100;
	printf(".ds %d ", yyval);
	if( dir==0 || dir==2 )	/* fwd, back */
		printf("\\h'%s%d.%dm'\\*(%d\n", (dir==2) ? "-" : "", a1, a2, p);
	else if (dir == 1)
		printf("\\v'-%d.%dm'\\*(%d\\v'%d.%dm'\n",
			a1, a2, p, a1, a2);
	else if (dir == 3)
		printf("\\v'%d.%dm'\\*(%d\\v'-%d.%dm'\n",
			a1, a2, p, a1, a2);
	a = (ps * 6 * amt) / 100;
/*
	if (dir == 1 || dir == 3)
		eht[yyval] =+ a;
	if( dir==1 )
		ebase[yyval] =- a;
	else if( dir==3 )
		ebase[yyval] =+ a;
*/
	if(dbg)printf(".\tmove %d dir %d amt %d; h=%d b=%d\n", 
		p, dir, amt, eht[yyval], ebase[yyval]);
}

funny(n) int n; {
	int f, t;
	yyval = oalloc();
	switch(n) {
	case 'S':
		f = "\\(*S"; break;
	case 'U':
		f = "\\(cu"; break;
	case 'A':	/* intersection */
		f = "\\(ca"; break;
	case 'P':
		f = "\\(*P"; break;
	case 'I':
		f = "\\(is";
		break;
	}
	printf(".ds %d %s\n", yyval, f);
	eht[yyval] = VERT(2);
	ebase[yyval] = 0;
	if(dbg)printf(".\tfunny: S%d <- %s; h=%d b=%d\n", 
		yyval, f, eht[yyval], ebase[yyval]);
}

ne3.c~[
# include "ne.h"

struct {
	char	*res;
	char	*resval;
} restab[] {
	">=",	"\\(>=",
	"<=",	"\\(<=",
	"==",	"\\(==",
	"!=",	"\\(!=",
	"+-",	"\\(+-",
	"->",	"\\(->",
	"<-",	"\\(<-",
	"inf",	"\\(if",
	"infinity",	"\\(if",
	"partial",	"\\(pd",
	"half",	"\\fR\\(12\\fP",
	"prime",	"\\(fm",
	"approx",	"~\b\\d~\\u",
	"nothing",	"",
	"cdot",	"\\v'-.5'.\\v'.5'",
	"times",	"\\|\\(mu\\|",
	"del",	"\\(gr",
	"grad",	"\\(gr",
	"...",	"\\v'-.3m'\\|\\|.\\|\\|.\\|\\|.\\|\\|\\v'.3m'",
	",...,",	",\\|\\|.\\|\\|.\\|\\|.\\|\\|,\\|",

	"alpha",	"\\(*a",
	"beta",	"\\(*b",
	"gamma",	"\\(*g",
	"GAMMA",	"\\(*G",
	"delta",	"\\(*d",
	"DELTA",	"\\(*D",
	"epsilon",	"\\(*e",
	"omega",	"\\(*w",
	"OMEGA",	"\\(*W",
	"lambda",	"\\(*l",
	"LAMBDA",	"\\(*L",
	"mu",	"\\(*m",
	"nu",	"\\(*n",
	"theta",	"\\(*h",
	"THETA",	"\\(*H",
	"phi",	"\\(*f",
	"PHI",	"\\(*F",
	"pi",	"\\(*p",
	"PI",	"\\(*P",
	"sigma",	"\\(*s",
	"SIGMA",	"\\(*S",
	"xi",	"\\(*c",
	"XI",	"\\(*C",
	"zeta",	"\\(*z",
	"iota",	"\\(*i",
	"eta",	"\\(*y",
	"kappa",	"\\(*k",
	"rho",	"\\(*r",
	"tau",	"\\(*t",
	"omicron",	"\\(*o",
	"upsilon",	"\\(*u",
	"UPSILON",	"\\(*U",
	"psi",	"\\(*q",
	"PSI",	"\\(*Q",
	"chi",	"\\(*x",
	"and",	"\\fRand\\fP",
	"for",	"\\fRfor\\fP",
	"if",	"\\fRif\\fP",
	"Re",	"\\fRRe\\fP",
	"Im",	"\\fRIm\\fP",
	"sin",	"\\fRsin\\fP",
	"cos",	"\\fRcos\\fP",
	"tan",	"\\fRtan\\fP",
	"arc",	"\\fRarc\\fP",
	"sinh",	"\\fRsinh\\fP",
	"coth",	"\\fRcoth\\fP",
	"tanh",	"\\fRtanh\\fP",
	"cosh",	"\\fRcosh\\fP",
	"lim",	"\\fRlim\\fP",
	"log",	"\\fRlog\\fP",
	"max",	"\\fRmax\\fP",
	"min",	"\\fRmin\\fP",
	"ln",	"\\fRln\\fP",
	"exp",	"\\fRexp\\fP",
	"det",	"\\fRdet\\fP",
	0,	0
};

int	csp;
int	psp;
#define	CSSIZE	400
char	cs[420];

text(t,p1) int t; char *p1; {
	int i,j,c;
	yyval = oalloc();
	ebase[yyval] = 0;
	eht[yyval] = VERT(2);
	if( t=='q' )
		j = p1;
	else if ( t == '~' )
		j = &"\\ ";
	else if ( t == '^' )
		j = &"";
	else if ( t == '\t' )
		j = &"\\t";
	else if( (i=lookup(p1,restab))>=0 )
		j = restab[i].resval;
	else {
		for( csp=psp=0; (c=p1[psp++])!='\0'; ){
			trans(c,p1);
			if( csp>CSSIZE ){
				p1[25] = '\0';
				error(FATAL,"converted token %s... too long",p1);
			}
		}
		cs[csp] = '\0';
		j = cs;
	}
	if(dbg)printf(".\t%ctext: S%d <- %s; b=%d,h=%d\n",
		t, yyval, j, ebase[yyval], eht[yyval]);
	printf(".ds %d \"%s\n", yyval, j);
}

trans(c,p1) int c; char *p1; {
	switch( c){
	case '0': case '1': case '2': case '3': case '4':
	case '5': case '6': case '7': case '8': case '9':
	case ':': case ';': case '!':
		roman(c); break;
	case '(': case '[': case ')': case ']':
		shim(); roman(c); break;
	case '+': case '|':
		shim(); roman(c); shim(); break;
	case '=': case '>': case '<':
		if( p1[psp]=='=' ){	/* look ahead for == <= >= */
			name4(c,'=');
			psp++;
		} else {
			shim(); cs[csp++] = c; shim(); 
		}
		break;
	case '-':
		if( p1[psp]=='>' ){
			shim(); name4('-','>'); psp++;
		} else {
			shim(); name4('m','i'); shim();
		}
		break;
	case '/':
		name4('s','l');
		break;
	case '~': case ' ':
		shim(); shim(); break;
	case '^':
		shim(); break;
	case '\\':	/* troff - pass 2 or 3 more chars */
		cs[csp++] = c; cs[csp++] = c = p1[psp++]; cs[csp++] = p1[psp++];
		if( c=='(' ) cs[csp++] = p1[psp++];
		if( c=='*' && cs[csp-1] == '(' ){
			cs[csp++] = p1[psp++];
			cs[csp++] = p1[psp++];
		}
		break;
	case '\'':
		name4('f','m'); break;
	default:
		cs[csp++] = c; break;
	}
}

shim() {
	;
}

roman(c) int c; {
	cs[csp++] = c;
}

name4(c1,c2) int c1,c2; {
	cs[csp++] = '\\';
	cs[csp++] = '(';
	cs[csp++] = c1;
	cs[csp++] = c2;
}
ne4.cщl
#include "ne.h"
#define	SIGPIPE	13	/* troff has stopped reading */

int	gsize	10;
int	gfont	'R';

char	in[600];	/* input buffer */
int	exit();
int noeqn;

main(argc,argv) int argc; char *argv[];{
	int i, type;
	first = 0;
	lefteq = righteq = '\0';
	signal(SIGPIPE, &exit);
	setfile(argc,argv);
	while( (type=getline(in)) != '\0' ){
		eqline = linect;
		if( in[0]=='.' && in[1]=='E' && in[2]=='Q' ){
			for( i=11; i<100; used[i++]=0 );
			printf("%s",in);
			printf(".nr 99 \\n(.s\n.nr 98 \\n(.f\n");
			init();
			yyparse();
			if( eqnreg>0 ){
			printf("'nr %d \\w'\\*(%d'\n", eqnreg, eqnreg);
				printf(".if %d>\\n(.v .ne %du\n", eqnht, eqnht);
				printf(".rn %d 10\n", eqnreg);
				if(!noeqn)printf("\\*(10\n");
			}
			printf(".ps \\n(99\n.ft \\n(98\n");
			printf(".EN");
			if( lastchar == '\0' ){
				putchar('\n');
				break;
			}
			if( putchar(lastchar) != '\n' )
				while( putchar(getch()) != '\n' );
			flush();
		}
		else if( type == lefteq )
			inline();
		else
			printf("%s",in);
	}
	flush();
	exit(0);
}

getline(s) char *s; {
	char c;
	while((*s++=c=getch())!='\n' && c!='\0' && c!=lefteq );
	if( c==lefteq )
		s--;
	*s++ = '\0';
	return(c);
}

inline() {
	int i,j,ds,t;
	printf(".nr 99 \\n(.s\n.nr 98 \\n(.f\n");
	ds = oalloc();
	printf(".ds %d \"\n", ds);
	do{
		printf(".as %d \"%s\n", ds, in);
		init();
		yyparse();
		if( eqnreg > 0 ) {
			printf(".as %d \\*(%d\n", ds, eqnreg);
			ofree(eqnreg);
		}
		printf(".ps \\n(99\n.ft \\n(98\n");
	} while( (t=getline(in)) == lefteq );
	printf(".as %d \"%s", ds, in);
	printf(".ps \\n(99\n.ft \\n(98\n");
	printf("\\*(%d\n", ds);
	ofree(ds);
	flush();
}

putout(p1) int p1; {
	int before, after;
	eqnht = eht[p1];
	printf(".ds %d \\x'0'", p1);
	before = eht[p1] - ebase[p1] - VERT(3);	/* 3 = 1.5 lines */
	if( before > 0 )
		printf("\\x'0-%du'", before);
	printf("\\f%c\\s%d\\*(%d\\s\\n(99\\f\\n(98",gfont,gsize,p1);
	after = ebase[p1] - VERT(1);
	if( after > 0 )
		printf("\\x'%du'", after);
	putchar('\n');
	eqnreg = p1;
	if(dbg)printf(".\tanswer <- S%d: h=%d, b=%d, before=%d, after=%d\n",
		p1, eht[p1], ebase[p1], before, after);
}

max(i,j) int i,j; {
	return( i>j ? i : j );
}

oalloc(){
	int i;
	for( i=11; i<100; i++)
		if( used[i]++ == 0 ) return(i);
	error( FATAL, "no strings left", i);
}

ofree(n) int n; {
	used[n] = 0;
}

setps(p) int p; {
	printf(".ps %d\n", p);
}

nrwid(n1, p, n2) int n1, p, n2; {
	printf(".nr %d \\w'\\*(%d'\n", n1, n2);
}

setfile(argc, argv) int argc; char *argv[]; {
	svargc = --argc;
	svargv = argv;
	while( svargc > 0 && svargv[1][0] == '-'){
		switch( svargv[1][1] ){

		case 'd': lefteq=svargv[1][2]; righteq=svargv[1][3]; break;
		case 's': gsize = numb(&svargv[1][2]); break;
		case 'f': gfont = svargv[1][2]; break;
		case 'e': noeqn++; break;
		default: dbg = 1;
		}
		svargc--;
		svargv++;
	}
	ptr = 0;
	fout = dup(1);
	ifile = 1;
	linect = 1;
	if( svargc <= 0 )
		fin = dup(0);
	else if( (fin = open(svargv[1], 0)) < 0)
		error( FATAL,"can't open file %s", svargv[1]);
}

yyerror(){;}

init(){
	ct = 0;
	ps = gsize;
	ft = gfont;
	first++;
}

error(fatal, s1, s2) int fatal; char *s1, *s2; {
	int sfout;
	if( fatal>0 )
		printf("fatal error: ");
	printf(s1,s2);
	printf(" file %s, between lines %d and %d\n",
		 svargv[ifile], eqline, linect);
	flush(fout);
	sfout = fout;
	fout = 2;
	if( fatal>0 )
		printf("fatal error: ");
	printf(s1,s2);
	printf(" file %s, between lines %d and %d\n",
		 svargv[ifile], eqline, linect);
	flush(2);
	fout = sfout;
	if( fatal > 0 )
		exit(1);
}
ne5.c~`G#include "ne.h"

mark(n) int n; {
	if( n )
		printf(".as %d \\k(97\n", n);
	else {
		yyval = oalloc();
		printf(".ds %d \\k(97\n", yyval);
		nrwid(yyval, ps, yyval);
		eht[yyval] = eht[n];
		ebase[yyval] = ebase[n];
	}
	if(dbg)printf(".\tmark %d as %d\n", n, yyval);
}

lineup(n) int n; {
	if( n ) {
		nrwid(n, ps, n);
		printf(".ds %d \\h'|\\n(97u-\\n(%du'\\*(%d\n", n, n, n);
	} else {
		yyval = oalloc();
		printf(".ds %d \\h'|\\n(97u'\n", yyval);
		nrwid(yyval, ps, yyval);
		eht[yyval] = eht[n];
		ebase[yyval] = ebase[n];
	}
	if(dbg)printf(".\tlineup %d in %d\n", n, yyval);
}
nne6.c~b#include "ne.h"

column(type, p1, p2) int type, p1, p2; {
	int i, n;
	lp[p1] = ct - p1 - 1;
	if( dbg ){
		printf(".\t%c column of", type);
		for( i=p1+1; i<ct; i++ )
			printf(" S%d", lp[i]);
		printf(", rows=%d\n",lp[p1]);
	}
	lp[ct++] = type;
}

matrix(p1,p2) int p1, p2; {
	int nrow, ncol, i, j, k, hb, b, val[100], db;
	char *space;
	space = "\\ \\ ";
	nrow = lp[p1];	/* disaster if rows inconsistent */
	ncol = 0;
	for( i=p1; i<ct; i =+ lp[i]+2 ){
		ncol++;
		if(dbg)printf(".\tcolct=%d\n",lp[i]);
	}
	for( k=1; k<=nrow; k++ ) {
		hb = b = 0;
		j = p1 + k;
		for( i=0; i<ncol; i++ ) {
			hb = max(hb, eht[lp[j]]-ebase[lp[j]]);
			b = max(b, ebase[lp[j]]);
			j =+ nrow + 2;
		}
		if(dbg)printf(".\trow %d: b=%d, hb=%d\n", k, b, hb);
		j = p1 + k;
		for( i=0; i<ncol; i++ ) {
			ebase[lp[j]] = b;
			eht[lp[j]] = b + hb;
			j =+ nrow + 2;
		}
	}
	j = p1;
	for( i=0; i<ncol; i++ ) {
		lpile(lp[j+lp[j]+1], j+1, j+lp[j]+1);
		val[i] = yyval;
		j =+ nrow + 2;
	}
	yyval = oalloc();
	eht[yyval] = eht[val[0]];
	ebase[yyval] = ebase[val[0]];
	if(dbg)printf(".\tmatrix S%d: r=%d, c=%d, h=%d, b=%d\n",
		yyval,nrow,ncol,eht[yyval],ebase[yyval]);
	printf(".ds %d \"", yyval);
	for( i=0; i<ncol; i++ )  {
		printf("\\*(%d%s", val[i], i==ncol-1 ? "" : space);
		ofree(val[i]);
	}
	printf("\n");
	ct = p1;
}
lnelex.cщ#
#include "ne.h"
#include "y.tab.c"

struct	{
	char	*key;
	int	keyval;
} keytab[] {
	"sub",	SUB,
	"sup",	SUP,
	".EN",	0,
	"from",	FROM,
	"to",	TO,
	"sum",	SUM,
	"hat",	HAT,
	"vec", VEC,
	"dyad", DYAD,
	"dot",	DOT,
	"dotdot",	DOTDOT,
	"bar",	BAR,
	"tilde",	TILDE,
	"under",	UNDER,
	"prod",	PROD,
	"int",	INT,
	"integral",	INT,
	"union",	UNION,
	"inter",	INTER,
	"pile",	PILE,
	"lpile",	LPILE,
	"cpile",	CPILE,
	"rpile",	RPILE,
	"over",	OVER,
	"sqrt",	SQRT,
	"above",	ABOVE,
	"size",	SIZE,
	"font",	FONT,
	"fat",	FAT,
	"roman",	ROMAN,
	"italic",	ITALIC,
	"bold",	BOLD,
	"left",	LEFT,
	"right",	RIGHT,
	"delim",	DELIM,
	"define",	DEFINE,
	"tdefine",	TDEFINE,
	"ndefine",	DEFINE,
	"gsize",	GSIZE,
	".gsize",	GSIZE,
	"gfont",	GFONT,
	"up",	UP,
	"down",	DOWN,
	"fwd",	FWD,
	"back",	BACK,
	"mark",	MARK,
	"lineup",	LINEUP,
	"matrix",	MATRIX,
	"col",	COL,
	"lcol",	LCOL,
	"ccol",	CCOL,
	"rcol",	RCOL,
	0,	0
};
int	peek	-1;
#define	SSIZE	400
char	token[SSIZE];
int	asp;
int speek[10];
char *swt[10];
int sw -1;

getch(){
  loop:
	if(sw >= 0){
		lastchar = (peek<0) ? *swt[sw]++ : peek;
		peek = -1;
		if(lastchar != '\0')return(lastchar);
		peek = speek[sw--];
		return(' ');
		}
	lastchar = (peek<0) ? getchar() : peek;
	if( lastchar=='\n' )
		linect++;
	peek = -1;
	if( lastchar!= '\0' )
		return(lastchar);
	if( ++ifile > svargc ){
		peek = '\0';
		return('\0');
	}
	close(fin);
	linect = 1;
	if( (fin=open(svargv[ifile],0)) >= 0 )
		goto loop;
	error(FATAL,"can't open file %s\n", svargv[ifile]);
}

yylex(){
	int c, type;
  beg:
	while( (c=getch())==' ' || c=='\n');
	yylval=c;
	switch(c){

	case '\0':
		return('\0');
	case '~':
		return(SPACE);
	case '^':
		return(THIN);
	case '\t':
		return(TAB);
	case '{':
		return(MQ);
	case '}':
		return(MQ1);
	case '"':
		for(asp=0; (c=getch())!='"'; ){
			if(c !='\\')token[asp++]=c;
			else { if((c=getch())!= '"')token[asp++]='\\';
				token[asp++] = c; }
			if( asp>=SSIZE )
				error(FATAL,"quoted string %.20s... too long", token);
		}
		token[asp]='\0';
		yylval= &token[0];
		return(QTEXT);
	}
	if( c==righteq )
		return('\0');

	getstr(token, c);
	if((type = lookup(token,deftab)) >= 0){
		if(sw >= 9)
			error(FATAL,"definitions nested > 9", sw);
		swt[++sw] = deftab[type].sptr;
		speek[sw] = peek;
		peek = -1;
		goto beg;
		}
	type = lookup(token,keytab);
	if( type < 0 )
		return(CONTIG);
	if( keytab[type].keyval==DEFINE || keytab[type].keyval==TDEFINE ) {
		define(keytab[type].keyval);
		goto beg;
	}
	else if( keytab[type].keyval==DELIM ) {
		delim();
		goto beg;
	}
	else if( keytab[type].keyval==GSIZE ){
		globsize();
		goto beg;
	}
	else if( keytab[type].keyval==GFONT ) {
		globfont();
		goto beg;
	}
	else
		return( keytab[type].keyval );
}

getstr(s,c) char *s, c; {
	for (asp=0; c!=' ' && c!='\t' && c!='\n' && c!='{' && c!='}'
		&& c!='"' && c!='~' && c!='^' && c!=righteq; ) {
		if(c == '\\') if((c = getch()) != '"')s[asp++] = '\\';
		s[asp++] = c;
		if( asp>=SSIZE )
			error(FATAL,"token %.20s... too long",s);
		c = getch();
		}
	if( c=='{' || c=='}' || c=='"' || c=='~' || c=='^' || c=='\t' || c==righteq )
		peek = c;
	s[asp]='\0';
	yylval = s;
}

lookup(str,tbl)
char *str;
struct { char *name; char *val; } tbl[];
{
	register i,j, r;
	for(i=0; tbl[i].name!=0; i++){ /* table of tbl wds */
		for( j=0; (r=tbl[i].name[j])==str[j] && r!='\0'; j++);
		if( r == str[j] )
			return(i);
	}
	return( -1 );
}

cstr(s,quote) char *s; int quote; {
	int del,c,i;
	while((del=getch()) == ' ' || del == '\t' || del == '\n');
	if(quote)
		for(i=0; (c=getch()) != del;)
			s[i++] = c;
	else {
		s[0] = del;
		for(i=1; (c=getch())!=' ' && c!= '\t' && c!='\n';)
			s[i++]=c;
	}
	s[i] = '\0';
	return(s);
}

define(type) int type; {
	/*	char *alloc (); */
	int i, c;
	while( (c=getch())==' ' || c=='\n' );
	getstr(token,c);
	if( type == DEFINE ) {
		if((i = lookup(token,deftab)) >= 0){
			yyval = i;
			free(deftab[yyval].sptr);
		} else {
			yyval = ptr++;
			for(i=0; token[i] != '\0'; i++);
			deftab[yyval].nptr = alloc(i+1);
			for(i=0; deftab[yyval].nptr[i]=token[i]; i++);
		}
		if(dbg)printf(".\tdefine %s\n",deftab[yyval].nptr);
	}
	cstr(token,1);
	if( type != DEFINE )
		return;
	for(i=0; token[i] != '\0'; i++);
	deftab[yyval].sptr = alloc(i+1);
	for(i=0; deftab[yyval].sptr[i] = token[i]; i++);
	if(dbg)printf(".\tname %s defined as %s\n",
		deftab[yyval].sptr, deftab[yyval].sptr);
}

delim() {
	char *s;
	yyval = eqnreg = 0;
	cstr(token,0);
	lefteq = token[0];
	righteq = token[1];
	if( (lefteq == 'o' && righteq == 'f') || (lefteq == 'O' && righteq == 'F') )
		lefteq = righteq = '\0';
}

globsize() {
	extern int gsize;
	int c;
	while( (c=getch())==' ' || c=='\n' );
	getstr(token,c);
	gsize = numb(token);
	yyval = eqnreg = 0;
	setps(gsize);
}

globfont() {
	extern int gfont;
	while( (gfont=getch())==' ' || gfont=='\n' );
	yyval = eqnreg = 0;
	printf(".ft %c\n", gfont);
}