Procedure ErrorMes(S:String);
Begin
  WriteLn(S);
  Halt;
End;
Var LexNum : Word;
Const

startp : array[1..23] of byte=
($E9,$A7,$A9,$55,$89,$E5,$8B,$7E,$06,$8B
,$76,$08,$8B,$4E,$04,$FC,$F3,$A4,$89,$EC
,$C2,$06,$00);

pushdx:byte=$52;
cbw : byte=$98;
cwd : byte=$99;
callf: byte=$E8;
pushdi :byte=$57;                           {=<>}
cmp : array[1..10] of byte=($5A,$5B,$39,$D3,$75,$7E,$7D,2,$B0,1);
ifcode : array[1..8] of byte=($58,$A8,$01,$75,$03,$E9,0,0);
startb : array[1..7] of byte=($55,$89,$E5,$81,$EC,0,0);
     {push bp;mov bp,sp;sub sp,0000}
endb   : array[1..6] of byte=($89,$EC,$5D,$c2,0,0);
     {mov sp,bp; pop bp;ret 00}
pushax : array[1..10] of byte=($89,$EF,$8B,$7D,$04,$8D,$85,0,0,$50);
         {mov di,bp; mov di,[di+4], lea ax,[di+0000], push ax}
popax : array[1..7] of byte=($5F,$66,$88,$05,$89,$05,$58);
         {pop di;mov [di],al;mov [di],ax; pop ax}
logical : array[1..11] of byte=($58,$89,$E7,$00,$05,$F7,$15,$1D,$F7,$EF,$FF);
         {pop ax;mov di,sp; op [di],ax; not word ptr [di];imul di;idiv}
pushcon : array[1..9] of byte=($BF,0,0,$8B,$05,$50,$58,$31,$C0);
         {mov di,0000, mov ax,[di]; push ax; pop ax; xor ax,ax}
Var
  prog_pos        : word;
  operationstack : Stack;
{-------------------------------}
Procedure MakeSyntax;
Var
  C   : LingvoP;
  bb,bb2  : byte;
  OOO : LongInt;
  Code : Integer;
  E  : ListP;
  F  : File of Byte;
{-------------------------------}
Procedure Next;
Begin
  inc(LexNum);
  C:=C^.Next;
End;
{-------------------------------}
Function Check(t,cc:word):Boolean;
Begin
  check:=(c^.LType=T) and (c^.LCode=Cc);
end;
{--------------------------}
Procedure CallOperation(operationtype,operationcode:integer;_32:boolean);forward;
Procedure Expression(Level,operationlevel : integer; _32:boolean);forward;
{-------------------------------}
Function Push(P:LingvoP;Level:Integer):Integer;
var
  d : blockp;
  q : byte;
  L : listp;
  boo : boolean;
  ii : indexp;
Begin
  write(f,pushax[1], pushax[2]);
  d:=cu;
  While level>P^.LCode do begin
    write('>');
    write(f,pushax[3], pushax[4],pushax[5]);
    dec(level);
    d:=d^.prev;
  end;
  l:=listFindP(P^.LPnt,D^.IdentL);
  if l=nil then begin writeln('internal error3');halt;end;
  if (l^.tty=8) and (l^.s=cu^.procname) then begin
    seek(f,filepos(f)-3);
    pushax[8]:=lo(l^.size+4);
    pushax[9]:=hi(l^.size+4);
    push:=2;
    write(f,pushax[6],pushax[7],pushax[8],pushax[9],pushax[10]);
  end
  else begin
    pushax[8]:=lo(-l^.code);
    pushax[9]:=hi(-l^.code);
    if check(4,11) then begin
      Next;
      write(f,pushax[6],pushax[7],pushax[8],pushax[9],pushax[10]);  {сохраним адресок}
      operationstack.push(0,4,11);
      ii:=l^.indexl;
      if ii=nil then errormes('неверное применение индекса');
      write('[');
      repeat
        expression(level,0,false);
        q:=$B8;
        pushax[8]:=lo(ii^.first);
        pushax[9]:=hi(ii^.first);
        write(ii^.first);
        write(f,q,pushax[8],pushax[9],pushax[10]);
        {отнимем FIRST}   calloperation(4,10,false);

        {сохраним множитель}
        pushax[8]:=lo(ii^.size);
        pushax[9]:=hi(ii^.size);
        write(f,q,pushax[8],pushax[9],pushax[10]);
        write(ii^.size);
        {умножим}  calloperation(4,13,false);
        {прибавим} calloperation(4,9,false);
        if not check(4,12) then begin ii:=ii^.next; write(',');end
                         else write(']');
        boo:=not check(4,4);
        if check(4,4) then next;
      until boo;
      if not check(4,12) then errormes('ожидалась ]');
      push:=ii^.size;
      next;
    end
    else begin
      push:=l^.size;
      write(f,pushax[6],pushax[7],pushax[8],pushax[9],pushax[10]);
    end;
  end;
End;
{-------------------------------}
Procedure NextIf(t,cc:word);
begin
  if check(T,cc) then begin next; end
  else  begin
    write('ожидался :',a[t],':',cc,' - ');
    if t=2 then writeln(keywords[cc].s);
    if t=4 then writeln(ssym[cc]);
    halt;
  end;
end;
{----------------------}
Function PushV(P:LingvoP;Level:Integer;_32:boolean):Integer;
var
  d : blockp;
  ii: indexp;
  L : listp;
  q : byte;
   boo : boolean;
qq : byte;
  size:byte;
  level1:integer;
Begin
  write(f,pushax[1], pushax[2]);
  d:=cu;
  level1:=level;
  While level1>P^.LCode do begin
    write('>');
    write(f,pushax[3], pushax[4],pushax[5]);
    dec(level1);
    d:=d^.prev;
  end;
  l:=listFindP(P^.LPnt,D^.IdentL);
  if (l^.tty>8) then errormes('ожидалась переменная');
  if (l^.tty=8) then begin
        level1:=level;
        write(f,pushdi);
        next;
        if check(4,1) then begin
          next;
          while l^.indexl^.prev<>nil do l^.indexl:=l^.indexl^.prev;
          repeat
            operationstack.push(0,4,1);
            if l^.indexl^.size=4 Then Expression(level,1,true)
                                   Else Expression(level,1,false);
            if not check(4,2) then begin
              nextif(4,4);
              if l^.indexl^.next=nil then errormes(') - ожидалась');
              l^.indexl:=l^.indexl^.next;
            end;
          until check(4,2);next;
          if l^.indexl^.next<>nil then errormes('ожидались параметры');
        end;
        level1:=level;
        write(f,pushax[1], pushax[2]);
        While level1>P^.LCode do begin
          write(f,pushax[3], pushax[4],pushax[5]);
           dec(level1);
        end;
        addcall(filepos(f)+2,l^.proc);
        write(f,pushdi,callf,startb[6],startb[7]);
        WriteLn('Call function:',ListFind(P^.LPnt,D^.IdentL));
        exit;
  end;
  write(L^.S,' ');
  if l=nil then begin writeln('internal error31');halt;end;
  pushax[8]:=lo(-l^.code);
  pushax[9]:=hi(-l^.code);
  Next;
  if check(4,11) then begin
    Next;
    write(f,pushax[6],pushax[7],pushax[8],pushax[9],pushax[10]);  {сохраним адресок}
    operationstack.push(0,4,11);
    ii:=l^.indexl;
    if ii=nil then errormes('неверное применение индекса');
    write('[');
    repeat
      expression(level,0,false);
      q:=$B8;
      pushax[8]:=lo(ii^.first);
      pushax[9]:=hi(ii^.first);
      write(ii^.first);
      write(f,q,pushax[8],pushax[9],pushax[10]);
      {отнимем FIRST}   calloperation(4,10,false);
      
      {сохраним множитель}
      pushax[8]:=lo(ii^.size);
      pushax[9]:=hi(ii^.size);
      write(f,q,pushax[8],pushax[9],pushax[10]);
      write(ii^.size);
      {умножим}  calloperation(4,13,false);
      {прибавим} calloperation(4,9,false);
      if not check(4,12) then begin ii:=ii^.next; write(',');end
                         else write(']');
      boo:=not check(4,4);
      if check(4,4) then next;
    until boo;
    if not check(4,12) then errormes('ожидалась ]');
    write(f,popax[1]);   {pop di}
    {сохраним значение в стеке}
    size:=ii^.size;
    pushax[9]:=0;
    pushax[8]:=0;
    next;
  end
  else size:=l^.size;
  q:=$8B;
  if size=1 then begin q:=$8A; end;
  if size=4 then qq:=$66 else qq:=$90;
  write(f,qq,q,pushax[7],pushax[8],pushax[9]);
  case size of
  1: write(f,cbw,pushax[10]);
  4: write(f,qq,pushax[10])
  else  if _32 then write(f,qq,cbw,qq,pushax[10]) else write(f,pushax[10]);
  end;
  if (qq=$66) and (not _32) then write(f,pushcon[7]);
  pushv:=size;
End;
{-------------------------------}
Function PushC(P:LingvoP;_32:boolean):Integer;
var
  L : listp;
  q : byte;
Begin
  l:=listFindP(P^.LPnt,CsB);
  if l=nil then begin writeln('internal error41');halt;end;
  if l^.size=4 then q:=$66 else q:=$90;
  pushcon[2]:=lo(l^.code);
  pushcon[3]:=hi(l^.code);
  if (l^.size=1) and (not _32) then write(f,pushcon[1],pushcon[2],pushcon[3],pushcon[4],pushcon[5],cbw,pushcon[6]); 
  if (l^.size=1) and (_32) then write(f,pushcon[1],pushcon[2],pushcon[3],pushcon[4],pushcon[5],cbw,q,cbw,q,pushcon[6]);
  if (l^.size=2) and (_32) then write(f,pushcon[1],pushcon[2],pushcon[3],pushcon[4],pushcon[5],q,cbw,q,pushcon[6]);
  if (l^.size=2) and (not _32) then write(f,pushcon[1],pushcon[2],pushcon[3],pushcon[4],pushcon[5],pushcon[6]);
  if (l^.size=4) then write(f,pushcon[1],pushcon[2],pushcon[3],q,pushcon[4],pushcon[5],q,pushcon[6]);
  if (q=$66) and (not _32) then write(f,pushcon[7]);
  pushc:=l^.size;
  write(' "',L^.S,'" ');
  Next;
End;
{-------------------------------}
Function GetLevel(v1,v2 : integer):Integer;
Begin
  Case v1 Of
    2:case V2 of{ключевые слова}
          {div/mod/neg} 20,21,42: getlevel:=8;
          {then}11,{to/downto/do} 16,17,19: getlevel:=1;
          {and} 7: getlevel:=4;
          {or}  6: getlevel:=3;
          {xor} 8: getlevel:=4;
          {not} 5: getlevel:=5
          else begin writeln('2ожидалась ;'); halt;end;   
      end;
    4:case v2 of{разделители}
     {(}1 : getlevel:=0;
      {)} 2: getlevel:=1;
       {<>=}14,15,8:getlevel:=6;
       {+-} 9,10: getlevel:=7;
      {*/}13,7: getlevel:=8;
      {,;} 4,5,{]}12 : getlevel:=1
        else begin writeln('2ожидалась ;'); halt;end;   
      end
    else begin writeln('1ожидалась ;'); halt;end
  end;
End;
{-------------------------------}
Procedure CallOperation(operationtype,operationcode:integer;_32:boolean);
var
  dd : byte;
  i : byte;
begin
  if (operationtype=0) and (operationcode=0) then begin writeln(';');exit;end;
  if operationtype=2 then write(' ',keywords[operationcode].s,' ');
  if operationtype=4 then write(ssym[operationcode]);

{---------ну давай считать---------------------}
  if _32 then dd:=$66 else dd:=$90;
  case operationtype of
    2:begin
        case operationcode of{ключевые слова}
          {then}11: exit;
          {div}20:if _32 then errormes('Эта операция только для целых чисел')
             else write(f,popax[1],logical[1],cwd,logical[9],logical[11],pushax[10]);
          {mod}21:if _32 then errormes('Эта операция только для целых чисел')
             else write(f,popax[1],logical[1],cwd,logical[9],logical[11],pushdx);
          {to/downto/do} 16,17,19: exit;
          {and} 7: begin bb:=$21;end;
          {or}  6: begin bb:=$09;end;
          {xor} 8: begin bb:=$31;end;
          {not} 5: begin end;
          {neg} 42: begin end
          else begin writeln('_2Lожидалась ;'); halt;end;
        end;
        if operationcode in [5..8,42] then
        case operationcode of
          5: write(f,logical[2],logical[3],dd,logical[6],logical[7]);
          42: write(f,logical[2],logical[3],dd,logical[6],logical[8])
          else write(f,dd,logical[1],logical[2],logical[3],dd,bb,logical[5]);
        end;
      end;
    4:case operationcode of{разделители}
     {(}1 : exit;
     {)} 2: exit;
      {=<>}8,14,15 : begin
           case operationcode of
            8:i:=$75;
            15:i:=$7E;
            14:i:=$7D;
          end;
          write(f,dd,pushcon[8],pushcon[9],dd,cmp[1],dd,cmp[2],dd,cmp[3],cmp[4],
                  i,cmp[8],cmp[9],cmp[10],dd,pushcon[6]);
        end;
     {+-} 9,10: begin
          if operationcode=9 then bb:=01 else bb:=$29;
           write(f,dd,logical[1],logical[2],logical[3],dd,bb,logical[5]);
         end;
      {*} 13: if _32 then exit
             else write(f,logical[1],popax[1],logical[9],logical[10],pushax[10]);
      {/} 7: if _32 then exit
             else write(f,popax[1],logical[1],cwd,logical[9],logical[11],pushax[10]);
      {,;]} 4,5,12 : exit
        else begin writeln('_2Aожидалась ;'); halt;end;
      end
    else begin writeln('_1ожидалась ;'); halt;end
  end;
{  if operationtype=2 then write(keywords[operationcode].s);
  if operationtype=4 then write(ssym[operationcode]);}
end;
{-------------------------------}
Procedure Expression(Level,operationlevel : integer; _32:boolean);
var
  operationcode, operationtype : integer;
  newlevel : integer;
  dd : byte;
  bb : byte;
  v1,v2,v3  : integer;
Begin
  repeat
  operationcode:=C^.LCode;
  operationtype:=C^.LType;
  if check(4,10) or check(2,5) Then Begin
    if check(4,10) then OperationStack.Push(9,2,42)
                   else OperationStack.Push(5,2,5);
    Next;
    operationcode:=C^.LCode;
    operationtype:=C^.LType;
  End;
  Case OperationType Of
    1:begin pushv(c,level,_32);end;
    3:begin pushc(c,_32);end;
    4:If Check(4,1) Then Begin
        NewLevel:=0;
        next;
        OperationStack.Push(newlevel,operationtype,operationcode);
        Expression(Level,NewLevel,_32);
        if not check(4,2) then ErrorMes('ожидалась )');
        Next;
      End Else ErrorMes('ожидался идентификатор1');
    Else ErrorMes('ожидался идентификатор2');
  End;  
{---------- Теперь операции -----------------}
  operationcode:=C^.LCode;
  operationtype:=C^.LType;
  NewLevel:=GetLevel(operationtype,operationcode);
  if operationstack.top(v1,v2,v3)=false then errormes('неизвестная ошибка1');
  If ((newlevel=0) or (NewLevel>v1)) and (not check(4,12)) and (not check(4,4))
  and (newlevel<>1) and (not check(4,2)) then OperationStack.Push(newlevel,operationtype,operationcode)
  Else Begin
    If (NewLevel=1) and (not check(4,2)) and (not check(4,4)) and (not check(4,12)) then begin
        While operationstack.top(v1,v2,v3) Do Begin
          operationstack.Pop(v1,v2,v3);
          CallOperation(v2,v3,_32);
        End;
      Exit;
    End;
    While not (NewLevel>v1) Do Begin
      if operationstack.Pop(v1,v2,v3)=false then errormes('неизвестная ошибка2');
      CallOperation(v2,v3,_32);
      if operationstack.top(v1,v2,v3)=false then errormes('неизвестная ошибка3');
    End;
    If check(4,2) or check(4,4) or check(4,12) then begin
      if (v2=4) and (v3=1) and check(4,2) Then operationstack.pop(v1,v2,v3);
      if (v2=4) and (v3=11) and check(4,12) Then operationstack.pop(v1,v2,v3);
      exit;
    End
    Else OperationStack.Push(newlevel,operationtype,operationcode);
  End;
  next;
  until newlevel=1;
End;
{-------------------------------}
Procedure Run(varaddr,level:integer;main:boolean;ending:word);
var
  fd,fd1,fd2: byte;
  db1,db2:byte;
  jmpaddr : word;
  withbegin : boolean;
  test : integer;
  ss: integer;
  bb,bb2: byte;
  D : LingvoP;
  de : indexp;
  returnaddr : word;
  mlist : listp;
  level1:integer;
  cu1 : blockp;
  otheraddr:integer;
Begin
  if main then 
{------сохраняем код начала процедуры---}
  begin
    cu^.addr:=filepos(f);
 {   prog_pos:=filepos(f)-3;
    bb:=prog_pos mod 256;
    bb2 :=prog_pos shr 8;
    seek(f,1);write(f,bb,bb2);
    seek(f,filesize(f));}
  end;
  if main then begin
    startb[6]:=lo(varaddr);
    startb[7]:=hi(varaddr);
    for fd:=1 to 7 do write(f,startb[fd]);  
  end;
{--------- непосредственный траляля ----------------}
  withbegin:=not check(2,1);
  if check(2,1) then next;
  Repeat
    fd:=C^.LType;
    D:=C;
    Case fd OF
    2:begin
       fd1:=c^.Lcode;
       case fd1 of
       2 : begin end;{end} 
{inline}  43: begin
         next;
         nextif(4,1);
         repeat
           if C^.LType<>3 Then errormes('ожидалась константа');
           val(ListFind(C^.LPnt,CsB),fd2,test);
           write(f,fd2);
           if test <>0 then  errormes('ожидалась целочисленная константа');
           next;
           if not check(4,2) then nextif(4,7);
         until check(4,2);
         nextif(4,2);
         nextif(4,5);
       end;
{while}34: begin
          next;
          returnaddr:=filepos(f);
          writeln('while ',returnaddr+$100);
          operationstack.init;
          operationstack.push(0,0,0);
          expression(level,0,false);
          operationstack.done;
          nextif(2,17);
          writeln('do');
          for fd2:=1 to 8 do write(f,ifcode[fd2]);
          otheraddr:=filepos(f);
          run(varaddr,level,false,0);
          write(f,ifcode[6]);
          jmpaddr:=filepos(f)+2-returnaddr;
          writeln('endwhile ',jmpaddr+returnaddr+$100-2);
          db1:=lo(-jmpaddr);
          db2:=hi(-jmpaddr);
          write(f,db1,db2);
          jmpaddr:=filepos(f)-otheraddr;
          seek(f,otheraddr-2);
          db1:=lo(jmpaddr);
          db2:=hi(jmpaddr);
          write(f,db1,db2);
          if not withbegin then nextif(4,5);
          seek(f,filesize(f));
        end;
       10:{if} begin
            next;
            write('if ');
            operationstack.init;
            operationstack.push(0,0,0);
            expression(level,0,false);
            operationstack.done;
            nextif(2,11);
            for fd2:=1 to 8 do write(f,ifcode[fd2]);
            returnaddr:=filepos(f);
            writeln('then ',returnaddr+$100);
            run(varaddr,level,false,0);
            write(f,ifcode[6],ifcode[7],ifcode[8]);
            jmpaddr:=filepos(f)-returnaddr;
            writeln('endthen ',jmpaddr+returnaddr+$100);
            seek(f,returnaddr-2);
            db1:=lo(jmpaddr);
            db2:=hi(jmpaddr);
            write(f,db1,db2);
            seek(f,jmpaddr+returnaddr);
            if check(4,5) then begin next;writeln('endif');end
            else if check(2,12) then begin
                next;
                returnaddr:=filepos(f);
                writeln('else ',returnaddr+$100);
                run(varaddr,level,false,0);
                write(f,ifcode[6],ifcode[7],ifcode[8]);
                jmpaddr:=filepos(f)-returnaddr;
                writeln('endelse ',jmpaddr+returnaddr+$100);
                seek(f,returnaddr-2);
                db1:=lo(jmpaddr);
                db2:=hi(jmpaddr);
                write(f,db1,db2);
                seek(f,jmpaddr+returnaddr);
                if check(4,5) then begin if not withbegin then next;writeln('endif');end
                    else errormes('; - отсутствует');
            end
            else errormes('else должно быть поблизости');
          end
          else begin write('ожидается идентификатор',c^.LType,'|',c^.lcode,'|=',fd);end;
       end;
    end;
    1: Begin
      write($100+filepos(f),' :');
      cu1:=cu;
      while Cu1^.Levelnum>D^.LCode do cu1:=cu1^.prev;
      mlist:=ListFindP(D^.LPnt,Cu1^.IdentL);
      Next;
      IF (mlist^.tty in [8,9]) and (not (check(4,6) and (mlist^.tty=8)))  Then Begin
        level1:=level;
        if check(4,1) then begin
          next;
          while mlist^.indexl^.prev<>nil do mlist^.indexl:=mlist^.indexl^.prev;
          repeat
            operationstack.init;
            operationstack.push(0,0,0);
            if mlist^.indexl^.size=4 Then Expression(level,1,true)
                                   Else Expression(level,1,false);
            operationstack.done;
            if not check(4,2) then begin
              nextif(4,4);
              if mlist^.indexl^.next=nil then errormes(') - ожидалась');
              mlist^.indexl:=mlist^.indexl^.next;
            end;
          until check(4,2);next;
          if mlist^.indexl^.next<>nil then errormes('ожидались параметры');
        end;
        level1:=level;
        write(f,pushax[1], pushax[2]);
        While level1>D^.LCode do begin
          write(f,pushax[3], pushax[4],pushax[5]);
          dec(level1);
        end;
        addcall(filepos(f)+2,mlist^.proc);
        write(f,pushdi,callf,startb[6],startb[7]);
        WriteLn('Call Procedures:',ListFind(D^.LPnt,Cu1^.IdentL));
        if (not check(4,5)) and (not withbegin) then errormes('; -где?');
        if not withbegin then Next;
      End
      Else Begin
        operationstack.push(1,0,0);
        cu1:=cu;
        while D^.LCode<cu1^.levelnum do cu1:=cu1^.prev;
        Write('Push -',ListFind(D^.LPnt,Cu1^.IdentL));
        ss:=push(D,level);
        if not (ss in [1,2,4]) then errormes('неверный тип');
        nextif(4,6);nextif(4,8); { := }
        Write(':=');
          operationstack.push(1,0,0);
        if ss=4 Then Expression(level,1,true)
                Else Expression(level,1,false);
        if not withbegin then nextif(4,5);
        case ss of
         1: write(f,popax[7],popax[1],popax[3],popax[4]);
         4: write(f,popax[2],popax[7],popax[1],popax[2],popax[5],popax[6])
         else write(f,popax[7],popax[1],popax[5],popax[6]);
        end;
      End;
    End
    Else Begin WriteLn('Error!',c^.LType,'|',c^.lcode,'|=',fd);halt;End;
  End;
  Until ((C^.LType=2) And (C^.LCode=2)) or withbegin;
  if not withbegin then Next;
  if main then begin
    endb[6]:=hi(ending);endb[5]:=lo(ending);
    for fd:=1 to 6 do write(f,endb[fd]);
  end;

End;
{-------------------------------}
Procedure StartLevel(level:word;ending:word);
Var
  Code: Word;
  varaddr : integer;
{-------------------------------}
Procedure GetVar;
Var
  e : listp;
  e1 : listp;
  res,ee : Word;
  cur: indexp;
Begin
  While C^.LType=1 Do Begin
    E:=listfindp(C^.LPnt,Cu^.IdentL);
    If e=nil then begin writeln('internal error1');halt;end;
    next;
    if (C^.LType<>4) And (C^.LCode<>6) Then begin WriteLn(': expected');halt;end;
    next;
    if C^.LType<>2 Then begin WriteLn('Type expected');halt;end;
    ee:=C^.LCode;
    if ee<>9 then e^.IndexL:=nil;
    Case ee Of
      {array}9: begin
               new(e^.IndexL);
               cur:=e^.IndexL;
               e^.tty:=6;
               cur^.prev:=nil;
               cur^.next:=nil;
               next; nextif(4,11);
               repeat
               if c^.LType<>3 Then begin WriteLn('ожидалось целочисленный индекс1 массива');halt;end;
               if C^.LCode<>1 then begin WriteLn('ожидалось целочисленный индекс2 массива');halt;end;
               e1:=listfindp(c^.LPnt,CsB);
               val(e1^.S,cur^.first,res);
               next;
               nextif(4,8);
               if c^.LType<>3 Then begin WriteLn('ожидалось целочисленный индекс3 массива');halt;end;
               if C^.LCode<>1 then begin WriteLn('ожидалось целочисленный индекс4 массива');halt;end;
               e1:=listfindp(c^.LPnt,CsB);
               val(e1^.S,cur^.last,res);
               next;
               if (C^.LType<>4) or ((C^.LCode<>4) and (C^.LCode<>12)) then begin WriteLn('ожидалась ]');halt;end;
               if (C^.LType=4) and (C^.LCode=4) Then Begin
                 next;
                 new(cur^.Next);
                 cur^.tty:=6;
                 Cur^.Next^.Next:=nil;
                 Cur^.Next^.Prev:=cur;
                 cur:=cur^.next;
               End;
               until (C^.LType=4) and (C^.LCode=12);
               nextif(4,12);  { ] }
               nextif(2,14); { of }
               if c^.LType<>2 then begin WriteLn('Type expected2');halt;end;
               case c^.lcode of
                  32: begin 
                    cur^.tty:=4;
                    new(cur^.next);
                    cur^.next^.next:=nil;
                    cur^.next^.prev:=cur;                   
                    cur:=cur^.next;
                    cur^.first:=0;
                    cur^.last:=255;
                    cur^.size:=1;cur^.tty:=3;
                  end;
                  37,39: begin cur^.size:=2;cur^.tty:=1;end;
                  38: begin cur^.size:=4;cur^.tty:=2;end;
                  40: begin cur^.size:=1;cur^.tty:=5;end;
                  36: begin cur^.size:=1;cur^.tty:=7;end;
                  41: begin cur^.size:=1;cur^.tty:=3;end
                 else begin WriteLn('Type expected21');halt;end;
               end;
               while cur^.prev<>nil do begin
                 cur^.prev^.size:=cur^.size*(1+cur^.last-cur^.first);
                 cur:=cur^.prev;
               end;
               e^.size:=cur^.size*(1+cur^.last-cur^.first);
               inc(varaddr,e^.size);
               e^.code:=varaddr;
             end;
      {str}  32: begin new(e^.IndexL);
               e^.IndexL^.size :=1;
               e^.IndexL^.First:=0;
               e^.IndexL^.Last:=255;
               e^.IndexL^.TTy:=3; {char};
               e^.IndexL^.Prev:=nil;
               e^.IndexL^.Next:=nil;
               e^.TTy:=4; {string ~ array[0..255] of char}
               inc(varaddr,256);
               e^.code:=varaddr;
               e^.size:=256;
             end;
      {word/int} 37,39: begin
               e^.TTy:=1; {int}
               inc(varaddr,2);
               e^.code:=varaddr;
               e^.size:=2;
              end;
       {byte} 36: begin
               e^.TTy:=7; {byte}
               inc(varaddr,1);
               e^.code:=varaddr;
               e^.size:=1;
              end;
      {real}        38: begin
               e^.TTy:=2; {int}
               inc(varaddr,4);
               e^.code:=varaddr;
               e^.size:=4;
              end;
      {boolean}     40: begin
               e^.TTy:=5; {bool}
               inc(varaddr,1);
               e^.code:=varaddr;
               e^.size:=1;
              end;
      {char}  41: begin
               e^.TTy:=3; {char}
               inc(varaddr,1);
               e^.code:=varaddr;
               e^.size:=1;
              end
      else begin WriteLn('Type expected1');halt;end;
    End;
    WriteLn(e^.S,' | ',a3[e^.TTy],' | bp-',e^.code,' | ',e^.size);
    cur:=e^.indexL;
    while cur<>nil do begin
      writeln(cur^.first,' .. ',cur^.last,' * ', cur^.size,' of ', a3[cur^.Tty]);
      cur:=cur^.next;
    end;
    next;
    if (C^.LType=4) and (C^.LCode=5) then next else begin WriteLn('; expected1');halt;end;
  End;
  if ((C^.LType=4) and ((C^.LCode=3) or (C^.LCode=5))) then Begin WriteLn('Begin Expected1');Halt;End;
End;
{-------------тело процедуры стартлевел--------------------}
var
  inl : indexp;
  ddd : listp;
  dcur: listp;
  old,dc: lingvop;
  mysize:integer;
Begin
  varaddr:=0;
  Repeat
    If C^.LType<>2 Then Begin WriteLn('Begin Expected2');Halt;End;
    Code:=C^.LCode;
    Case Code Of
{var}  3 : Begin next; getvar; end;
{func/proc} 22,23: begin
             next;
             ddd:=listfindp(c^.Lpnt,cu^.identL);
             cu:=cu^.nextlevel;
             while (cu<>nil) and (cu^.bln+1<>lexnum) do cu:=cu^.next;
             if cu=nil then errormes('неполноценная таблица блоков');
             ddd^.proc:=cu;
             next;
             if code=22 then ddd^.tty:=8 else ddd^.tty:=9;
{             ddd^.code:=filepos(f);}
             if check(4,5) or check(4,1) then
             begin
               if code=22 then ddd^.size:=2 else ddd^.size:=0;inl:=nil;
               mysize:=4;
               if check(4,1) then begin
                 next;               old:=c;
                 repeat
                   if inl=nil then begin
                     new(inl);
                     inl^.prev:=nil;
                     inl^.next:=nil;
                   end
                   else begin
                     new(inl^.next);
                     inl^.next^.prev:=inl;
                     inl^.next^.next:=nil;
                     inl:=inl^.next;
                   end;
                   if c^.LType<>1 Then errormes('ожидался параметр процедуры');
                   dc:=c;next;
                   nextif(4,6);
                   if c^.LType<>2 Then errormes('неверный тип параметра процедуры');
                   dcur:=listfindp(dc^.lPnt,cu^.identl);
                   case c^.lcode of
                     38:begin
                       inl^.size:=4;
                       dcur^.tty:=2;
                       dcur^.size:=4;
                       inc(mysize,4);
                     end;
                     36,37,39,40,41 : begin
                       inl^.size:=2;
                       dcur^.tty:=1;
                       dcur^.size:=2;
                       inc(mysize,2);
                     end
                     else errormes('неверный тип параметра процедуры');
                   end;
                   next;
                   if not check(4,2) then nextif(4,5);
                 until check(4,2);

                 while inl^.prev<>nil do inl:=inl^.prev;
                 ddd^.indexl:=inl;
                 dc:=old;
                 ddd^.size:=mysize-4;
                 if code=22 then inc(ddd^.size,2);
                 while mysize>4 do begin
                   dcur:=listfindp(dc^.lPnt,cu^.identl);
                   dcur^.code:=-mysize;
                   dec(mysize,dcur^.size);
                   dc:=dc^.next^.next^.next^.next;
                 end;
                 next;
               end;
               next;
               if code=22 then startlevel(cu^.levelnum,ddd^.size) else startlevel(cu^.levelnum,ddd^.size+2);
               if not check(4,5) then errormes('end;');
               next;
             end;
             {---------???????????-----}
             cu:=cu^.prev;
           End;
{begin} 1: begin run(varaddr,level,true,ending); end
else Begin WriteLn('Begin Expected!!!');Halt;End;
    End;
  Until ((C^.LType=4) and ((C^.LCode=3) or (C^.LCode=5)));
  IF (C^.LCode=3) and (level>0) Then Begin Writeln('End; expected'); Halt; End;
End;
{===============================}
var
  constvar : listp;
  int1,res :  integer;
  real1 : real;
  int2: longint;
  str1 : string;  
  n : calladdrp;
Begin
  assign(f,'res.com');rewrite(f);
  For ooo:=1 to 23 do write(f,startp[ooo]);
{----------определим тип констант, и запишем их в файл!!!------------------}
  constvar:=csb;
  Writeln('---------- константы -----------');
  while constvar<>nil do begin
    constvar^.code:=filepos(f)+$100;
    case constvar^.tty of
    1:begin       
       val(constvar^.s,int1,res);
       if res<>0 then begin writeln(constvar^.s,'  -- обшибка'); exit; end;
       bb:=int1 mod 256;
       bb2 :=int1 shr 8;
       write(f,bb,bb2);       
      end;
    2:begin
       val(constvar^.s,real1,res);
       if res<>0 then begin writeln(constvar^.s,'  -- обшибка'); exit; end;
       int2:=round(65536*real1);
       bb:=int2 mod 256;
       bb2 :=(int2 shr 8) mod 256;
       write(f,bb,bb2);       
       bb :=(int2 shr 16) mod 256;
       bb2 :=(int2 shr 24);
       write(f,bb,bb2);   
      end;
    3:begin
       bb:=ord(constvar^.s[1]);
       write(f,bb);
     end;
    4:begin
      bb:=length(constvar^.s);write(f,bb);  
      for int1:=1 to 255 do begin if int1>bb then bb2:=0 else bb2:=ord(constvar^.s[int1]);
        write(f,bb2);
      end;
    end;    
    end;
    writeln(constvar^.s,'|',constvar^.code,'|',constvar^.size,'|',constvar^.TTy);
    constvar:=constvar^.next;
  end;   
{--------Запись JMP!!!-----------------}
  C:=Lin;
{-------Переход в начало блока Begin -------------}
  writeln('программа');
  Cu:=Main;
  addcall(1,main);
  LexNum:=1;
  operationstack.init;
  StartLevel(0,0);
  operationstack.done;
  if not check(4,3) then errormes('ожидалась end. ');
  while myrecall<>nil do begin
    n:=myrecall;
    myrecall:=n^.next;
    writeln('calling ',n^.who^.procname,' at ', n^.who^.addr+$100, ' from ', n^.fromcall+$100);
    seek(f,n^.fromcall);
    popax[1]:=lo(n^.who^.addr-2-n^.fromcall);
    popax[2]:=hi(n^.who^.addr-2-n^.fromcall);
    write(f,popax[1],popax[2]);
    dispose(n);
  end;
  close(f);
End;