Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  ss
Language: PASCAL
Code:
unit convsor;
   interface
      uses 
         expsion;
      procedure transfPolonesa(ein:string; var eout:tExp);
   implementation
      uses
         pilasim,operdres,simbolos;
      procedure decbin(s:string; var i:integer;  var n:integer);
      begin
         n:=0;
         while (s[i]>='0') and (s[i]<='9') and (i<=length(s)) do
         begin
            n:=n*10+(ord(s[i])-ord('0'));
            i:=i+1
         end
      end;
      procedure colocaSimbolo(y:tSim; var e:tExp; var p:tPilaSim);
      var
         x:tSim;
         a,b:tOprdor;
      begin
         if not esOperador(y) then
            anadeSimbolo(e,y)
         else
         begin
            pilasim.cima(p,x);
            a:= operador(x);
            b:= operador(y);
            if (a<>dolar) or (b<>dolar) then
            begin
               if precizqda(a)<precdcha(b) then
                  pilasim.apilar(p,y)
               else
               begin
                  while precizqda(a)>precdcha(b) do
                  begin
                     anadeSimbolo(e,x);
                     pilasim.desapilar(p);
                     pilasim.cima(p,x);
                     a:= operador(x)
                  end;
                  if precizqda(a)=precdcha(b) then
                     pilasim.desapilar(p)
                  else
                     pilasim.apilar(p,y)
               end
            end
            else
               pilasim.desapilar(p)
         end
      end;
      procedure transfPolonesa(ein:string; var eout:tExp);
      var
         p:tPilaSim;
         a:tSim;
         i,x:integer;
      begin
         expNula(eout);
         pilasim.p_nula(p);
         hazOperador(dolar,a);
         pilasim.apilar(p,a);
         i:= 1;
         while i<=length(ein) do
            begin
               if ein[i]=' ' then
                  i:=i+1
               else if ein[i]='+' then
               begin
                  hazOperador(suma,a);
                  colocaSimbolo(a,eout,p);
                  i:=i+1
               end
               else if ein[i]='-' then
               begin
                  hazOperador(resta,a);
                  colocaSimbolo(a,eout,p);
                  i:=i+1
               end
               else if ein[i]='*' then
               begin
                  hazOperador(producto,a);
                  colocaSimbolo(a,eout,p);
                  i:=i+1
               end
               else if ein[i]='/' then
               begin
                  hazOperador(division,a);
                  colocaSimbolo(a,eout,p);
                  i:=i+1
               end
               else if ein[i]='(' then
               begin
                  hazOperador(parizqdo,a);
                  colocaSimbolo(a,eout,p);
                  i:=i+1
               end
               else if ein[i]=')' then
               begin
                  hazOperador(pardcho,a);
                  colocaSimbolo(a,eout,p);
                  i:=i+1
               end
               else if (ein[i]>='0') and (ein[i]<='9') then
               begin
                  decbin(ein,i,x);
                  hazOperando(x,a);
                  colocaSimbolo(a,eout,p)
               end
               else
                  i:=i+1
            end;
         hazOperador(dolar,a);
         colocaSimbolo(a,eout,p)
      end;
end.
     
Comments: