Advertisement
Golden_Rus

Gasm compil release

Feb 26th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 29.43 KB | None | 0 0
  1. //compil
  2. program compil;
  3.  
  4. {$APPTYPE CONSOLE}
  5. //03.01.2015
  6. {
  7. 03.01.2015: mov add or and jmp int cmp not
  8. 16.01.2015: jme jmm jml jmn
  9. The End 26.02.2015
  10. }
  11.  
  12. uses
  13.   SysUtils,
  14.   Classes,
  15.   Windows;
  16.  
  17. var _stack, stack_cmd:array[0..10000] of string;
  18.     stack_param:array[0..3000, 0..1] of string;
  19.     _ram, _var:array[0..9] of string;
  20.     ram:array[0..1023] of integer;
  21.     str:string;
  22.     version:string='1.4r';
  23.     date:string='03.01.2015';
  24.     fb: array [1..320, 1..240] of byte;
  25.     i, j, cmd, cmd_num:integer;
  26.     stat:boolean=true;
  27. {function _cmd(numb:integer):boolean;
  28. begin
  29. if (stack_cmd[numb]='mov') and (stack_cmd[numb]='add') and (stack_cmd[numb]='or') and (stack_cmd[numb]='and') and (stack_cmd[numb]='jmp') and (stack_cmd[numb]='int') and (stack_cmd[numb]='cmp') and  (stack_cmd[numb]='not') and (stack_cmd[numb]='jz') then Result:= true else Result:=false;
  30. end;  }
  31.  
  32. function Is_int(val:string):boolean;
  33. begin
  34.   val:=trim(val);
  35.   if (StrToIntDef(val, 0) = 0) and (StrToIntDef(val, 1) = 1) then
  36.     Is_int:=false
  37.   else
  38.     Is_int:=true;
  39. end;
  40. {
  41. //-----------------------------------------
  42. // Установка курсора в координаты X, Y
  43. //-----------------------------------------
  44. procedure GotoXY(X, Y: Integer);
  45. var
  46.   c: _COORD;
  47. begin
  48.   c.x:=X;
  49.   c.y:=Y;
  50.   SetConsoleCursorPosition(hndl,c);
  51. end;
  52.  
  53.  
  54. //--------------------------------------
  55. // Показываем/Скрываем курсор
  56. //--------------------------------------
  57.  procedure ShowCursor(Show: Boolean);
  58.  var
  59.  CCI: _CONSOLE_CURSOR_INFO;
  60. begin
  61. CCI.bVisible := Show;
  62.   SetConsoleCursorInfo(hndl, CCI);
  63. end;     //Не работает. Когда нибудь пофиксить. } //Не используется
  64. //<Блок процедур, описывающих мнемокод>
  65. //------------------------------------------------------------------------------------------------
  66. procedure _mov(n:integer);
  67. var p1, p2:string;
  68. begin
  69.   p1:=stack_param[n, 0];
  70.   p2:=stack_param[n, 1];
  71.   if (p2[1]='r') and (Is_int(p2[2])) then
  72.   begin
  73.     if (p1[1]='r') and (Is_int(p1[2])) then _ram[StrToInt(p2[2])]:=_ram[StrToInt(p1[2])]
  74.     else if (p1[1]='v') and (Is_int(p1[2])) then _ram[StrToInt(p2[2])]:=_var[StrToInt(p1[2])]
  75.     else _ram[StrToInt(p2[2])]:=p1;
  76.   end
  77.   else if (p2[1]='v') and (Is_int(p2[2])) then
  78.    begin
  79.     if (p1[1]='r') and (Is_int(p1[2])) then _var[StrToInt(p2[2])]:=_ram[StrToInt(p1[2])]
  80.     else if (p1[1]='v') and (Is_int(p1[2])) then _var[StrToInt(p2[2])]:=_var[StrToInt(p1[2])]
  81.     else _var[StrToInt(p2[2])]:=p1;
  82.   end
  83.   else
  84.   begin
  85.     writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  86.   end;
  87. end;
  88. //--------------------------------------------------------------------------------------------------
  89.  procedure _add(n:integer);
  90. var p1, p2:string;
  91. begin
  92.   p1:=stack_param[n, 0];
  93.   p2:=stack_param[n, 1];
  94.   if (p1[1]='r') and (Is_int(p1[2])) then
  95.   begin
  96.     if (p2[1]='r') and (Is_int(p1[2])) then
  97.       if (Is_int(_ram[StrToInt(p2[2])])) and (Is_int(_ram[StrToInt(p1[2])])) then
  98.         _ram[StrToInt(p1[2])]:=IntToStr(StrToInt(_ram[StrToInt(p1[2])])+StrToInt(_ram[StrToInt(p2[2])]))
  99.       else
  100.         _ram[StrToInt(p1[2])]:=_ram[StrToInt(p1[2])]+_ram[StrToInt(p2[2])]
  101.       else if (p2[1]='v') and (Is_int(p2[2])) then
  102.         if (Is_int(_var[StrToInt(p2[2])])) and (Is_int(_ram[StrToInt(p1[2])])) then
  103.           _ram[StrToInt(p1[2])]:=IntToStr(StrToInt(_ram[StrToInt(p1[2])])+StrToInt(_var[StrToInt(p2[2])]))
  104.         else
  105.           _ram[StrToInt(p1[2])]:=_ram[StrToInt(p1[2])]+_var[StrToInt(p2[2])]
  106.       else if (Is_int(p2)) and (Is_int(_ram[StrToInt(p1[2])])) then
  107.         _ram[StrToInt(p1[2])]:=IntToStr(StrToInt(_ram[StrToInt(p1[2])])+StrToInt(p2))
  108.         else
  109.           _ram[StrToInt(p1[2])]:=_ram[StrToInt(p1[2])]+p2
  110.     end
  111.   else if (p1[1]='v') and (Is_int(p1[2])) then
  112.    begin
  113.     if (p2[1]='r') and (Is_int(p1[2])) then
  114.       if (Is_int(_ram[StrToInt(p2[2])])) and (Is_int(_var[StrToInt(p1[2])])) then
  115.         _var[StrToInt(p1[2])]:=IntToStr(StrToInt(_var[StrToInt(p1[2])])+StrToInt(_ram[StrToInt(p2[2])]))
  116.       else
  117.         _var[StrToInt(p1[2])]:=_var[StrToInt(p1[2])]+_ram[StrToInt(p2[2])]
  118.       else if (p2[1]='v') and (Is_int(p2[2])) then
  119.         if (Is_int(_var[StrToInt(p2[2])])) and (Is_int(_var[StrToInt(p1[2])])) then
  120.           _var[StrToInt(p1[2])]:=IntToStr(StrToInt(_var[StrToInt(p1[2])])+StrToInt(_var[StrToInt(p2[2])]))
  121.         else
  122.           _var[StrToInt(p1[2])]:=_var[StrToInt(p1[2])]+_var[StrToInt(p2[2])]
  123.       else if (Is_int(p2)) and (Is_int(_var[StrToInt(p1[2])])) then
  124.         _var[StrToInt(p1[2])]:=IntToStr(StrToInt(_var[StrToInt(p1[2])])+StrToInt(p2))
  125.         else
  126.           _var[StrToInt(p1[2])]:=_var[StrToInt(p1[2])]+p2;
  127.     end
  128.   else
  129.     writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  130. end;
  131. //-----------------------------------------------------------------------------------------------------
  132. procedure _or(n:integer);
  133. var p1, p2:string;
  134. begin
  135.   p1:=stack_param[n, 0];
  136.   p2:=stack_param[n, 1];
  137.   if (p1[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p1[2])]='true') or (_ram[StrToInt(p1[2])]='false')) then
  138.   begin
  139.     if (p2[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p2[2])]='true') or (_ram[StrToInt(p2[2])]='false')) then
  140.       if (_ram[StrToInt(p1[2])]='true') or (_ram[StrToInt(p2[2])]='true') then
  141.         _ram[0]:='true'
  142.       else _ram[0]:='false'
  143.  
  144.     else if (p2[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p2[2])]='true') or (_var[StrToInt(p2[2])]='false')) then
  145.       if (_ram[StrToInt(p1[2])]='true') or (_var[StrToInt(p2[2])]='true') then
  146.         _ram[0]:='true'
  147.       else _ram[0]:='false'
  148.     else if (p2='true') or (p2='false') then
  149.       if (_ram[StrToInt(p1[2])]='true') or (p2='true') then
  150.         _ram[0]:='true'
  151.       else _ram[0]:='false'
  152.   end
  153.   else if (p1[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p1[2])]='true') or (_var[StrToInt(p1[2])]='false')) then
  154.   begin
  155.     if (p2[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p2[2])]='true') or (_ram[StrToInt(p2[2])]='false')) then
  156.       if (_var[StrToInt(p1[2])]='true') or (_ram[StrToInt(p2[2])]='true') then
  157.         _ram[0]:='true'
  158.       else _ram[0]:='false'
  159.  
  160.     else if (p2[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p2[2])]='true') or (_var[StrToInt(p2[2])]='false')) then
  161.       if (_var[StrToInt(p1[2])]='true') or (_var[StrToInt(p2[2])]='true') then
  162.         _ram[0]:='true'
  163.       else _ram[0]:='false'
  164.     else if (p2='true') or (p2='false') then
  165.       if (_var[StrToInt(p1[2])]='true') or (p2='true') then
  166.         _ram[0]:='true'
  167.       else _ram[0]:='false'
  168.   end
  169.   else if ((p1='true') or (p1='false')) and ((p2='true') or (p2='false'))  then
  170.   begin
  171.       if (p1='true') or (p2='true') then
  172.         _ram[0]:='true'
  173.       else _ram[0]:='false'
  174.   end
  175.   else
  176.     writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  177. end;
  178. //---------------------------------------------------------------------------------------------------
  179. procedure _and(n:integer);
  180. var p1, p2:string;
  181. begin
  182.   p1:=stack_param[n, 0];
  183.   p2:=stack_param[n, 1];
  184.   if (p1[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p1[2])]='true') or (_ram[StrToInt(p1[2])]='false')) then
  185.   begin
  186.     if (p2[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p2[2])]='true') or (_ram[StrToInt(p2[2])]='false')) then
  187.       if (_ram[StrToInt(p1[2])]='true') and (_ram[StrToInt(p2[2])]='true') then
  188.         _ram[0]:='true'
  189.       else _ram[0]:='false'
  190.  
  191.     else if (p2[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p2[2])]='true') or (_var[StrToInt(p2[2])]='false')) then
  192.       if (_ram[StrToInt(p1[2])]='true') and (_var[StrToInt(p2[2])]='true') then
  193.         _ram[0]:='true'
  194.       else _ram[0]:='false'
  195.     else if (p2='true') or (p2='false') then
  196.       if (_ram[StrToInt(p1[2])]='true') and (p2='true') then
  197.         _ram[0]:='true'
  198.       else _ram[0]:='false'
  199.   end
  200.   else if (p1[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p1[2])]='true') or (_var[StrToInt(p1[2])]='false')) then
  201.   begin
  202.     if (p2[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p2[2])]='true') or (_ram[StrToInt(p2[2])]='false')) then
  203.       if (_var[StrToInt(p1[2])]='true') and (_ram[StrToInt(p2[2])]='true') then
  204.         _ram[0]:='true'
  205.       else _ram[0]:='false'
  206.  
  207.     else if (p2[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p2[2])]='true') or (_var[StrToInt(p2[2])]='false')) then
  208.       if (_var[StrToInt(p1[2])]='true') and (_var[StrToInt(p2[2])]='true') then
  209.         _ram[0]:='true'
  210.       else _ram[0]:='false'
  211.     else if (p2='true') or (p2='false') then
  212.       if (_var[StrToInt(p1[2])]='true') and (p2='true') then
  213.         _ram[0]:='true'
  214.       else _ram[0]:='false'
  215.   end
  216.   else if ((p1='true') or (p1='false')) and ((p2='true') or (p2='false'))  then
  217.   begin
  218.       if (p1='true') and (p2='true') then
  219.         _ram[0]:='true'
  220.       else _ram[0]:='false'
  221.   end
  222.   else
  223.     writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  224. end;
  225. //--------------------------------------------------------------------------------------------
  226. procedure _jmp(n:integer);
  227. var p1, p2:string;
  228. begin
  229.   p1:=stack_param[n, 0];
  230.   cmd_num:=StrToInt(p1)-1;
  231. end;
  232. //--------------------------------------------------------------------------------------------
  233. procedure _int(n:integer);
  234. var p1, p2:string;
  235.     _tmp:integer;
  236.     Fil:TStringList;
  237. begin
  238.   p1:=stack_param[n, 0];
  239.   p2:=stack_param[n, 1];
  240.   //------------------------- консоль ввод-вывод--------------------------------
  241.   if p1='pnt' then
  242.   begin
  243.     if (p2[1]='r') and (Is_int(p2[2])) then writeln(_ram[StrToInt(p2[2])])
  244.     else if (p2[1]='v') and (Is_int(p2[2])) then writeln(_var[StrToInt(p2[2])])
  245.     else writeln(p2);
  246.   end
  247.   else if p1='in' then
  248.   begin
  249.     if (p2[1]='r') and (Is_int(p2[2])) then readln(_ram[StrToInt(p2[2])])
  250.     else if (p2[1]='v') and (Is_int(p2[2])) then readln(_var[StrToInt(p2[2])])
  251.     else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  252.   end
  253.   //-----------------------------работа с диском--------------------------------
  254.   else if p1='wdsk' then
  255.   begin
  256.     if Is_int(p2) then
  257.     begin
  258.     _tmp:=StrToInt(p2);
  259.       if (_tmp>=0) and (_tmp<4095) and (Is_Int(_var[0])) then
  260.         begin
  261.         Fil:=TStringList.Create;
  262.         Fil.LoadFromFile('disk');
  263.         Fil.Strings[_tmp]:=_var[0];
  264.         Fil.SaveToFile('disk');
  265.         Fil.Free;
  266.         end
  267.       else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
  268.     end
  269.     else if (p2[1]='r') and (Is_int(p2[2])) then
  270.     begin
  271.     _tmp:=StrToInt(p2[2]);
  272.       if (_tmp>=0) and (_tmp<4095) and (Is_Int(_var[0])) then
  273.         begin
  274.         Fil:=TStringList.Create;
  275.         Fil.LoadFromFile('disk');
  276.         Fil.Strings[StrToInt(_ram[_tmp])]:=_var[0];
  277.         Fil.SaveToFile('disk');
  278.         Fil.Free;
  279.         end
  280.       else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
  281.     end
  282.     else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  283.   end
  284.  
  285.   else if p1='rdsk' then
  286.   begin
  287.     if Is_int(p2) then
  288.     begin
  289.     _tmp:=StrToInt(p2);
  290.       if (_tmp>=0) and (_tmp<4095) then
  291.         begin
  292.           Fil:=TStringList.Create;
  293.           Fil.LoadFromFile('disk');
  294.           _var[0]:=Fil.Strings[_tmp];
  295.           Fil.SaveToFile('disk');
  296.           Fil.Free;
  297.         end
  298.       else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
  299.     end
  300.     else if (p2[1]='r') and (Is_int(p2[2])) then
  301.     begin
  302.     _tmp:=StrToInt(p2[2]);
  303.       if (_tmp>=0) and (_tmp<4095) then
  304.         begin
  305.           Fil:=TStringList.Create;
  306.           Fil.LoadFromFile('disk');
  307.           _var[0]:=Fil.Strings[StrToInt(_ram[_tmp])];
  308.           Fil.SaveToFile('disk');
  309.           Fil.Free;
  310.         end
  311.       end
  312.     else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  313.   end
  314.   //------------------------Работа с ОЗУ----------------------------------------
  315.   else if p1='wram' then
  316.   begin
  317.     if Is_int(p2) then
  318.     begin
  319.     _tmp:=StrToInt(p2);
  320.       if (_tmp>=0) and (_tmp<1024) and (Is_Int(_ram[9])) then
  321.         begin
  322.         ram[_tmp]:=StrToInt(_ram[9]);
  323.         end
  324.       else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
  325.     end
  326.     else if (p2[1]='r') and (Is_int(p2[2])) then
  327.     begin
  328.     _tmp:=StrToInt(p2[2]);
  329.       if (_tmp>=0) and (_tmp<1024) and (Is_Int(_ram[9])) then
  330.         begin
  331.         ram[StrToInt(_ram[_tmp])]:=StrToInt(_ram[9]);
  332.         end
  333.       else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
  334.     end
  335.     else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  336.   end
  337.  
  338.   else if p1='rram' then
  339.   begin
  340.     if Is_int(p2) then
  341.     begin
  342.     _tmp:=StrToInt(p2);
  343.       if (_tmp>=0) and (_tmp<1024) then
  344.         begin
  345.         _ram[9]:=IntToStr(ram[_tmp]);
  346.         end
  347.       else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
  348.     end
  349.     else if (p2[1]='r') and (Is_int(p2[2])) then
  350.     begin
  351.     _tmp:=StrToInt(p2[2]);
  352.       if (_tmp>=0) and (_tmp<1024) then
  353.         begin
  354.         _ram[9]:=IntToStr(ram[StrToInt(_ram[_tmp])]);
  355.         end
  356.       else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
  357.     end
  358.     else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  359.   end
  360.   //----------------------------------------------------------------------------
  361.   else
  362.     writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  363. end;
  364. //----------------------------------------------------------------------------------------------
  365. procedure _cmp(n:integer);
  366. var p1, p2:string;
  367. begin
  368.   p1:=stack_param[n, 0];
  369.   p2:=stack_param[n, 1];
  370.   if (p1[1]='r') and (Is_int(p2[2])) then
  371.   begin
  372.     if (p2[1]='r') and (Is_int(p1[2])) then
  373.     //-----int-----------
  374.       if (is_int(_ram[StrToInt(p1[2])])) and (is_int(_ram[StrToInt(p2[2])])) then
  375.         if StrToInt(_ram[StrToInt(p1[2])]) < StrToInt(_ram[StrToInt(p2[2])]) then
  376.         _ram[0]:='-1'
  377.       else if StrToInt(_ram[StrToInt(p1[2])]) = StrToInt(_ram[StrToInt(p2[2])]) then
  378.         _ram[0]:='0'
  379.       else if StrToInt(_ram[StrToInt(p1[2])]) > StrToInt(_ram[StrToInt(p2[2])]) then
  380.         _ram[0]:='1'
  381.  
  382.     else if (p2[1]='v') and (Is_int(p1[2])) then
  383.       if (is_int(_ram[StrToInt(p1[2])])) and (is_int(_var[StrToInt(p2[2])])) then
  384.         if StrToInt(_ram[StrToInt(p1[2])]) < StrToInt(_var[StrToInt(p2[2])]) then
  385.         _ram[0]:='-1'
  386.       else if StrToInt(_ram[StrToInt(p1[2])]) = StrToInt(_var[StrToInt(p2[2])]) then
  387.         _ram[0]:='0'
  388.       else if StrToInt(_ram[StrToInt(p1[2])]) > StrToInt(_var[StrToInt(p2[2])]) then
  389.         _ram[0]:='1'
  390.     else
  391.       if (is_int(_ram[StrToInt(p1[2])])) and (is_int(p2)) then
  392.         if StrToInt(_ram[StrToInt(p1[2])]) < StrToInt(p2) then
  393.         _ram[0]:='-1'
  394.       else if StrToInt(_ram[StrToInt(p1[2])]) = StrToInt(p2) then
  395.         _ram[0]:='0'
  396.       else if StrToInt(_ram[StrToInt(p1[2])]) > StrToInt(p2) then
  397.         _ram[0]:='1'
  398.     //-------/int--------------
  399.     //------str----------------
  400.     else if (not is_int(_ram[StrToInt(p1[2])])) and (not is_int(_ram[StrToInt(p2[2])])) then
  401.         if  length(_ram[StrToInt(p1[2])]) < length(_ram[StrToInt(p2[2])]) then
  402.         _ram[0]:='-1'
  403.       else if length(_ram[StrToInt(p1[2])]) = length(_ram[StrToInt(p2[2])]) then
  404.         if _ram[StrToInt(p1[2])]= _ram[StrToInt(p2[2])] then
  405.           _ram[0]:='0'
  406.         else
  407.           _ram[0]:='-0'
  408.       else if length(_ram[StrToInt(p1[2])]) > length(_ram[StrToInt(p2[2])]) then
  409.         _ram[0]:='1'
  410.  
  411.     else if (p2[1]='v') and (Is_int(p1[2])) then
  412.       if (not is_int(_ram[StrToInt(p1[2])])) and (not is_int(_var[StrToInt(p2[2])])) then
  413.         if length(_ram[StrToInt(p1[2])]) < length(_var[StrToInt(p2[2])]) then
  414.         _ram[0]:='-1'
  415.       else if length(_ram[StrToInt(p1[2])]) = length(_var[StrToInt(p2[2])]) then
  416.         if _ram[StrToInt(p1[2])]=_var[StrToInt(p2[2])] then
  417.         _ram[0]:='0'
  418.         else
  419.           _ram[0]:='-0'
  420.       else if length(_ram[StrToInt(p1[2])]) > length(_var[StrToInt(p2[2])]) then
  421.         _ram[0]:='1'
  422.     else
  423.       if (not is_int(_ram[StrToInt(p1[2])])) and (not is_int(p2)) then
  424.         if length(_ram[StrToInt(p1[2])]) < length(p2) then
  425.           if _ram[StrToInt(p1[2])]=p2 then
  426.           _ram[0]:='-1'
  427.       else if length(_ram[StrToInt(p1[2])]) = length(p2) then
  428.         if _ram[StrToInt(p1[2])]=p2 then
  429.           _ram[0]:='0'
  430.         else
  431.           _ram[0]:='-0'
  432.       else if length(_ram[StrToInt(p1[2])]) > length(p2) then
  433.         _ram[0]:='1'
  434.     //-----/str----------------
  435.   end
  436.   else if (p1[1]='v') and (Is_int(p2[2])) then
  437.   begin
  438.     if (p2[1]='r') and (Is_int(p1[2])) then
  439.       if (is_int(_var[StrToInt(p1[2])])) and (is_int(_ram[StrToInt(p2[2])])) then
  440.         if StrToInt(_var[StrToInt(p1[2])]) < StrToInt(_ram[StrToInt(p2[2])]) then
  441.         _ram[0]:='-1'
  442.       else if StrToInt(_var[StrToInt(p1[2])]) = StrToInt(_ram[StrToInt(p2[2])]) then
  443.         _ram[0]:='0'
  444.       else if StrToInt(_var[StrToInt(p1[2])]) > StrToInt(_ram[StrToInt(p2[2])]) then
  445.         _ram[0]:='1'
  446.  
  447.     else if (p2[1]='v') and (Is_int(p1[2]))then
  448.       if (is_int(_var[StrToInt(p1[2])])) and (is_int(_var[StrToInt(p2[2])])) then
  449.         if StrToInt(_var[StrToInt(p1[2])]) < StrToInt(_var[StrToInt(p2[2])]) then
  450.         _ram[0]:='-1'
  451.       else if StrToInt(_var[StrToInt(p1[2])]) = StrToInt(_var[StrToInt(p2[2])]) then
  452.         _ram[0]:='0'
  453.       else if StrToInt(_var[StrToInt(p1[2])]) > StrToInt(_var[StrToInt(p2[2])]) then
  454.         _ram[0]:='1'
  455.     else
  456.       if (is_int(_var[StrToInt(p1[2])])) and (is_int(p2)) then
  457.         if StrToInt(_var[StrToInt(p1[2])]) < StrToInt(p2) then
  458.         _ram[0]:='-1'
  459.       else if StrToInt(_var[StrToInt(p1[2])]) = StrToInt(p2) then
  460.         _ram[0]:='0'
  461.       else if StrToInt(_var[StrToInt(p1[2])]) > StrToInt(p2) then
  462.         _ram[0]:='1'
  463.   end
  464.  else if p1=p2  then
  465.   _ram[0]:='true'
  466.  else
  467.   _ram[0]:='false';
  468. end;
  469. //----------------------------------------------------------------------------------------------
  470. procedure _not(n:integer);
  471. var p1:string;
  472. begin
  473.   p1:=stack_param[n, 0];
  474.   if (p1[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p1[2])]='true') or (_ram[StrToInt(p1[2])]='false')) then
  475.   begin
  476.       if _ram[StrToInt(p1[2])]='true' then
  477.         _ram[StrToInt(p1[2])]:='false'
  478.       else _ram[StrToInt(p1[2])]:='true'
  479.   end
  480.   else if (p1[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p1[2])]='true') or (_var[StrToInt(p1[2])]='false')) then
  481.   begin
  482.       if _var[StrToInt(p1[2])]='true' then
  483.         _var[StrToInt(p1[2])]:='false'
  484.       else _var[StrToInt(p1[2])]:='true'
  485.   end
  486.   else
  487.     writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
  488. end;
  489. //----------------------------------------------------------------------------------------------
  490. procedure _jme(n:integer);
  491. var p1, p2:string;
  492. begin
  493.   p1:=stack_param[n, 0];
  494.   if _ram[0]='0' then cmd_num:=StrToInt(p1)-1;
  495. end;
  496. //----------------------------------------------------------------------------------------------
  497. procedure _jmm(n:integer);
  498. var p1, p2:string;
  499. begin
  500.   p1:=stack_param[n, 0];
  501.   if _ram[0]='1' then cmd_num:=StrToInt(p1)-1;
  502. end;
  503. //----------------------------------------------------------------------------------------------
  504. procedure _jml(n:integer);
  505. var p1, p2:string;
  506. begin
  507.   p1:=stack_param[n, 0];
  508.   if _ram[0]='-1' then cmd_num:=StrToInt(p1)-1;
  509. end;
  510. //----------------------------------------------------------------------------------------------
  511. procedure _jmn(n:integer);
  512. var p1, p2:string;
  513. begin
  514.   p1:=stack_param[n, 0];
  515.   if _ram[0]='-0' then cmd_num:=StrToInt(p1)-1;
  516. end;
  517. //----------------------------------------------------------------------------------------------
  518. //</Блок процедур, описывающих мнемокод>
  519. procedure inter();
  520. var _stat:boolean;
  521. begin
  522.       _stat:=true;
  523.       cmd_num:=0;
  524.         while _stat do
  525.         begin
  526.           if (stack_cmd[cmd_num]='') or (stack_cmd[cmd_num]=' ') or (cmd_num>=99) then
  527.           _stat:=false
  528.           //
  529.           else if stack_cmd[cmd_num]='mov' then
  530.           begin
  531.             _mov(cmd_num);
  532.             cmd_num:=cmd_num+1;
  533.           end
  534.           //
  535.           else if stack_cmd[cmd_num]='add' then
  536.           begin
  537.             _add(cmd_num);
  538.             cmd_num:=cmd_num+1;
  539.           end
  540.           //
  541.           else if stack_cmd[cmd_num]='jmp' then
  542.           begin
  543.             _jmp(cmd_num);
  544.             cmd_num:=cmd_num+1;
  545.           end
  546.           //
  547.           else if stack_cmd[cmd_num]='or' then
  548.           begin
  549.             _or(cmd_num);
  550.             cmd_num:=cmd_num+1;
  551.           end
  552.           //
  553.           else if stack_cmd[cmd_num]='and' then
  554.           begin
  555.             _and(cmd_num);
  556.             cmd_num:=cmd_num+1;
  557.           end
  558.           //
  559.           else if stack_cmd[cmd_num]='jme' then
  560.           begin
  561.             _jme(cmd_num);
  562.             cmd_num:=cmd_num+1;
  563.           end
  564.           //
  565.           else if stack_cmd[cmd_num]='jml' then
  566.           begin
  567.             _jme(cmd_num);
  568.             cmd_num:=cmd_num+1;
  569.           end
  570.           //
  571.           else if stack_cmd[cmd_num]='jmm' then
  572.           begin
  573.             _jme(cmd_num);
  574.             cmd_num:=cmd_num+1;
  575.           end
  576.           //
  577.           else if stack_cmd[cmd_num]='jmn' then
  578.           begin
  579.             _jme(cmd_num);
  580.             cmd_num:=cmd_num+1;
  581.           end
  582.           //
  583.           else if stack_cmd[cmd_num]='cmp' then
  584.           begin
  585.             _cmp(cmd_num);
  586.             cmd_num:=cmd_num+1;
  587.           end
  588.           //
  589.           else if stack_cmd[cmd_num]='not' then
  590.           begin
  591.             _not(cmd_num);
  592.             cmd_num:=cmd_num+1;
  593.           end
  594.           //
  595.           else if stack_cmd[cmd_num]='int' then
  596.           begin
  597.           _int(cmd_num);
  598.           cmd_num:=cmd_num+1;
  599.           end;
  600.         end;
  601. end;
  602. procedure parser(str_in:string);
  603. begin
  604. stat:=true;
  605. str_in:=trim(str_in);
  606.   if str='date' then writeln(date) else if length(str_in)>0 then
  607.   begin
  608.     j:=0;
  609.     for i:=0 to length(str_in) do if str_in[i] <> ' ' then _stack[j]:=trim(_stack[j]+str_in[i]) else j:=j+1;
  610.     j:=0;
  611.     i:=0;
  612.     cmd:=0;
  613.     while stat do
  614.     begin
  615.       if _stack[i]='' then begin
  616.         stat:=false;
  617.         end
  618.       else
  619.       if (_stack[i] = 'mov') or (_stack[i] = 'add') or (_stack[i] = 'or') or (_stack[i] = 'and') or (_stack[i] = 'cmp') or (_stack[i] = 'int') then
  620.       begin
  621.         stack_cmd[cmd]:=_stack[i];
  622.         stack_param[cmd, 0]:= _stack[i+1];
  623.         stack_param[cmd, 1]:= _stack[i+2];
  624.         i:=i+3;
  625.         cmd:=cmd+1;
  626.       end else if (_stack[i] = 'jmp') or (_stack[i] = 'not') or (_stack[i] = 'jme') or (_stack[i] = 'jmm') or (_stack[i] = 'jml') or (_stack[i] = 'jmn') then
  627.       begin
  628.         stack_cmd[cmd]:=_stack[i];
  629.         stack_param[cmd, 0]:= _stack[i+1];
  630.         i:=i+2;
  631.         cmd:=cmd+1;
  632.       end else begin
  633.         writeln('Expected mnemonic | invalid command:'+IntToStr(i));
  634.         stat:=false;
  635.       end;
  636.     end;
  637.   end;
  638.   inter();
  639. end;
  640. //------------------------------------------------------------------------------
  641. procedure _file();
  642. var f:TextFile;
  643.     text, tmp:string;
  644. begin
  645. assignFile(f, paramStr(1));
  646. Reset(f);
  647.  while (not EOF(f)) do
  648.  begin
  649.   Readln(f, tmp);
  650.   text:=text+' '+tmp;
  651.   tmp:='';
  652.  end;
  653.  parser(text);
  654. end;
  655. //-----------------------------------------------------------------------------------
  656. var _stat:boolean;
  657. begin
  658.   if ParamStr(1) <>'' then _file();
  659.   while true do
  660.   begin
  661.     write('G_asm v.'+version+': ');
  662.     readln(str);
  663.     parser(str);
  664.   end;
  665. end.
  666. ///compil
  667.  
  668. //editor
  669. unit Dl;
  670.  
  671. interface
  672.  
  673. uses
  674.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  675.   ExtDlgs, StdCtrls, ExtCtrls, Jpeg, Printers, ShellApi;
  676.  
  677. type                                    
  678.   TForm1 = class(TForm)
  679.     OpenDialog1: TOpenDialog;
  680.     SaveDialog1: TSaveDialog;
  681.     OpenPictureDialog1: TOpenPictureDialog;
  682.     SavePictureDialog1: TSavePictureDialog;
  683.     FontDialog1: TFontDialog;
  684.     ColorDialog1: TColorDialog;
  685.     PrintDialog1: TPrintDialog;
  686.     PrinterSetupDialog1: TPrinterSetupDialog;
  687.     FindDialog1: TFindDialog;
  688.     ReplaceDialog1: TReplaceDialog;
  689.     Button1: TButton;
  690.     Memo1: TMemo;
  691.     Button2: TButton;
  692.     Button5: TButton;
  693.     Button7: TButton;
  694.     Button9: TButton;
  695.     Button11: TButton;
  696.     Button12: TButton;
  697.     Button14: TButton;
  698.     Button3: TButton;
  699.     Memo2: TMemo;
  700.     procedure Button1Click(Sender: TObject);
  701.     procedure Button11Click(Sender: TObject);
  702.     procedure Button2Click(Sender: TObject);
  703.     procedure Button5Click(Sender: TObject);
  704.     procedure Button6Click(Sender: TObject);
  705.     procedure Button7Click(Sender: TObject);
  706.     procedure Button9Click(Sender: TObject);
  707.     procedure Button10Click(Sender: TObject);
  708.     procedure FindDialog1Find(Sender: TObject);
  709.     procedure Button8Click(Sender: TObject);
  710.     procedure Button12Click(Sender: TObject);
  711.     procedure Button13Click(Sender: TObject);
  712.     procedure FormCreate(Sender: TObject);
  713.     procedure Button14Click(Sender: TObject);
  714.     procedure ReplaceDialog1Replace(Sender: TObject);
  715.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  716.     procedure ReplaceDialog1Find(Sender: TObject);
  717.     procedure Button3Click(Sender: TObject);
  718.     procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
  719.       MousePos: TPoint; var Handled: Boolean);
  720.     procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
  721.       MousePos: TPoint; var Handled: Boolean);
  722.  
  723.   private
  724.   public
  725.     { Public declarations }
  726.   end;
  727.  
  728. var
  729.   Form1: TForm1;
  730.   EditFile: string;
  731.   version:string='1.4r';
  732.  
  733. implementation
  734.  
  735. {$R *.DFM}
  736.  
  737. procedure TForm1.Button12Click(Sender: TObject);
  738. begin
  739.  Memo1.Lines.Clear;
  740.  Memo1.Font.Size:=8;
  741.  Memo1.Font.Color:=clWindowText;
  742.  Memo1.Color:=clWindow;
  743. end;
  744.  
  745. procedure TForm1.Button1Click(Sender: TObject);
  746. begin
  747.  if OpenDialog1.Execute then
  748.   begin
  749.    EditFile:=OpenDialog1.FileName;
  750.    Memo1.Lines.LoadFromFile(EditFile);
  751.    Form1.Caption:='Compil_Editor ' +version+ ' - '+ExtractFileName(EditFile);
  752.   end;
  753. end;
  754. procedure _save();
  755. begin
  756.  //if SaveDialog1.Execute then
  757.   Form1.Memo1.Lines.SaveToFile(EditFile);//запись на прямую в файл
  758.   if Form1.Memo1.Modified then Form1.Memo1.Modified:=false;
  759. end;
  760. procedure TForm1.Button2Click(Sender: TObject);
  761. begin
  762. _save();
  763. end;
  764.  
  765. procedure TForm1.Button14Click(Sender: TObject);
  766. begin
  767.  if SaveDialog1.Execute then//запись в файл + диалоговое оконо
  768.   begin
  769.    EditFile:=SaveDialog1.FileName;
  770.    Memo1.Lines.SaveToFile(EditFile);
  771.    Form1.Caption:='Compil_Editor ' +version+ '- '+ExtractFileName(EditFile);
  772.    if Memo1.Modified then Memo1.Modified:=false;
  773.   end;
  774. end;
  775.  
  776. procedure TForm1.Button5Click(Sender: TObject);
  777. begin
  778.  if FontDialog1.Execute then Memo1.Font:=FontDialog1.Font;
  779. end;
  780.  
  781. procedure TForm1.Button6Click(Sender: TObject);
  782. begin
  783.  if ColorDialog1.Execute then Memo1.Font.Color:=ColorDialog1.Color;
  784. end;
  785.  
  786. procedure TForm1.Button13Click(Sender: TObject);
  787. begin
  788. if ColorDialog1.Execute then Memo1.Color:=ColorDialog1.Color;
  789. end;
  790.  
  791. procedure TForm1.Button7Click(Sender: TObject);
  792. var
  793.  Stroka:System.TextFile;
  794.  i:integer;    
  795. begin
  796.  if PrintDialog1.Execute then
  797.   begin
  798.    AssignPrn(Stroka);
  799.    Rewrite(Stroka);
  800.    Printer.Canvas.Font:=Memo1.Font;
  801.    for i:=0 to Memo1.Lines.Count-1 do
  802.     Writeln(Stroka,Memo1.Lines[i]);
  803.    System.CloseFile(Stroka);
  804.   end;
  805. end;
  806.  
  807.  
  808.  
  809. procedure TForm1.Button8Click(Sender: TObject);
  810. begin
  811.  PrinterSetupDialog1.Execute;
  812. end;
  813.  
  814. procedure TForm1.Button9Click(Sender: TObject);
  815. begin
  816.  FindDialog1.Execute;
  817. end;
  818.  
  819. procedure TForm1.Button10Click(Sender: TObject);
  820. begin
  821.  ReplaceDialog1.Execute;
  822. end;
  823.  
  824. procedure TForm1.FindDialog1Find(Sender: TObject);
  825. {begin
  826.  //ищется первое появление строки
  827.  if pos(FindDialog1.FindText,Memo1.Text)<>0 then
  828.   begin
  829.    Memo1.HideSelection:=false;
  830.    Memo1.SelStart:=pos(FindDialog1.FindText,Memo1.Text)-1;
  831.    Memo1.SelLength:=Length(FindDialog1.FindText);
  832.   end
  833.  else
  834.   MessageDlg('String '+FindDialog1.FindText+' not found!',mtConfirmation,[mbYes],0);}
  835. var
  836.  Buff,P,FT: PChar;
  837.  BuffLen: Word;
  838. begin
  839.  with Sender as TFindDialog do
  840.   begin
  841.    GetMem(FT, Length(FindText) + 1);
  842.    StrPCopy(FT, FindText);
  843.    BuffLen:= Memo1.GetTextLen + 1;
  844.    GetMem(Buff, BuffLen);
  845.    Memo1.GetTextBuf(Buff, BuffLen);
  846.    P:= Buff + Memo1.SelStart + Memo1.SelLength;
  847.    P:= StrPos(P, FT);
  848.    if P=nil then MessageBeep(0)
  849.    else
  850.     begin
  851.      Memo1.SelStart:= P - Buff;
  852.      Memo1.SelLength:= Length(FindText);
  853.     end;
  854.    FreeMem(FT, Length(FindText) + 1);
  855.    FreeMem(Buff, BuffLen);
  856.   end;
  857. end;
  858.  
  859. procedure TForm1.FormCreate(Sender: TObject);
  860. var i:integer;
  861. begin
  862.  EditFile:='Noname.txt';
  863.  Form1.Caption:='Compil_Editor ' +version+ ' - '+ExtractFileName(EditFile);
  864.  for i:=0 to 1000 do Form1.Memo2.Lines.Add(IntToStr(i));
  865.  for i:=0 to 1000 do Form1.Memo1.Lines.Add('');
  866. end;
  867.  
  868. procedure TForm1.ReplaceDialog1Replace(Sender: TObject);
  869. label 10;//метка
  870. begin
  871.  Memo1.HideSelection:=true;
  872.  10://метка
  873.   if pos(ReplaceDialog1.FindText,Memo1.Text)<>0 then
  874.    begin
  875.     Memo1.SelStart:=pos(ReplaceDialog1.FindText,Memo1.Text)-1;
  876.     Memo1.SelLength:=Length(ReplaceDialog1.FindText);
  877.     Memo1.SelText:=ReplaceDialog1.ReplaceText;
  878.     goto 10;
  879.    end;
  880.  Memo1.HideSelection:=false;
  881. end;
  882.  
  883. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  884. begin
  885.  if Memo1.Modified then
  886.   if MessageDlg('File '+ExtractFileName(EditFile)+' changed'+#10#13'Confirm Exit?',
  887.    mtConfirmation,[mbYes,mbNo],0)=mrYes
  888.    then Action:=caFree
  889.    else Action:=caNone;
  890. end;
  891.  
  892. procedure TForm1.Button11Click(Sender: TObject);
  893. begin
  894.  Close;
  895. end;
  896.  
  897. procedure TForm1.ReplaceDialog1Find(Sender: TObject);
  898. begin
  899.  with Sender as TReplaceDialog do
  900.   while True do
  901.    begin
  902.     if Memo1.SelText <> FindText then
  903.     FindDialog1Find(Sender);
  904.     if Memo1.SelLength = 0 then Break;
  905.     Memo1.SelText:= ReplaceText;
  906.     if not (frReplaceAll in Options) then Break;
  907.    end;
  908. end;
  909.  
  910. procedure TForm1.Button3Click(Sender: TObject);
  911. begin
  912. _save();
  913. ShellExecute(Handle, nil, Pchar('compil.exe'), PChar(ExtractFileName(EditFile)),nil, Sw_ShowNormal);
  914. end;
  915.  
  916.  
  917.  
  918.  
  919.  
  920. procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
  921.   MousePos: TPoint; var Handled: Boolean);
  922. begin
  923. memo2.Perform(WM_VScroll, SB_LINEDOWN,0);
  924. memo1.Perform(WM_VScroll, SB_LINEDOWN,0);
  925. end;
  926.  
  927. procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
  928.   MousePos: TPoint; var Handled: Boolean);
  929. begin
  930. memo2.Perform(WM_VScroll, SB_LINEUP,0);
  931. memo1.Perform(WM_VScroll, SB_LINEUP,0);
  932. end;
  933.  
  934. end.
  935. ///editor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement