\expandafter\xdef\csname c@tcode\endcsname{\the\catcode`\@}
\catcode`\@=11
%
%  \math{4+3*5}  should yield  19
%
\def\math#1{\m@thinit\m@theval #1)}
\def\m@threcurse({\m@thinit\m@theval}
\def\m@theval{\futurelet\q\m@thone}
\def\m@thone{%
\iftrue\let\next\m@therr\fi
%
%  Is q a macro?
%
\ifcat\q\relax\let\next\m@thmacro\fi
%
%  Is q a digit?
%
\if\q0\let\next\m@thdigit\fi
\if\q1\let\next\m@thdigit\fi
\if\q2\let\next\m@thdigit\fi
\if\q3\let\next\m@thdigit\fi
\if\q4\let\next\m@thdigit\fi
\if\q5\let\next\m@thdigit\fi
\if\q6\let\next\m@thdigit\fi
\if\q7\let\next\m@thdigit\fi
\if\q8\let\next\m@thdigit\fi
\if\q9\let\next\m@thdigit\fi
%
%  Is q an open parenthesis?
%
\if\q(\let\next\m@threcurse\fi
%
%  Is q a close parenthesis?
%
\if\q)\let\next\m@thend\fi
%
%  Is q an operator?
%
\if\q+\let\next\m@thop\fi
\if\q-\let\next\m@thop\fi
\if\q*\let\next\m@thop\fi
\if\q/\let\next\m@thop\fi
%
\next}
%
%  Main parse loop has been done.  Now we need the utility routines.
%
\newcount\m@tha\newcount\m@thb
%
\def\m@thinit{\begingroup\m@tha=0\m@thb=0\let\m@tholdop\m@thadd}
\def\m@thdigit#1{\multiply\m@thb by 10\advance\m@thb by #1\m@theval}
\def\m@thadd{\advance\m@tha by \m@thb}
\def\m@thsub{\advance\m@tha by -\m@thb}
\def\m@thmul{\multiply\m@tha by \m@thb}
\def\m@thdiv{\divide\m@tha by \m@thb}
\def\m@thop#1{%
\m@tholdop\m@thb=0
\if\q+\let\m@tholdop\m@thadd\fi
\if\q-\let\m@tholdop\m@thsub\fi
\if\q*\let\m@tholdop\m@thmul\fi
\if\q/\let\m@tholdop\m@thdiv\fi
\m@theval}
%
\def\m@thend){\m@tholdop\xdef\m@thtemp{\number\m@tha}\endgroup\m@thb=\m@thtemp
\ifx\m@tholdop\relax\let\next\m@thfinal\else\let\next\m@theval\fi
\next}
%
\def\m@thfinal{\number\m@thb}
\let\m@tholdop=\relax % this will remain true on the ``outside''
\def\m@therr{\message{Math parsing error -- bad character is:}\show\q}
\def\m@thmacro#1{\expandafter\m@theval#1}
\catcode`\@=\c@tcode
