Wascal IDE
 
Pas2Php
 
Geep Software
 
Buzz PHP
 
Code Library
 
Contacts
 
Credits
 

PAS2PHP v0.8 - Pascal to PHP Transpiler

Wikipedia: What is a Transpiler?

 About Test Examples Pas2Php Library Downloads 

Examples (Code Conversion Tests)

The following are Pascal conversion tests. I will be adding more test here which are used to not only demo the conversion quality, but also detect bugs.

Example #1 - Times Table (Nested For/Do + If/Then)
012345678910
112345678910
22468101214161820
336912151821242730
4481216202428323640
55101520253035404550
Example #2 - Basic Math

10 div 3 = "3"

10 / 3 = "3.3333333333333"

1 + 2 * 3 - 5 = "2"

Power(2, 3) = "8"

Ceil(2.5) = "3"

Floor(-2.5) = "-3"

Trunc(-2.5) = "-2"

Pred(100) = "99"

Succ(100) = "101"

Example #3 - Repeat/Until

All Numbers 1-10: [1][2][3][4][5][6][7][8][9][10]

Even Numbers 1-10: [2][4][6][8][10]

Odd Numbers 1-10: [1][3][5][7][9]

Example #4 - While/Do

Numbers 0-19: [0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19]

Example #5 - Case/Of

One | Two | Three | Four | Else, Lets | Rock!

Example #6 - Iterate String using For/Do

String = "Lazarus Rocks!"

Length = "14"

(L)(a)(z)(a)(r)(u)(s)( )(R)(o)(c)(k)(s)(!)

Example #7 - Variant Arrays

Create an array of Variants [10, 20, 30, 40, 50]

Iterate and Display Each Item

[10][20][30][40][50]

Reduce Length to 3

[10][20][30]

Increase Length to 4

[10][20][30][]

Set Last Value to 123

[10][20][30][123]

Example #8 - String & Char Functions

String = "Pascal is the BEST!"

Pos('P', LStr) = "1"

Pos('S', LStr) = "17"

Pos('a', LStr) = "2"

RPos('a', LStr) = "5"

RPos('%', LStr) = "0"

Pos('is', LStr) = "8"

Pos('z', LStr) = "0"

Ord('A') = "65"

Char(33) = "!"

Pred('C') = "B"

Succ('C') = "D"

Example #9 - Enum Constants

Apple, Orange, Pear, Pineapple.

Example #10 - Records

Name: Roamin Bob

Address: Wherever he lays his hat

Example #10 - Exceptions

Try/Finally (without Exception)

>>> Finally

Try/Finally (with Exception)

>>> Finally

>>> Except

Try/Except (without Exception)

Try/Except (with Exception)

>>> Except

Example #12 - String Values Extract using Pos/Copy

String = "This,Is,A,CSV,String"

Extracted Values = ["This"]["Is"]["A"]["CSV"]["String"]

String = ""

Extracted Values = [""]

String = ","

Extracted Values = [""][""]

String = "Apple,,Orange"

Extracted Values = ["Apple"][""]["Orange"]

Example #13 - String Replace

String = "Today was a $(value) day."

Today was a great day.

Today was a windy day.

Today was a sunny day.

Today was a long day.

Example #14 - Filename Functions

Filename = "/home/wascalne/public_html/toto.dog"

IncludeTrailingPathDelimiter = "/home/wascalne/public_html/toto.dog/"

ExtractFileDir = "/home/wascalne/public_html"

ExtractFilePath = "/home/wascalne/public_html/"

ExtractFileName = "toto.dog"

ChangeFileExt to ".cat" = "/home/wascalne/public_html/toto.cat"

ChangeFileExt to "" = "/home/wascalne/public_html/toto"

Example #15 - String Resizing

String = "Lazarus + Pascal"

SetLength(7) = "Lazarus"

SetLength(10) = "Lazarus!!!"

* Note: Spaces are replaced with "!".

Example #16 - Component Tree (based on CComponent)
    - [Value="Root" Count="4"]
      - [Value="David" Count="1"]
        - [Value="Apple" Count="0"]
      - [Value="Betty" Count="1"]
        - [Value="Orange" Count="0"]
      - [Value="Susan" Count="1"]
        - [Value="Pear" Count="0"]
      - [Value="Chris" Count="1"]
        - [Value="Grape" Count="0"]
Example #17 - 2 Dimension String Array
c0,r0 c1,r0 c2,r0 c3,r0 c4,r0
c0,r1 c1,r1 c2,r1 c3,r1 c4,r1
c0,r2 c1,r2 c2,r2 c3,r2 c4,r2
c0,r3 c1,r3 c2,r3 c3,r3 c4,r3
c0,r4 c1,r4 c2,r4 c3,r4 c4,r4
Example #18 - 2 Dimension Integer Array
0 0 0 0 0
0 1 2 3 4
0 2 4 6 8
0 3 6 9 12
0 4 8 12 16
Example #19 - Array of String (1 Dimension)
Apple = [A][p][p][l][e]
Orange = [O][r][a][n][g][e]
Pear = [P][e][a][r]
Grape = [G][r][a][p][e]

Geep Software License

Geep software is designed to be free/easy and fun to use. But, as with all software, please note that this software is provided "AS IS" and without warranty of any kind. (Read Below for more information.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright (C) 2014 Derek John Evans
http://www.wascal.net/

Top Downloads
Wascal IDE v1.0.4
PAS2PHP v0.8
Lazbro v0.4

Geep Software Downloads
Wallpaper Manager
Second Copy

Programming Tools
Wascal IDE
Lazarus IDE
Free Pascal
NSSM - Service Manager

Pascal API's
Indy (Internet Direct)
Jedi Code Format
RemObjects Pascal Script
SynEdit

JavaScript API's
Dynarch Calendar
TinyMCE
CKEditor

Audio/Video Tools
Reaper
ASIO4ALL
Lame MP3 Encoder
FFmpeg