Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //compil
- program compil;
- {$APPTYPE CONSOLE}
- //03.01.2015
- {
- 03.01.2015: mov add or and jmp int cmp not
- 16.01.2015: jme jmm jml jmn
- The End 26.02.2015
- }
- uses
- SysUtils,
- Classes,
- Windows;
- var _stack, stack_cmd:array[0..10000] of string;
- stack_param:array[0..3000, 0..1] of string;
- _ram, _var:array[0..9] of string;
- ram:array[0..1023] of integer;
- str:string;
- version:string='1.4r';
- date:string='03.01.2015';
- fb: array [1..320, 1..240] of byte;
- i, j, cmd, cmd_num:integer;
- stat:boolean=true;
- {function _cmd(numb:integer):boolean;
- begin
- 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;
- end; }
- function Is_int(val:string):boolean;
- begin
- val:=trim(val);
- if (StrToIntDef(val, 0) = 0) and (StrToIntDef(val, 1) = 1) then
- Is_int:=false
- else
- Is_int:=true;
- end;
- {
- //-----------------------------------------
- // Установка курсора в координаты X, Y
- //-----------------------------------------
- procedure GotoXY(X, Y: Integer);
- var
- c: _COORD;
- begin
- c.x:=X;
- c.y:=Y;
- SetConsoleCursorPosition(hndl,c);
- end;
- //--------------------------------------
- // Показываем/Скрываем курсор
- //--------------------------------------
- procedure ShowCursor(Show: Boolean);
- var
- CCI: _CONSOLE_CURSOR_INFO;
- begin
- CCI.bVisible := Show;
- SetConsoleCursorInfo(hndl, CCI);
- end; //Не работает. Когда нибудь пофиксить. } //Не используется
- //<Блок процедур, описывающих мнемокод>
- //------------------------------------------------------------------------------------------------
- procedure _mov(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- p2:=stack_param[n, 1];
- if (p2[1]='r') and (Is_int(p2[2])) then
- begin
- if (p1[1]='r') and (Is_int(p1[2])) then _ram[StrToInt(p2[2])]:=_ram[StrToInt(p1[2])]
- else if (p1[1]='v') and (Is_int(p1[2])) then _ram[StrToInt(p2[2])]:=_var[StrToInt(p1[2])]
- else _ram[StrToInt(p2[2])]:=p1;
- end
- else if (p2[1]='v') and (Is_int(p2[2])) then
- begin
- if (p1[1]='r') and (Is_int(p1[2])) then _var[StrToInt(p2[2])]:=_ram[StrToInt(p1[2])]
- else if (p1[1]='v') and (Is_int(p1[2])) then _var[StrToInt(p2[2])]:=_var[StrToInt(p1[2])]
- else _var[StrToInt(p2[2])]:=p1;
- end
- else
- begin
- writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end;
- end;
- //--------------------------------------------------------------------------------------------------
- procedure _add(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- p2:=stack_param[n, 1];
- if (p1[1]='r') and (Is_int(p1[2])) then
- begin
- if (p2[1]='r') and (Is_int(p1[2])) then
- if (Is_int(_ram[StrToInt(p2[2])])) and (Is_int(_ram[StrToInt(p1[2])])) then
- _ram[StrToInt(p1[2])]:=IntToStr(StrToInt(_ram[StrToInt(p1[2])])+StrToInt(_ram[StrToInt(p2[2])]))
- else
- _ram[StrToInt(p1[2])]:=_ram[StrToInt(p1[2])]+_ram[StrToInt(p2[2])]
- else if (p2[1]='v') and (Is_int(p2[2])) then
- if (Is_int(_var[StrToInt(p2[2])])) and (Is_int(_ram[StrToInt(p1[2])])) then
- _ram[StrToInt(p1[2])]:=IntToStr(StrToInt(_ram[StrToInt(p1[2])])+StrToInt(_var[StrToInt(p2[2])]))
- else
- _ram[StrToInt(p1[2])]:=_ram[StrToInt(p1[2])]+_var[StrToInt(p2[2])]
- else if (Is_int(p2)) and (Is_int(_ram[StrToInt(p1[2])])) then
- _ram[StrToInt(p1[2])]:=IntToStr(StrToInt(_ram[StrToInt(p1[2])])+StrToInt(p2))
- else
- _ram[StrToInt(p1[2])]:=_ram[StrToInt(p1[2])]+p2
- end
- else if (p1[1]='v') and (Is_int(p1[2])) then
- begin
- if (p2[1]='r') and (Is_int(p1[2])) then
- if (Is_int(_ram[StrToInt(p2[2])])) and (Is_int(_var[StrToInt(p1[2])])) then
- _var[StrToInt(p1[2])]:=IntToStr(StrToInt(_var[StrToInt(p1[2])])+StrToInt(_ram[StrToInt(p2[2])]))
- else
- _var[StrToInt(p1[2])]:=_var[StrToInt(p1[2])]+_ram[StrToInt(p2[2])]
- else if (p2[1]='v') and (Is_int(p2[2])) then
- if (Is_int(_var[StrToInt(p2[2])])) and (Is_int(_var[StrToInt(p1[2])])) then
- _var[StrToInt(p1[2])]:=IntToStr(StrToInt(_var[StrToInt(p1[2])])+StrToInt(_var[StrToInt(p2[2])]))
- else
- _var[StrToInt(p1[2])]:=_var[StrToInt(p1[2])]+_var[StrToInt(p2[2])]
- else if (Is_int(p2)) and (Is_int(_var[StrToInt(p1[2])])) then
- _var[StrToInt(p1[2])]:=IntToStr(StrToInt(_var[StrToInt(p1[2])])+StrToInt(p2))
- else
- _var[StrToInt(p1[2])]:=_var[StrToInt(p1[2])]+p2;
- end
- else
- writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end;
- //-----------------------------------------------------------------------------------------------------
- procedure _or(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- p2:=stack_param[n, 1];
- if (p1[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p1[2])]='true') or (_ram[StrToInt(p1[2])]='false')) then
- begin
- if (p2[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p2[2])]='true') or (_ram[StrToInt(p2[2])]='false')) then
- if (_ram[StrToInt(p1[2])]='true') or (_ram[StrToInt(p2[2])]='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- else if (p2[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p2[2])]='true') or (_var[StrToInt(p2[2])]='false')) then
- if (_ram[StrToInt(p1[2])]='true') or (_var[StrToInt(p2[2])]='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- else if (p2='true') or (p2='false') then
- if (_ram[StrToInt(p1[2])]='true') or (p2='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- end
- else if (p1[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p1[2])]='true') or (_var[StrToInt(p1[2])]='false')) then
- begin
- if (p2[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p2[2])]='true') or (_ram[StrToInt(p2[2])]='false')) then
- if (_var[StrToInt(p1[2])]='true') or (_ram[StrToInt(p2[2])]='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- else if (p2[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p2[2])]='true') or (_var[StrToInt(p2[2])]='false')) then
- if (_var[StrToInt(p1[2])]='true') or (_var[StrToInt(p2[2])]='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- else if (p2='true') or (p2='false') then
- if (_var[StrToInt(p1[2])]='true') or (p2='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- end
- else if ((p1='true') or (p1='false')) and ((p2='true') or (p2='false')) then
- begin
- if (p1='true') or (p2='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- end
- else
- writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end;
- //---------------------------------------------------------------------------------------------------
- procedure _and(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- p2:=stack_param[n, 1];
- if (p1[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p1[2])]='true') or (_ram[StrToInt(p1[2])]='false')) then
- begin
- if (p2[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p2[2])]='true') or (_ram[StrToInt(p2[2])]='false')) then
- if (_ram[StrToInt(p1[2])]='true') and (_ram[StrToInt(p2[2])]='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- else if (p2[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p2[2])]='true') or (_var[StrToInt(p2[2])]='false')) then
- if (_ram[StrToInt(p1[2])]='true') and (_var[StrToInt(p2[2])]='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- else if (p2='true') or (p2='false') then
- if (_ram[StrToInt(p1[2])]='true') and (p2='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- end
- else if (p1[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p1[2])]='true') or (_var[StrToInt(p1[2])]='false')) then
- begin
- if (p2[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p2[2])]='true') or (_ram[StrToInt(p2[2])]='false')) then
- if (_var[StrToInt(p1[2])]='true') and (_ram[StrToInt(p2[2])]='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- else if (p2[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p2[2])]='true') or (_var[StrToInt(p2[2])]='false')) then
- if (_var[StrToInt(p1[2])]='true') and (_var[StrToInt(p2[2])]='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- else if (p2='true') or (p2='false') then
- if (_var[StrToInt(p1[2])]='true') and (p2='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- end
- else if ((p1='true') or (p1='false')) and ((p2='true') or (p2='false')) then
- begin
- if (p1='true') and (p2='true') then
- _ram[0]:='true'
- else _ram[0]:='false'
- end
- else
- writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end;
- //--------------------------------------------------------------------------------------------
- procedure _jmp(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- cmd_num:=StrToInt(p1)-1;
- end;
- //--------------------------------------------------------------------------------------------
- procedure _int(n:integer);
- var p1, p2:string;
- _tmp:integer;
- Fil:TStringList;
- begin
- p1:=stack_param[n, 0];
- p2:=stack_param[n, 1];
- //------------------------- консоль ввод-вывод--------------------------------
- if p1='pnt' then
- begin
- if (p2[1]='r') and (Is_int(p2[2])) then writeln(_ram[StrToInt(p2[2])])
- else if (p2[1]='v') and (Is_int(p2[2])) then writeln(_var[StrToInt(p2[2])])
- else writeln(p2);
- end
- else if p1='in' then
- begin
- if (p2[1]='r') and (Is_int(p2[2])) then readln(_ram[StrToInt(p2[2])])
- else if (p2[1]='v') and (Is_int(p2[2])) then readln(_var[StrToInt(p2[2])])
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end
- //-----------------------------работа с диском--------------------------------
- else if p1='wdsk' then
- begin
- if Is_int(p2) then
- begin
- _tmp:=StrToInt(p2);
- if (_tmp>=0) and (_tmp<4095) and (Is_Int(_var[0])) then
- begin
- Fil:=TStringList.Create;
- Fil.LoadFromFile('disk');
- Fil.Strings[_tmp]:=_var[0];
- Fil.SaveToFile('disk');
- Fil.Free;
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
- end
- else if (p2[1]='r') and (Is_int(p2[2])) then
- begin
- _tmp:=StrToInt(p2[2]);
- if (_tmp>=0) and (_tmp<4095) and (Is_Int(_var[0])) then
- begin
- Fil:=TStringList.Create;
- Fil.LoadFromFile('disk');
- Fil.Strings[StrToInt(_ram[_tmp])]:=_var[0];
- Fil.SaveToFile('disk');
- Fil.Free;
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end
- else if p1='rdsk' then
- begin
- if Is_int(p2) then
- begin
- _tmp:=StrToInt(p2);
- if (_tmp>=0) and (_tmp<4095) then
- begin
- Fil:=TStringList.Create;
- Fil.LoadFromFile('disk');
- _var[0]:=Fil.Strings[_tmp];
- Fil.SaveToFile('disk');
- Fil.Free;
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
- end
- else if (p2[1]='r') and (Is_int(p2[2])) then
- begin
- _tmp:=StrToInt(p2[2]);
- if (_tmp>=0) and (_tmp<4095) then
- begin
- Fil:=TStringList.Create;
- Fil.LoadFromFile('disk');
- _var[0]:=Fil.Strings[StrToInt(_ram[_tmp])];
- Fil.SaveToFile('disk');
- Fil.Free;
- end
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end
- //------------------------Работа с ОЗУ----------------------------------------
- else if p1='wram' then
- begin
- if Is_int(p2) then
- begin
- _tmp:=StrToInt(p2);
- if (_tmp>=0) and (_tmp<1024) and (Is_Int(_ram[9])) then
- begin
- ram[_tmp]:=StrToInt(_ram[9]);
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
- end
- else if (p2[1]='r') and (Is_int(p2[2])) then
- begin
- _tmp:=StrToInt(p2[2]);
- if (_tmp>=0) and (_tmp<1024) and (Is_Int(_ram[9])) then
- begin
- ram[StrToInt(_ram[_tmp])]:=StrToInt(_ram[9]);
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end
- else if p1='rram' then
- begin
- if Is_int(p2) then
- begin
- _tmp:=StrToInt(p2);
- if (_tmp>=0) and (_tmp<1024) then
- begin
- _ram[9]:=IntToStr(ram[_tmp]);
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
- end
- else if (p2[1]='r') and (Is_int(p2[2])) then
- begin
- _tmp:=StrToInt(p2[2]);
- if (_tmp>=0) and (_tmp<1024) then
- begin
- _ram[9]:=IntToStr(ram[StrToInt(_ram[_tmp])]);
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)')
- end
- else writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end
- //----------------------------------------------------------------------------
- else
- writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end;
- //----------------------------------------------------------------------------------------------
- procedure _cmp(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- p2:=stack_param[n, 1];
- if (p1[1]='r') and (Is_int(p2[2])) then
- begin
- if (p2[1]='r') and (Is_int(p1[2])) then
- //-----int-----------
- if (is_int(_ram[StrToInt(p1[2])])) and (is_int(_ram[StrToInt(p2[2])])) then
- if StrToInt(_ram[StrToInt(p1[2])]) < StrToInt(_ram[StrToInt(p2[2])]) then
- _ram[0]:='-1'
- else if StrToInt(_ram[StrToInt(p1[2])]) = StrToInt(_ram[StrToInt(p2[2])]) then
- _ram[0]:='0'
- else if StrToInt(_ram[StrToInt(p1[2])]) > StrToInt(_ram[StrToInt(p2[2])]) then
- _ram[0]:='1'
- else if (p2[1]='v') and (Is_int(p1[2])) then
- if (is_int(_ram[StrToInt(p1[2])])) and (is_int(_var[StrToInt(p2[2])])) then
- if StrToInt(_ram[StrToInt(p1[2])]) < StrToInt(_var[StrToInt(p2[2])]) then
- _ram[0]:='-1'
- else if StrToInt(_ram[StrToInt(p1[2])]) = StrToInt(_var[StrToInt(p2[2])]) then
- _ram[0]:='0'
- else if StrToInt(_ram[StrToInt(p1[2])]) > StrToInt(_var[StrToInt(p2[2])]) then
- _ram[0]:='1'
- else
- if (is_int(_ram[StrToInt(p1[2])])) and (is_int(p2)) then
- if StrToInt(_ram[StrToInt(p1[2])]) < StrToInt(p2) then
- _ram[0]:='-1'
- else if StrToInt(_ram[StrToInt(p1[2])]) = StrToInt(p2) then
- _ram[0]:='0'
- else if StrToInt(_ram[StrToInt(p1[2])]) > StrToInt(p2) then
- _ram[0]:='1'
- //-------/int--------------
- //------str----------------
- else if (not is_int(_ram[StrToInt(p1[2])])) and (not is_int(_ram[StrToInt(p2[2])])) then
- if length(_ram[StrToInt(p1[2])]) < length(_ram[StrToInt(p2[2])]) then
- _ram[0]:='-1'
- else if length(_ram[StrToInt(p1[2])]) = length(_ram[StrToInt(p2[2])]) then
- if _ram[StrToInt(p1[2])]= _ram[StrToInt(p2[2])] then
- _ram[0]:='0'
- else
- _ram[0]:='-0'
- else if length(_ram[StrToInt(p1[2])]) > length(_ram[StrToInt(p2[2])]) then
- _ram[0]:='1'
- else if (p2[1]='v') and (Is_int(p1[2])) then
- if (not is_int(_ram[StrToInt(p1[2])])) and (not is_int(_var[StrToInt(p2[2])])) then
- if length(_ram[StrToInt(p1[2])]) < length(_var[StrToInt(p2[2])]) then
- _ram[0]:='-1'
- else if length(_ram[StrToInt(p1[2])]) = length(_var[StrToInt(p2[2])]) then
- if _ram[StrToInt(p1[2])]=_var[StrToInt(p2[2])] then
- _ram[0]:='0'
- else
- _ram[0]:='-0'
- else if length(_ram[StrToInt(p1[2])]) > length(_var[StrToInt(p2[2])]) then
- _ram[0]:='1'
- else
- if (not is_int(_ram[StrToInt(p1[2])])) and (not is_int(p2)) then
- if length(_ram[StrToInt(p1[2])]) < length(p2) then
- if _ram[StrToInt(p1[2])]=p2 then
- _ram[0]:='-1'
- else if length(_ram[StrToInt(p1[2])]) = length(p2) then
- if _ram[StrToInt(p1[2])]=p2 then
- _ram[0]:='0'
- else
- _ram[0]:='-0'
- else if length(_ram[StrToInt(p1[2])]) > length(p2) then
- _ram[0]:='1'
- //-----/str----------------
- end
- else if (p1[1]='v') and (Is_int(p2[2])) then
- begin
- if (p2[1]='r') and (Is_int(p1[2])) then
- if (is_int(_var[StrToInt(p1[2])])) and (is_int(_ram[StrToInt(p2[2])])) then
- if StrToInt(_var[StrToInt(p1[2])]) < StrToInt(_ram[StrToInt(p2[2])]) then
- _ram[0]:='-1'
- else if StrToInt(_var[StrToInt(p1[2])]) = StrToInt(_ram[StrToInt(p2[2])]) then
- _ram[0]:='0'
- else if StrToInt(_var[StrToInt(p1[2])]) > StrToInt(_ram[StrToInt(p2[2])]) then
- _ram[0]:='1'
- else if (p2[1]='v') and (Is_int(p1[2]))then
- if (is_int(_var[StrToInt(p1[2])])) and (is_int(_var[StrToInt(p2[2])])) then
- if StrToInt(_var[StrToInt(p1[2])]) < StrToInt(_var[StrToInt(p2[2])]) then
- _ram[0]:='-1'
- else if StrToInt(_var[StrToInt(p1[2])]) = StrToInt(_var[StrToInt(p2[2])]) then
- _ram[0]:='0'
- else if StrToInt(_var[StrToInt(p1[2])]) > StrToInt(_var[StrToInt(p2[2])]) then
- _ram[0]:='1'
- else
- if (is_int(_var[StrToInt(p1[2])])) and (is_int(p2)) then
- if StrToInt(_var[StrToInt(p1[2])]) < StrToInt(p2) then
- _ram[0]:='-1'
- else if StrToInt(_var[StrToInt(p1[2])]) = StrToInt(p2) then
- _ram[0]:='0'
- else if StrToInt(_var[StrToInt(p1[2])]) > StrToInt(p2) then
- _ram[0]:='1'
- end
- else if p1=p2 then
- _ram[0]:='true'
- else
- _ram[0]:='false';
- end;
- //----------------------------------------------------------------------------------------------
- procedure _not(n:integer);
- var p1:string;
- begin
- p1:=stack_param[n, 0];
- if (p1[1]='r') and (Is_int(p1[2])) and ((_ram[StrToInt(p1[2])]='true') or (_ram[StrToInt(p1[2])]='false')) then
- begin
- if _ram[StrToInt(p1[2])]='true' then
- _ram[StrToInt(p1[2])]:='false'
- else _ram[StrToInt(p1[2])]:='true'
- end
- else if (p1[1]='v') and (Is_int(p1[2])) and ((_var[StrToInt(p1[2])]='true') or (_var[StrToInt(p1[2])]='false')) then
- begin
- if _var[StrToInt(p1[2])]='true' then
- _var[StrToInt(p1[2])]:='false'
- else _var[StrToInt(p1[2])]:='true'
- end
- else
- writeln('Err '+IntToStr(n)+' : Invalid argument(s)');
- end;
- //----------------------------------------------------------------------------------------------
- procedure _jme(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- if _ram[0]='0' then cmd_num:=StrToInt(p1)-1;
- end;
- //----------------------------------------------------------------------------------------------
- procedure _jmm(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- if _ram[0]='1' then cmd_num:=StrToInt(p1)-1;
- end;
- //----------------------------------------------------------------------------------------------
- procedure _jml(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- if _ram[0]='-1' then cmd_num:=StrToInt(p1)-1;
- end;
- //----------------------------------------------------------------------------------------------
- procedure _jmn(n:integer);
- var p1, p2:string;
- begin
- p1:=stack_param[n, 0];
- if _ram[0]='-0' then cmd_num:=StrToInt(p1)-1;
- end;
- //----------------------------------------------------------------------------------------------
- //</Блок процедур, описывающих мнемокод>
- procedure inter();
- var _stat:boolean;
- begin
- _stat:=true;
- cmd_num:=0;
- while _stat do
- begin
- if (stack_cmd[cmd_num]='') or (stack_cmd[cmd_num]=' ') or (cmd_num>=99) then
- _stat:=false
- //
- else if stack_cmd[cmd_num]='mov' then
- begin
- _mov(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='add' then
- begin
- _add(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='jmp' then
- begin
- _jmp(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='or' then
- begin
- _or(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='and' then
- begin
- _and(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='jme' then
- begin
- _jme(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='jml' then
- begin
- _jme(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='jmm' then
- begin
- _jme(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='jmn' then
- begin
- _jme(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='cmp' then
- begin
- _cmp(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='not' then
- begin
- _not(cmd_num);
- cmd_num:=cmd_num+1;
- end
- //
- else if stack_cmd[cmd_num]='int' then
- begin
- _int(cmd_num);
- cmd_num:=cmd_num+1;
- end;
- end;
- end;
- procedure parser(str_in:string);
- begin
- stat:=true;
- str_in:=trim(str_in);
- if str='date' then writeln(date) else if length(str_in)>0 then
- begin
- j:=0;
- 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;
- j:=0;
- i:=0;
- cmd:=0;
- while stat do
- begin
- if _stack[i]='' then begin
- stat:=false;
- end
- else
- 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
- begin
- stack_cmd[cmd]:=_stack[i];
- stack_param[cmd, 0]:= _stack[i+1];
- stack_param[cmd, 1]:= _stack[i+2];
- i:=i+3;
- cmd:=cmd+1;
- 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
- begin
- stack_cmd[cmd]:=_stack[i];
- stack_param[cmd, 0]:= _stack[i+1];
- i:=i+2;
- cmd:=cmd+1;
- end else begin
- writeln('Expected mnemonic | invalid command:'+IntToStr(i));
- stat:=false;
- end;
- end;
- end;
- inter();
- end;
- //------------------------------------------------------------------------------
- procedure _file();
- var f:TextFile;
- text, tmp:string;
- begin
- assignFile(f, paramStr(1));
- Reset(f);
- while (not EOF(f)) do
- begin
- Readln(f, tmp);
- text:=text+' '+tmp;
- tmp:='';
- end;
- parser(text);
- end;
- //-----------------------------------------------------------------------------------
- var _stat:boolean;
- begin
- if ParamStr(1) <>'' then _file();
- while true do
- begin
- write('G_asm v.'+version+': ');
- readln(str);
- parser(str);
- end;
- end.
- ///compil
- //editor
- unit Dl;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtDlgs, StdCtrls, ExtCtrls, Jpeg, Printers, ShellApi;
- type
- TForm1 = class(TForm)
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- OpenPictureDialog1: TOpenPictureDialog;
- SavePictureDialog1: TSavePictureDialog;
- FontDialog1: TFontDialog;
- ColorDialog1: TColorDialog;
- PrintDialog1: TPrintDialog;
- PrinterSetupDialog1: TPrinterSetupDialog;
- FindDialog1: TFindDialog;
- ReplaceDialog1: TReplaceDialog;
- Button1: TButton;
- Memo1: TMemo;
- Button2: TButton;
- Button5: TButton;
- Button7: TButton;
- Button9: TButton;
- Button11: TButton;
- Button12: TButton;
- Button14: TButton;
- Button3: TButton;
- Memo2: TMemo;
- procedure Button1Click(Sender: TObject);
- procedure Button11Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button5Click(Sender: TObject);
- procedure Button6Click(Sender: TObject);
- procedure Button7Click(Sender: TObject);
- procedure Button9Click(Sender: TObject);
- procedure Button10Click(Sender: TObject);
- procedure FindDialog1Find(Sender: TObject);
- procedure Button8Click(Sender: TObject);
- procedure Button12Click(Sender: TObject);
- procedure Button13Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Button14Click(Sender: TObject);
- procedure ReplaceDialog1Replace(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure ReplaceDialog1Find(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
- MousePos: TPoint; var Handled: Boolean);
- procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
- MousePos: TPoint; var Handled: Boolean);
- private
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- EditFile: string;
- version:string='1.4r';
- implementation
- {$R *.DFM}
- procedure TForm1.Button12Click(Sender: TObject);
- begin
- Memo1.Lines.Clear;
- Memo1.Font.Size:=8;
- Memo1.Font.Color:=clWindowText;
- Memo1.Color:=clWindow;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- if OpenDialog1.Execute then
- begin
- EditFile:=OpenDialog1.FileName;
- Memo1.Lines.LoadFromFile(EditFile);
- Form1.Caption:='Compil_Editor ' +version+ ' - '+ExtractFileName(EditFile);
- end;
- end;
- procedure _save();
- begin
- //if SaveDialog1.Execute then
- Form1.Memo1.Lines.SaveToFile(EditFile);//запись на прямую в файл
- if Form1.Memo1.Modified then Form1.Memo1.Modified:=false;
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- _save();
- end;
- procedure TForm1.Button14Click(Sender: TObject);
- begin
- if SaveDialog1.Execute then//запись в файл + диалоговое оконо
- begin
- EditFile:=SaveDialog1.FileName;
- Memo1.Lines.SaveToFile(EditFile);
- Form1.Caption:='Compil_Editor ' +version+ '- '+ExtractFileName(EditFile);
- if Memo1.Modified then Memo1.Modified:=false;
- end;
- end;
- procedure TForm1.Button5Click(Sender: TObject);
- begin
- if FontDialog1.Execute then Memo1.Font:=FontDialog1.Font;
- end;
- procedure TForm1.Button6Click(Sender: TObject);
- begin
- if ColorDialog1.Execute then Memo1.Font.Color:=ColorDialog1.Color;
- end;
- procedure TForm1.Button13Click(Sender: TObject);
- begin
- if ColorDialog1.Execute then Memo1.Color:=ColorDialog1.Color;
- end;
- procedure TForm1.Button7Click(Sender: TObject);
- var
- Stroka:System.TextFile;
- i:integer;
- begin
- if PrintDialog1.Execute then
- begin
- AssignPrn(Stroka);
- Rewrite(Stroka);
- Printer.Canvas.Font:=Memo1.Font;
- for i:=0 to Memo1.Lines.Count-1 do
- Writeln(Stroka,Memo1.Lines[i]);
- System.CloseFile(Stroka);
- end;
- end;
- procedure TForm1.Button8Click(Sender: TObject);
- begin
- PrinterSetupDialog1.Execute;
- end;
- procedure TForm1.Button9Click(Sender: TObject);
- begin
- FindDialog1.Execute;
- end;
- procedure TForm1.Button10Click(Sender: TObject);
- begin
- ReplaceDialog1.Execute;
- end;
- procedure TForm1.FindDialog1Find(Sender: TObject);
- {begin
- //ищется первое появление строки
- if pos(FindDialog1.FindText,Memo1.Text)<>0 then
- begin
- Memo1.HideSelection:=false;
- Memo1.SelStart:=pos(FindDialog1.FindText,Memo1.Text)-1;
- Memo1.SelLength:=Length(FindDialog1.FindText);
- end
- else
- MessageDlg('String '+FindDialog1.FindText+' not found!',mtConfirmation,[mbYes],0);}
- var
- Buff,P,FT: PChar;
- BuffLen: Word;
- begin
- with Sender as TFindDialog do
- begin
- GetMem(FT, Length(FindText) + 1);
- StrPCopy(FT, FindText);
- BuffLen:= Memo1.GetTextLen + 1;
- GetMem(Buff, BuffLen);
- Memo1.GetTextBuf(Buff, BuffLen);
- P:= Buff + Memo1.SelStart + Memo1.SelLength;
- P:= StrPos(P, FT);
- if P=nil then MessageBeep(0)
- else
- begin
- Memo1.SelStart:= P - Buff;
- Memo1.SelLength:= Length(FindText);
- end;
- FreeMem(FT, Length(FindText) + 1);
- FreeMem(Buff, BuffLen);
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- var i:integer;
- begin
- EditFile:='Noname.txt';
- Form1.Caption:='Compil_Editor ' +version+ ' - '+ExtractFileName(EditFile);
- for i:=0 to 1000 do Form1.Memo2.Lines.Add(IntToStr(i));
- for i:=0 to 1000 do Form1.Memo1.Lines.Add('');
- end;
- procedure TForm1.ReplaceDialog1Replace(Sender: TObject);
- label 10;//метка
- begin
- Memo1.HideSelection:=true;
- 10://метка
- if pos(ReplaceDialog1.FindText,Memo1.Text)<>0 then
- begin
- Memo1.SelStart:=pos(ReplaceDialog1.FindText,Memo1.Text)-1;
- Memo1.SelLength:=Length(ReplaceDialog1.FindText);
- Memo1.SelText:=ReplaceDialog1.ReplaceText;
- goto 10;
- end;
- Memo1.HideSelection:=false;
- end;
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- if Memo1.Modified then
- if MessageDlg('File '+ExtractFileName(EditFile)+' changed'+#10#13'Confirm Exit?',
- mtConfirmation,[mbYes,mbNo],0)=mrYes
- then Action:=caFree
- else Action:=caNone;
- end;
- procedure TForm1.Button11Click(Sender: TObject);
- begin
- Close;
- end;
- procedure TForm1.ReplaceDialog1Find(Sender: TObject);
- begin
- with Sender as TReplaceDialog do
- while True do
- begin
- if Memo1.SelText <> FindText then
- FindDialog1Find(Sender);
- if Memo1.SelLength = 0 then Break;
- Memo1.SelText:= ReplaceText;
- if not (frReplaceAll in Options) then Break;
- end;
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- _save();
- ShellExecute(Handle, nil, Pchar('compil.exe'), PChar(ExtractFileName(EditFile)),nil, Sw_ShowNormal);
- end;
- procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
- MousePos: TPoint; var Handled: Boolean);
- begin
- memo2.Perform(WM_VScroll, SB_LINEDOWN,0);
- memo1.Perform(WM_VScroll, SB_LINEDOWN,0);
- end;
- procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
- MousePos: TPoint; var Handled: Boolean);
- begin
- memo2.Perform(WM_VScroll, SB_LINEUP,0);
- memo1.Perform(WM_VScroll, SB_LINEUP,0);
- end;
- end.
- ///editor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement