2005-01-04 22:30:59 +00:00
|
|
|
/* Make this with: lex delatex.lex; cc lex.yy.c -ll -o delatex */
|
|
|
|
L [A-Za-z]
|
2005-01-30 16:48:14 +00:00
|
|
|
%Start Display Math Normal Tag VerbPlus Bracket
|
2005-01-04 22:30:59 +00:00
|
|
|
%%
|
|
|
|
<Normal>\' {yyleng--; yymore(); /* ignore apostrophes */}
|
|
|
|
<Normal>{L}+\\- {yyleng-=2; yymore(); /* ignore hyphens */}
|
2005-01-30 16:48:14 +00:00
|
|
|
<Normal>[a-zA-Z0-9_]+@[a-zA-Z0-9_.]+ ; /* ignore email addresses */
|
2005-01-04 22:30:59 +00:00
|
|
|
<Normal>[a-z]/[^A-Za-z] ; /* ignore single letter "words" */
|
|
|
|
<Normal>[A-Z]+ ; /* ignore words all in uppercase */
|
|
|
|
<Normal>{L}+('{L}*)*{L} {printf("%s\n",yytext); /* any other letter seq is a word */}
|
|
|
|
<Normal>"%".* ; /* ignore comments */
|
|
|
|
<Normal>\\{L}+ ; /* ignore other control sequences */
|
|
|
|
<Normal>"\\begin{" BEGIN Tag; /* ignore this and up to next "}" */
|
|
|
|
<Normal>"\\bibitem{" BEGIN Tag;
|
|
|
|
<Normal>"\\bibliography{" BEGIN Tag;
|
|
|
|
<Normal>"\\bibstyle{" BEGIN Tag;
|
|
|
|
<Normal>"\\cite{" BEGIN Tag;
|
|
|
|
<Normal>"\\end{" BEGIN Tag;
|
|
|
|
<Normal>"\\include{" BEGIN Tag;
|
|
|
|
<Normal>"\\includeonly{" BEGIN Tag;
|
|
|
|
<Normal>"\\input{" BEGIN Tag;
|
|
|
|
<Normal>"\\label{" BEGIN Tag;
|
|
|
|
<Normal>"\\pageref{" BEGIN Tag;
|
|
|
|
<Normal>"\\ref{" BEGIN Tag;
|
2005-01-30 16:48:14 +00:00
|
|
|
<Normal>"\\verb+" BEGIN VerbPlus;
|
|
|
|
<Normal>"\\documentclass[" BEGIN Bracket;
|
|
|
|
<Normal>"\\documentclass{" BEGIN Tag;
|
|
|
|
<Normal>"\\usepackage[" BEGIN Bracket;
|
|
|
|
<Normal>"\\usepackage{" BEGIN Tag;
|
|
|
|
<Bracket>[^\]] ;
|
|
|
|
<Bracket>"][" ;
|
|
|
|
<Bracket>"]{" BEGIN Tag;
|
|
|
|
<Bracket>"]" BEGIN Normal;
|
2005-01-04 22:30:59 +00:00
|
|
|
<Tag>[^}] ; /* ignore things up to next "}" */
|
|
|
|
<Tag>"}" BEGIN Normal;
|
2005-01-30 16:48:14 +00:00
|
|
|
<VerbPlus>[^+] ; /* ignore thing up to next "+" */
|
|
|
|
<VerbPlus>"+" BEGIN Normal;
|
2005-01-04 22:30:59 +00:00
|
|
|
<Normal>[0-9]+ ; /* ignore numbers */
|
|
|
|
<Normal>"\\(" BEGIN Math; /* begin latex math mode */
|
|
|
|
<Math>"\\)" BEGIN Normal; /* end latex math mode */
|
|
|
|
<Math>.|\\[^)]|\n ; /* ignore anything else in latex math mode */
|
|
|
|
<Normal>"\\[" BEGIN Display; /* now in Latex display mode */
|
|
|
|
<Display>[^$]|\\[^\]] ; /* ignore most things in display math mode */
|
|
|
|
<Display>"\\]" BEGIN Normal; /* get out of Display math mode */
|
|
|
|
<Normal>\\. ; /* ignore other single character control sequences */
|
|
|
|
<Normal>\\\n ; /* more of the same */
|
|
|
|
<Normal>\n|. ; /* ignore anything else, a character at a time */
|
|
|
|
%%
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
BEGIN Normal; /* Starts yylex off in the right state */
|
|
|
|
if (argc==1) {
|
|
|
|
yyin = stdin;
|
|
|
|
yylex();
|
|
|
|
}
|
|
|
|
else for (i=1; i<argc; i++) {
|
|
|
|
yyin = fopen(argv[i],"r");
|
|
|
|
if (yyin==NULL) {
|
|
|
|
fprintf(stderr,"can't open %s\n",argv[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
yylex();
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
int
|
|
|
|
yywrap(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|