Autor Beitrag
Pscore
Hält's aus hier
Beiträge: 14



BeitragVerfasst: Do 29.09.05 13:56 
Unit 1:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, unit2, baseclss;

type
  TForm1 = class(TForm)
    Therm: TEdit;
    check: TButton;
    y: TLabel;
    Ergebnis: TLabel;
    Label1: TLabel;
    procedure checkClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Keller: TLifo;

implementation

{$R *.dfm}

procedure TForm1.checkClick(Sender: TObject);
var x:string;
    i:integer;
    fehler:boolean;
begin
Keller:=Tlifo.create;
fehler:=false;
I:=1;
x:=therm.Text;
while (i<=length(x)) and not fehler do
begin
if x[i] in ['(', '[', '{'] then Keller.push(Tchar.create(x[i]))
else
case x[i] of
')': if Tchar(top).getvalue<>'(' then fehler:=true;
']': if Tchar(top).getvalue<>'[' then fehler:=true;
'}': if Tchar(top).getvalue<>'{' then fehler:=true;
end;
I:=I+1;
end;
if not fehler and Keller.empty then label1.Caption:='richtig' else label1.caption:='fehler';
end;
end.


Unit2:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
unit Unit2;

interface
uses Baseclss;
Type
Tlifonode = class(TBase)
            Constructor Create(tb:TBase);
            Destructor destroy; OVerride;

            Private
            value:TBase;
            next:Tlifonode;
end;

TLifo = Class(TBase)
        Constructor Create;
        Destructor Destroy;
        function empty:boolean;
        function top:TBase;
        procedure push(tb:TBase);
        procedure pop;
        private
        current:Tlifonode;
end;

implementation

Constructor TLifonode.Create(tb:TBase);
begin
Value:=tb;
next:=NIL
end;

Destructor Tlifonode.destroy;
begin
if not (value=NIL) then
value.destroy
end;

Constructor Tlifo.create;
begin
current:=NIL;
end;

Function TLifo.empty:boolean;
begin
result:=current=NIL;
end;


function Tlifo.top:TBase;
begin
result:=current.value;
end;

Procedure Tlifo.push(tb:TBase);
var temp:Tlifonode;
begin
temp:=Tlifonode.create(tb);
temp.next:=current;
current:=temp;

end;

Procedure Tlifo.pop;
var temp:Tlifonode;
begin
temp:=current.next;
current.destroy;
current:=temp;
end;

Destructor Tlifo.Destroy;
begin
while not empty do pop;
end;

end.


baseclss:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
unit baseclss;

interface
uses classes;

Type
TBase = Class
  Procedure writeValue;Virtual;Abstract;
  function compare(tb:TBase):integer;Virtual;Abstract;
  function copy:Tbase;virtual;abstract;
    end;


TChar = Class(Tbase)
        Value:Char;
        Constructor create(v:char);
        function getvalue:char;
        end;

Implementation

Constructor TChar.Create(v:char);
begin
value:=v;
end;

Function Tchar.getvalue: char;
begin
result:=value;
end;


end.


Project2:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
program Project2;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas',
  baseclss in 'baseclss.pas';

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.



Hallo,
oben ist der Quellcode für einen lifo der Klammersetzung Prüft, allerdings funktioniert es noch nicht so ganz.
Es tritt immer ein fehler auf sobald das Programm auf eine Klammer zu trifft.Was schafft da abhilfe?
Danke für eure Hilfe.

Moderiert von user profile iconKlabautermann: Code- durch Delphi-Tags ersetzt