.


:




:

































 

 

 

 


2.4

 

, . . 3- . .

 

- . , 1 . 1 ( ), - ( ).

:

 

 

 


- : , ,

= 0

 

Pop

Push()

  . -  
  - op_um  
  abs op_abs  
  + op_add push(pop+pop)
  op_sub buf=pop push(pop-buf)
  * op_mult push(pop*pop)
  / op_div ....
  % op_mod ....
  < op_less buf=pop if (pop<buf) then push(1) else push(0)
  > op_grt ....
  = op_equ ....
  | op_or push(pop | pop)
  & op_and ....
  ~ op_not  
    op_view  
    op_stop  

 

  . -  
    >= op_  
    <= op_  
    <> op_  
    !> op_  
    !< op_  
    != op_  
    e2 op_  
    sign op_  

 


 

curr_code.op -

curr_code.adr

var[1..v_max] -

code[1..c_max]

  op_pushC push(curr_code.adr)
  op_pushV _ push(var[curr_code.adr])
  op_pop _  
  op_jamp _ curr_adr = adr_com
  op_jmpC _ if pop=1 then curr_adr = adr_com else curr_adr=curr_adr + 1

 

:

( )

 

 


 

Procedure VirtComp(

Code array[1..CMAX) of instr, { }

Var array[1..VMAX] of integer) { }

 

begin

curr_adr:=1; { }

curr_code:=code[curr_adr]; { 1 }

 

{ ϻ }

while curr_code.op<>op_stop do

begin

{ }

case curr_code.op of

{ }

 

op_plus: begin push(pop+pop); { }

curr_adr:=curr_adr+1 end;

 

op_sub: begin buf:=pop; push(pop-buf);

curr_adr:=curr_adr+1 end; { }

........

op_less: begin buf:=pop; { < }

if pop<buf then push(1)

else push(0) end;

........

{ }

op_pushC: begin push(curr_code.adr);

curr_adr:=curr_adr+1 end;

 

op_pushV: begin push(var[curr_code.adr]]);

curr_adr:=curr_adr+1 end;

 

{ }

op_jamp: curr_adr:=curr_code.adr;

op_jampC: begin if pop=1

then curr_adr:=curr_code.adr]

else curr_adr:=curr_adr+1 end;

 

else w_err( )

end{case};

curr_code:=code[curr_adr]; { }

end {while}

end { VirtComp}


( )

 

1. : {gencode(_, )}

2.

 

MULT

MULT=id | number | (EXPR)

 

 

,

 

 

MULT= idP {gencode(op_pushV, P)} |

numberP {gencode(op_pushC, P)} |

(EXPR)

 

 


ADD

 

ADD = MULT { oper MULT }

 

ADD = MULT { operP {R=P } MULT {gencode(R, 0)} }

 

EXPR

 

LOGIC


 

 

STMT= id =EXPR

STMT= idP =EXPR {gencode(op_pop, Q)} Q:=P

 

If typeLex=id then

Begin

Buf=valueLex

Getlex();

EXPR();

Gencode(op_pop, buf)

End

Else if typeLex=view then

 

VIEW

 

STMT= view EXPR

STMT= view EXPR {gencode(op_view, 0)}

 

if typeLex=view then

begin

getlex();

EXPR();

gencode(op_view, 0)

end

else if typeLex=view then




<== | ==>
. |
:


: 2017-01-28; !; : 338 |


:

:

: , .
==> ...

1351 - | 1300 -


© 2015-2024 lektsii.org - -

: 0.026 .