%{ uses YaccLib, LexLib; (* TP4 ex3 *) %} %token NUM /* constants */ %type S /* expressions */ %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; } | NUM { $$ := $1; } ; %% {$I tp4Lex} var i : Integer; begin if yyparse=0 then { done }; end.