Page 1 of 1

OOP TO PB

Posted: Thu Jul 19, 2007 9:04 pm
by Anonymous
Hello everybody, i've made a small program for convert "c++ like" to PB opérational code.

it is very easy to use, the syntax is very near of c++ syntax's


Example :

in this example, we make an class named "PERSONNAGE" ( person in english )
this class as got 2 methods called SetName() and GetName()
and one variable called Name$

Code: Select all

class PERSONNAGE
{
SetName(Name$)
GetName.s()
Name$
}


PERSONNAGE::SetName(Name$)
{
;Insert Purebasic code here
*This\Name$ = Name$
}

PERSONNAGE::GetName.s()
{
ProcedureReturn *This\Name$
}
with this apps (oop-pb) you can convert that code in PureBasic Code
see the translation :

Code: Select all

;******************************************************************
;    Object-oriented programming to Purebasic Converter           
;
;                      Par Cpl.Bator
;
;******************************************************************
;-Constructor(s) & Destructor(s)
; ----------------------------------------------------------------
Macro New_PERSONNAGE(Pointeur)
*Pointeur_.PERSONNAGE_=AllocateMemory(SizeOf(PERSONNAGE_))
*Pointeur_\Vtable=?Vtable_PERSONNAGE
Pointeur.PERSONNAGE=@*Pointeur_\Vtable
EndMacro
; ----------------------------------------------------------------
Macro Free_PERSONNAGE(Pointeur)
  Pointeur#_.Class#_=Pointeur
  FreeMemory(Pointeur)
EndMacro
; ----------------------------------------------------------------
;-Interfaces
Interface PERSONNAGE
   SetName(Name$)
   GetName.s()
EndInterface
; ----------------------------------------------------------------
; ----------------------------------------------------------------
;-Structures
Structure PERSONNAGE_

Vtable.l
Name$

EndStructure
; ----------------------------------------------------------------



; ----------------------------------------------------------------
;-Methodes
Procedure SetName(*This.PERSONNAGE_,Name$)

*This\Name$ = Name$
EndProcedure

; ----------------------------------------------------------------
Procedure.s GetName(*This.PERSONNAGE_)

ProcedureReturn *This\Name$
EndProcedure

; ----------------------------------------------------------------
; ----------------------------------------------------------------
;-DataSections
DataSection
VTable_PERSONNAGE:
Data.l @SetName(),@GetName()
; ----------------------------------------------------------------
EndDataSection
; ----------------------------------------------------------------

and you use this code with :

Code: Select all

IncludeFile "Personnage.pbc_Out.pbi"

New_PERSONNAGE(A)
A\SetName("Fred")

Debug A\GetName()
Now, the oop is more easy with oop-pb :D

you can download this here with 2 Examples :

File:1->oop-pb.tar.gz
Image


How to :

Open an console
go to the directory of oop-pb

an try this

Code: Select all

./oop-pb MyFile.pbc
the output file is MyFile.pbc_out.pbi

Enjoy :P

Posted: Fri Jul 20, 2007 10:13 am
by inc.
Hi!

Just look out for "LCP" (Little class parser) from the board member "fsw" here in the forum, he also did release an OOP preprocessor.

Maybe you both should get in contact so you can benefit from each others advantages in the building of such an oop preprozessor, so that finally we get one (official ;-) ) oop preprocessor for the PB community.

Greets
:)

Posted: Fri Jul 20, 2007 2:33 pm
by Anonymous
Just look out for "LCP" (Little class parser) from the board member "fsw" here in the forum, he also did release an OOP preprocessor.
LCP work in windows :? oop-pb work in linux and windows(not yet :D)
Maybe you both should get in contact so you can benefit from each others advantages in the building of such an oop preprozessor, so that finally we get one (official Wink ) oop preprocessor for the PB community.

Greets
it 's very hard for me, because i dont speak English very well , and a parsing program is not easy.

Posted: Fri Jul 20, 2007 3:32 pm
by inc.
Cpl.Bator wrote:LCP work in windows :? oop-pb work in linux and windows(not yet :D)
Oh, .... we're in Linux here, .. I totally missed that :)