Execute a Markov algorithm: Difference between revisions
Content added Content deleted
m (→{{header|Pascal}}: cosmetic) |
m (→{{header|Pascal}}: some correction) |
||
Line 3,561: | Line 3,561: | ||
Terms := s.Split([' -> ']); |
Terms := s.Split([' -> ']); |
||
if Length(Terms) <> 2 then exit(False); |
if Length(Terms) <> 2 then exit(False); |
||
r.Pattern := Terms[0]. |
r.Pattern := Terms[0].Trim; |
||
r.Replacement := Terms[1].Trim; |
|||
r.Replacement := Terms[1].TrimLeft; |
|||
r.Terminating := False; |
r.Terminating := False; |
||
if (r.Replacement <> '') and (r.Replacement[1] = '.') then begin |
if (r.Replacement <> '') and (r.Replacement[1] = '.') then begin |
||
r.Terminating := True; |
r.Terminating := True; |
||
Delete(r.Replacement, 1, 1); |
Delete(r.Replacement, 1, 1); |
||
end; |
end; |
||
Result := True; |
Result := True; |
||
end; |
end; |
||
Line 3,602: | Line 3,601: | ||
repeat |
repeat |
||
Applied := False; |
Applied := False; |
||
for r in Rules do |
for r in Rules do begin |
||
if |
if r.Pattern = '' then begin |
||
Result := |
Result := r.Replacement + Result; |
||
⚫ | |||
end else begin |
|||
Applied := Result.IndexOf(r.Pattern) >= 0; |
|||
if Applied then |
|||
Result := Result.Replace(r.Pattern, r.Replacement); |
|||
end; |
|||
if Applied then begin |
|||
if r.Terminating then exit; |
if r.Terminating then exit; |
||
⚫ | |||
break; |
break; |
||
end; |
end; |
||
end; |
|||
until not Applied; |
until not Applied; |
||
end; |
end; |