AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

String nach bestimmten muster auflösen

Ein Thema von Overphil · begonnen am 19. Okt 2015 · letzter Beitrag vom 20. Okt 2015
 
Dejan Vu
(Gast)

n/a Beiträge
 
#8

AW: String nach bestimmten muster auflösen

  Alt 20. Okt 2015, 06:30
Hier mal Pseudocode.
Delphi-Quellcode:
procedure Parse;
begin
  While GetNextCommand(command) do
    Execute(command);
end;

Function GetNextCommand(var cmd : TCommand) : Boolean;
var
  c : Char;

Begin
   if AtEof Then Exit(False)
   c := TakeChar;
   if c=')then Exit(False);
   if not (c in allowedCommands) then raise Exception.Create('Invalid command');
   cmd := TCommand.Create;
   cmd.Command := c;
   cmd.Value := TakeNumber;
   if (cmd.Command = RepeatCmd) then
     if TakeChar<>'(then Raise Exception.Create('Expected "("')
   result := True;
End;

Procedure Execute (aCmd : TCommand);
Begin
  case aCmd.Command of
    RepeatCmd : Parse;
    ForwardCmd : GoForward (aCmd.Value);
    RightCmd : TurnRight(aCmd.Value);
    ...
  end
end;

Function AtEof : Boolean;
Begin
  result := CurrentPtr>Length(InputString);
End;

Function TakeChar : Char;
Begin
  result := InputString[CurrentPtr];
  inc(CurrentPtr);
End;

Function TakeNumber : Integer;
Var
  p : Integer;

Begin
  p := CurrentPtr;
  While TakeChar in Digits and Not AtEof;
  if p=CurrentPtr then Raise Exception.Create('Not a number');
  result := StrToInt(Copy(InputString,p,CurrentPtr-p));
end;

Procedure Run (aString : String);
Begin
  InputString := aString;
  CurrentPtr := 1;
  Parse;
End;
Ganz grob skizziert.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:23 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz