%{
	uses   YaccLib, LexLib;
        (* TP4 ex2 *)
%}

%type <Integer> S	/* expressions */
%type <Integer> T
%left '+'      	/* operators */
%left '*'

%%
input	: /* empty */
	| input '\n'    { yyaccept; }
	| input S '\n'	{ writeln($2); }
	| error '\n'    { yyerrok; }

S    :  S '+' S	   { $$ := $1 + $3; }
	|  S '*' S { $$ := $1 * $3; }
	|  T     { $$ := $1; }

T : T'1' {$$:=$1+1}
T : '1'  {$$:=1}

%%
{$I tp4Lex_2}
var i : Integer;
begin
  if yyparse=0 then (* fini! *);
end.
