Program Postfix_program; Uses crt,Tipusu,Uverem,Usor; Type muvelet=record jel:string; prc:byte; end; prectomb=array[1..7] of muvelet; Const p=7; jelek:prectomb=((jel:'(';prc:0),(jel:'+';prc:1),(jel:'-';prc:1), (jel:'*';prc:2),(jel:'/';prc:2),(jel:'^';prc:3)); var Infix, PostFix:Tsor; lex:lexegys; v:tverem; er_str:string; er_strmeny:real; ok:integer; Function prec(lex:string):byte; var i:integer; begin i:=1; While (i
lex) do inc(i); prec:=jelek[i].prc; end; Procedure beolvas(var Infix:Tsor); var i:integer; szov:string; lex:lexegys; Function muvelet_e(lex:string):boolean; var i:integer; begin i:=1; While (i<=p) and (jelek[i].jel<>lex) do inc(i); If (jelek[i].jel=lex) or (lex=')') then muvelet_e:=true else muvelet_e:=false; end; begin While not eof(f) do begin Write('Kovetkezo elem? '); Readln(szov); Write(szov); lex.adat:=szov; If muvelet_e(szov) then lex.tipus:='m' else lex.tipus:='o'; writeln(lex.tipus); infix.sorba(lex); end; end; Procedure VerembolNyitoZig(var v:Tverem; var Postfix:Tsor); var e:TelemTip; begin While v.teteje<>'(' do begin v.verembol(e); Postfix.sorba(e); end; end; Procedure NemKisebbPrecVerembolKi(var v:Tverem; Postfix:Tsor; lex:lexegys); var x:lexegys; prec1,prec2:byte; begin While (prec(lex.adat)<=prec(v.teteje)) and not(v.ures_e) do begin v.verembol(x); Postfix.sorba(x); end; end; Procedure VerembolSorba(var V:Tverem ; Postfix:Tsor); var e:Lexegys; begin While not(v.ures_e) do begin v.verembol(e); Postfix.sorba(e); end; end; Procedure InPostFix(var infix:Tsor; var postfix:Tsor; var v:Tverem); begin While not infix.ures_e do begin Infix.sorbol(lex); Writeln(lex.adat); If lex.tipus='o' then Postfix.sorba(lex) else begin if lex.adat='(' then v.verembe(lex) else begin If lex.adat=')' then begin VerembolNyitoZig(v,Postfix); v.verembol(lex); end else begin NemKisebbPrecVerembolKi(v,Postfix,lex); v.verembe(lex); end; end; end; end; VerembolSorba(v,PostFix); end; Procedure Kiiras(postfix:Tsor); var e:lexegys; begin While not postfix.ures_e do begin Postfix.sorbol(e); Write(e.adat); Write(' '); end; end; Function Muvfv(c:string; op1,op2:real):real; begin If c='+' then Muvfv:=op1+op2 else If c='-' then Muvfv:=op1-op2 else If c='*' then Muvfv:=op1*op2 else If c='/' then Muvfv:=op1/op2 else If c='^' then Muvfv:=Hatvany(op1,op2) end; end; Function Kiertekeles(var Postfix:Tsor):string; var lex,lex2:Lexegys; op1,op2,op3:real; ok:integer; begin While not(Postfix.ures_e) do begin Postfix.sorbol(lex); If lex.tipus='o'then v.verembe(lex) else begin v.verembol(lex2); val(lex2.adat,op2,ok); If ok<>0 then begin write(lex2.adat,' 2. operandus? '); readln(op2); end; v.verembol(lex2); val(lex2.adat,op1,ok); If ok<>0 then begin write(lex2.adat,' 1. operandus '); readln(op1); end; op3:=muveletvegzes(lex.adat,op1,op2); str(op3,lex2.adat); lex.tipus:='o'; v.verembe(lex2); end; end; v.verembol(lex); Kiertekeles:=lex.adat; end; begin infix.ures; postfix.ures; v.ures; clrscr; beolvas(infix); InPostfix(infix,postfix,v); er_str:=Kiertekeles(PostFix); val(er_str,eredmeny,ok); Write('Az er_strmeny:'); writeln(eredmeny); end.