PHP Language and C++

Started by Elias Montoya, April 15, 2010, 01:11:21 AM

Previous topic - Next topic

Elias Montoya

 I started playing with converting basic code to php and C++ on monday.

I created a small Powerbasic parser to convert basic code to php.
It works amazingly good! i have implemented several commands in my converter,
for example, this is a test script converted by my converter from BASIC code
to PHP:

if ($eli = 2.5) // Test comment
{
$s3++; // Test comment
$s3++; // Test comment
}
else // Test comment
{
$s3--; // Test comment
} // Test

switch ($infierno) // Test comment
{
case "2":
for ($Index=1; $Index<100; $Index+-1) // Test comment
{
} // Test comment
break;
case "3": // Test comment
for ($Index=1; $Index<100; $Index+-1)
{
if (!$index = 25)
{
break; // Test comment
$myvariable = date("H:i:s", time()); // Test comment
$myvariable = "  $DATE"; // Test comment
} // Test comment
}
break;
case "4":
$got = $thisisalabel; // Test comment
break;
} // Test comment END SELECT

if (!$correct) // Test comment
{
$text = "Some text " . $concatenate . ($hola) . "!" // Test comment
        . "This is a second text line."
        . "This is a THIRD text line.";
}

$a = ($b5 * 3)+$hj;

$ip = $_COOKIE["Nombre" . ($test . "421")];
$ip = $_COOKIE["Nombre" . ($test . "421")];

if ($a)
{
echo "Hi mom";
}
if ($a)
{
$a = $sthen + 1;
}
else
{
$a = $a + 3 || $b;
}
if ($a = 67) $a = $a + 1;

$campos = "uno dos,tres";
$myfield = Parse($campos, 1, ", ", 1);
echo $myfield . "<br>";
$myfield = Parse($campos, 0, ",", 1);
echo $myfield . "<br>";

echo substr($myfield, 2, 1);


Do you guys think there could be market for a tool like this?
It certainly makes easier to code. :)
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Elias Montoya

BTW, heres the original bas file:

LOCAL A AS LONG
LOCAL B AS LONG
LOCAL IP AS LONG
LOCAL eLI AS LONG
LOCAL text AS STRING
LOCAL S3 AS LONG
LOCAL INDEX AS LONG
LOCAL Correct AS LONG
LOCAL Campos AS LONG
LOCAL myfield AS LONG
LOCAL infierno AS STRING

IF (eli = 2.5) THEN  ' Test comment
    INCR s3 ' Test comment
    INCR s3 ' Test comment
ELSE ' Test comment
    DECR s3' Test comment
END IF ' Test

SELECT CASE $infierno ' Test comment
CASE 2
    FOR Index = 1 TO 100 STEP -1 ' Test comment
    NEXT Index ' Test comment
CASE 3 ' Test comment
    FOR Index = 1 TO 100 STEP -1
        IF ISFALSE(Index = 25) THEN
            EXIT FOR   ' Test comment
            MyVariable = $TIME ' Test comment
            MyVariable    = "  $DATE" ' Test comment
        END IF ' Test comment
    NEXT Index
CASE 4
      GOT = ThisIsaLabel ' Test comment
END SELECT ' Test comment END SELECT

IF ISFALSE(Correct) THEN ' Test comment
Text         ="Some text " & Concatenate & FORMAT$(Hola) & "!" _' Test comment
& "This is a second text line." _
   & "This is a THIRD text line."
END IF

A = (B5 * 3)+hj

Ip = COOKIE$("Nombre" & (test & "421"))
Ip = $_Cookie("Nombre" & (test & "421"))

IF a THEN
    STDOUT "Hi mom"
END IF
IF A THEN A = sTHEN + 1 ELSE A =A + 3 OR  B
IF A=67 THEN A = A + 1

campos = "uno dos,tres"
myfield =    PARSE$(campos, ANY ", ", 1)
STDOUT myfield & "<br>"
myfield =    PARSE$(campos, ",", 1)
STDOUT myfield & "<br>"

STDOUT MID$(myfield, 2, 1)


Yeah, i like basic best.
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Rolf Brandt

Looks like a very interesting project, Elias.
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Pete Totushek

Hi Elias,

Every once in a while (usually when I have to create something new for our website), I google for a tool like this as it would be much easier to do what I want in PB.
-Pete
www.totusoft.com -- Home of LAN Speed Test

Elias Montoya

 I will continue working on this. I have 3 php projects in the wait, and i want to do them
in BASIC.

So far this thing has stand alone syntax checking that shows the most common errors in the
code, and some of the not so common ones.

Since i am also working on a editor for a friend, i might use the same interface, kind of.
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Martin Francom

Elias,  I also would be interested in such a tool.  I think there would be a market in the PB community for such a tool.

Elias Montoya

 Glad to hear that, i also think there could be market. But i am posting here because
PB forums rules prohibit the promotion of other compilers or languages.

This baby is turning into a monster, and incredibly i still have control over ir completely.
So far it catches all the syntax errors i can think of flawlessly.

I am writting PHP functions to replace the BASIC ones, like Parse$, Left$, Date$ etc...

This is going very good and i am doing it in firefly and PBCC.

To think it all started trying to help a friend with its robot parser... BTW, has anybody seen theo?


Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Roger Garstang

Sounds cool.  I don't think King Bob should complain about something like that.  PHP really isn't a compiler either.  This would be no different than making something in PB to write HTML, JavaScript, etc.  I'd consider it a 3rd Party tool...unless you feel really generous and put it in the Source Code section  :P

Elias Montoya

 Oh Roger, i AM generous. :)

Unfortunately i rely on my programming for income. :(

What to do? :(

Anyway... the thing is alost complete, it works perfectly good!!!
it even adds EXIT FOR/IF/SELECT etc... functionality!
Too bad this functionality requires the GOTO  command, which
requires PHP 5.3+ because most servers use 5.2. :(




Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Roger Garstang

Why is Goto needed?  Doesn't Break work?  There is always an alternate way to do something too.  I've only had a couple places in all the apps I wrote where a goto was needed, and that was usually only for weird places where things processed linear like Serial Communications or TCP.

Elias Montoya


Break works. But, how would you "Break" a FOR/NEXT loop when you are inside a SELECT/END SELECT block?
Using Break would break out of the select block, but would still be inside the FOR/NEXT loop. Using EXIT FOR, exits both SELECT block and NEXT loop.

Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Roger Garstang

#11
Download the php_manual_en.chm from the PHP website if you haven't already. There is an optional parameter Break # where # is how many structures to break out of.  Only one it doesn't mention working with that PB does it an IF block, but there are other ways there and I very seldom break/exit out of an IF in PB.

Elias Montoya

 I will in this moment roger, I just learned php like 3 weeks ago and this whole thing is giving me lots of experience, but i cant be in everything. :)

This project is turning really really huge!!!!! :)
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Elias Montoya

#13
 Well i modified my code and now the EXIT FOR looks like this:

for ($index=1; $index<=3; $index++$b);
{
if (!($index = 25))
{
if (!($index = 22))
{
break 3;// Test comment
$myvariable = $time;// Test comment
$myvariable = "  \$DATE";// AQUI DEBERIA IR ESCAPED!!!
}// Test comment
}// Test comment
}


But in order to translate the GOTO command the server will definately need to have 5.3 installed.

:)
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Elias Montoya

#14
 This thing can now handle arrays, functions and TYPES (UDT's, even UDT's with UDT's as members!).  ;D

Have you ever seen a UDT in a php app? :)
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.