I suggest you take a look at some of the concepts used in the template system, such as Smarty, and implement your own. For example, a mathematical template allows you to perform the following operations:
{* $height=4, $width=5 *}
{math equation="x + y" x=$height y=$width}
, . - , eval().
, RPN (Reverse Polish Notation) : +, - , *, /, IF, THEN, SWAP, DUP, =, <>, >, <. >= <=.