RIL DelphiToPHP Converter
Under development
RIL DelphiToPHP Converter is for Pascal programmers, like me, who wants to reuse some algorithms in PHP scripts.
Now the Internet doesn't seem to be littered with Pascal to PHP converters, so therefore I made one. Well, the first version supports conversion of only basic Pascal syntax. In my solution I extended the work of others by using a converter from Pascal to C++ named delphitocpp, and from the result of this converter (C++) I go on to convert the C++ code into ready to run PHP script.
Method signatures littered with unknown types (unknown to both PHP and to Delphi btw) may need to be listed in a config file so that the converter can strip such things out of the code. But except for that, this Pascal to PHP converter should be able to do much trivial work, with need for no or little manual correction.
The amount of work needed to "manually postprocess" the PHP code to make it doing exactly the same thing as the original Pascal code, will of course be determined by how well the original code complies with the PHP-way of doing things. But the point is, you may get up to 90%+ of the conversion job done for low level code, at the click of a button.
- Original Delphi Pascal code
Small example code (sharp) which was 100% converted with the RIL DelphiToPHP Converter:
-
unit SomeParser; -
-
//... -
-
function FindClosingBracket(const S: String; StartPos: Integer; MaxBrackCnt:Byte; out
-
FoundPos:Integer; out FoundBrackCnt: Integer): Boolean; -
// -
// Description: Look up double square brackets ']]', or only a single bracket -
// ']', which is enforced if MaxBracktCnt is set to = 1. -
// The FoundPos and FoundBracketCnt values are undefined if the -
// function returns false (thus, do not attempt read/used them). -
// FromPos : Position to start searching from. -
// MaxBrackCnt: If for certain there's no more than one bracket at where from -
// the call is made, then the result must not exceed 1, regardless. -
// FoundPos: Position when a matching closing Brack was found. -
// FoundBrackCnt: Number of found brackets that fit the conditions. -
// -
var -
i, Brack: Integer; -
begin -
Result := false; -
Brack := 1; -
-
// Only lookbehind is allowed -
for i := StartPos+1 to Length(S) do -
begin -
if S[i]='[' then -
Inc(Brack) -
-
else if S[i]=']' then begin -
Dec(Brack); -
if Brack=0 then -
begin -
FoundPos := i; // We already found it, but we may still adjust it ... -
FoundBrackCnt := 1; -
if (MaxBrackCnt = 2) and (S[i-1]=']') then begin {MaxBrackCnt = 2 } -
FoundPos := i-1; -
FoundBrackCnt := 2; -
end; -
Result := True; -
Break; -
end; -
end; -
end; -
end; {FindClosingBracket}
-
-
end.
- And here's the 100% automatically converted PHP code
-
function FindClosingBracket( &$S, $StartPos, $MaxBrackCnt, &$FoundPos, &$FoundBrackCnt) -
//# -
//# Description: Look up double square brackets ']]', or only a single bracket -
//# ']', which is enforced if MaxBracktCnt is set to = 1. -
//# The FoundPos and FoundBracketCnt values are undefined if the -
//# function returns false (thus, do not attempt read/used them). -
//# FromPos : Position to start searching from. -
//# MaxBrackCnt: If for certain there's no more than one bracket at where from -
//# the call is made, then the result must not exceed 1, regardless. -
//# FoundPos: Position when a matching closing Brack was found. -
//# FoundBrackCnt: Number of found brackets that fit the conditions. -
//# -
{ /**$result;**/ -
/**$i;**/ /**$Brack;**/ -
-
$result = false; -
$Brack = 1; -
-
//# Only lookbehind is allowed -
{ $i_end = strLen( $S )+1 ; -
for( $i = $StartPos+1 ; $i < $i_end ; $i++ ) -
{ -
if( $S[$i]=="[" ) -
$Brack++; -
else if( $S[$i]=="]" ) { -
$Brack--; -
if( $Brack==0 ) -
{ -
$FoundPos = $i; //# We already found it, but we may still adjust it ... -
$FoundBrackCnt = 1; -
if( ( $MaxBrackCnt == 2 ) && ( $S[ $i-1 ]=="]" ) ) { /*$MaxBrackCnt = 2 */ -
$FoundPos = $i-1; -
$FoundBrackCnt = 2; -
} -
$result = true; -
break; -
} -
} -
}} -
return $result; -
} /*FindClosingBracket*/
:::: Parsed using GeSHi 1.0.8 ::::
To be continued.

