
?<include list>;

<calc #result>
	<print "calc : "> 
	::sys <getline #line 
		<setVar exprlist ()>
		<expr>
	>
	<exprlist #x>
	<rpnf #result #x>
	<print " = " #result>
	;

<expr>
	<expradd>
	;

<expradd>
		<exprmul>
		{
		   "+" <exprmul>
				<exprlist #x>
				::list <append #list #x ("+")>
				<setVar exprlist #list>
		 |
		   "-" <exprmul> 
				<exprlist #x>
				::list <append #list #x ("-")>
				<setVar exprlist #list>
		}
	;

<exprmul>  
		<exprID>
		{ 
		     "*" <exprID> 
				<exprlist #x>
				::list <append #list #x ("*")>
				<setVar exprlist #list>
		  |
		     "/" <exprID>
				<exprlist #x>
				::list <append #list #x ("/")>
				<setVar exprlist #list>
		}
        ;

<exprID>
	   "+" <exprterm> 
	 |
	   "-" <exprterm>
				<exprlist #x>
				::list <append #list #x ("-1" "*")>
				<setVar exprlist #list>
	 |
	  <exprterm>
	;

<exprterm>
	   "(" <expr> ")" 
	|
	   <FNUM #t>
				<exprlist #x>
				::list <append #list #x  (#t)>
				<setVar exprlist #list>
	;


?{ <calc #line> };

