Mantixd,
Cita:
Empezado por Mantixd
...quiero hacer un tipo Analizador Léxico digamos que en ensamblador, tengo un Arreglo donde tengo los registros y quiero que al escribir código fuente en un Memo y presionar un botón buscar me compare los datos del arreglo con los escritos en el Memo...
|
Revisa este código:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
ListBox1: TListBox;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
public
end;
const
RegAsm : Array[1..30] of string = ('AX','BX','CX','DX','AH','AL',
'BH','BL','BP','CH','CL','CS',
'DH','DL','DI','DS', 'GS', 'IP',
'SI','SP','SS', 'ES',
'EAX','EBP','EBX','ECX',
'EDI','EDX','EIP','ESIFE');
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
SL: TStringList;
i, j, k : Integer;
Token : String;
AuxStr : String;
begin
SL := TStringList.Create;
ListBox1.Clear;
for i := 0 to Memo1.Lines.Count - 1 do
begin
AuxStr := Memo1.Lines[i];
for j := 1 to Length(AuxStr) do
begin
if (AuxStr[j] <> ' ') and (AuxStr[j] <> ',') then
Token := Token + AuxStr[j]
else
begin
SL.Add(Token);
Token := EmptyStr;
end
end;
SL.Add(Token);
Token := EmptyStr;
for j := 0 to SL.Count - 1 do
for k := Low(RegAsm) to High(RegAsm) do
if UpperCase(SL[j]) = UpperCase(RegAsm[k]) then
ListBox1.Items.Add(UpperCase(RegAsm[k]));
SL.Clear;
end;
SL.Free;
end;
end.
El código anterior,
analiza el código fuente de un programa en Assembler como input en un TMemo en base a un arreglo de registros en Assembler y si hay ocurrencias coloca dichos registros en un TListBox, como se muestra en la siguiente imagen:
Espero sea útil
Nelson.