TPLY

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

TPLY

bsquared
I recently saw a semi working example of a Java to Delphi converter
that was done with javacc.  Unfortunately it would only convert simple
java (v 1.4 maybe).

Can anyone recommend a good place to start reading or offer any advise
to accomplish this with TPLY.

I am looking into porting some Java libraries to FPC 2.5.x, and am
unfamiliar with the TPLY tools.

Thanks,
Brian
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

leledumbo
Administrator
I prefer doing this manually, syntax conversion is easy, but library design is totally different.
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

bsquared
> I prefer doing this manually, syntax conversion is easy, but library design
> is totally different.

A conversion of the Java code will provide a good starting point I
think.  Additionally, learning TPLY or lex/yacc could prove very
useful I think.

Do you have grammer files for syntax conversion?  I have not found an
up to date grammer file for FPC's current objpas dialect.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

tcoq
In reply to this post by bsquared
Hello Brian,
there is a port to Lazarus here:

http://www.tcoq.org/

with some examples. I can help you if needed. The documentation is quite
complete.

Translating the whole Java language would be very difficult, but
translating only the structure could be done. You would need to write a
grammar capable of bypassing all internal code.

I hope this helps.
Best regards,
Thierry

> Can anyone recommend a good place to start reading or offer any advise
> to accomplish this with TPLY.
>
> I am looking into porting some Java libraries to FPC 2.5.x, and am
> unfamiliar with the TPLY tools.
>
> Thanks,
> Brian
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
>    

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

bsquared
>>
>> I am looking into porting some Java libraries to FPC 2.5.x, and am
>> unfamiliar with the TPLY tools.
>>
> Translating the whole Java language would be very difficult, but translating
> only the structure could be done. You would need to write a grammar capable
> of bypassing all internal code.

The libraries are some of the Google Data libraries.  The libs are
available in other languages, so I don't necessarily have to start
with java, although I have some familiarity with it.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

bsquared
In reply to this post by tcoq
> there is a port to Lazarus here:
>
> http://www.tcoq.org/
>
> with some examples. I can help you if needed. The documentation is quite
> complete.

Thanks it looks interesting, I like the component approach, I will
take a close look.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

bsquared
On Wed, Oct 27, 2010 at 9:21 AM, Brian Winfrey <[hidden email]> wrote:

>> there is a port to Lazarus here:
>>
>> http://www.tcoq.org/
>>
>> with some examples. I can help you if needed. The documentation is quite
>> complete.
>
> Thanks it looks interesting, I like the component approach, I will
> take a close look.
>

I was not able to set paths and compile.  There were file naming
problems with case and duplication.  I have a diff file if you like.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

leledumbo
Administrator
Learn compilation technique, a recursive descent parser should be easy to understand and code instead of learning automatic lexer and parser generator. Plus, structurally, Java is a very simple language, so AST transformation should be easy. With FPC 2.5.1, almost all Java constructs can be directly translated to FPC dialect, minus anonymous inner class only AFAIK.
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

tcoq
In reply to this post by bsquared
Hello Brian,

Yes, please send the diff file, so I can look at it. Which platform
(Windows, Linux, FPC) are you using?

Another approach would be to look at (and reverse engineer) the byte
code. If it's not obfuscated, it might even be easier to parse and port
than the native Java.

On 27/10/2010 20:38, Brian Winfrey wrote:

> On Wed, Oct 27, 2010 at 9:21 AM, Brian Winfrey<[hidden email]>  wrote:
>    
>>> there is a port to Lazarus here:
>>>
>>> http://www.tcoq.org/
>>>
>>> with some examples. I can help you if needed. The documentation is quite
>>> complete.
>>>        
>> Thanks it looks interesting, I like the component approach, I will
>> take a close look.
>>
>>      
> I was not able to set paths and compile.  There were file naming
> problems with case and duplication.  I have a diff file if you like.
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
>    

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

bsquared
>
> Yes, please send the diff file, so I can look at it. Which platform
> (Windows, Linux, FPC) are you using?
Linux, Kubuntu 10.04 .
Linux is case sensitive, so the case in the uses must match the case
of the file or unit declaration I think. ie.
* filename = test.pas
* unit Test;
is accessed as test or Test in the uses clause.

I'm not sure , but I think if the file name were Test.pas then it must
be Test in the uses.

The changes I made in this diff were simply to get it to compile.

Subsequently I renamed all files and folders to lowercase, converted
spaces to underscores and added a prefix to eliminate duplicate file
names where needed.

>
> Another approach would be to look at (and reverse engineer) the byte code.
> If it's not obfuscated, it might even be easier to parse and port than the
> native Java.
>
How would you suggest I proceed in that.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

diff.diff (258K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

bsquared
In reply to this post by leledumbo
Thank you, What techiniques have you used in the past that you could
share to get me started?

On Wed, Oct 27, 2010 at 8:04 PM, leledumbo <[hidden email]> wrote:

>
> Learn compilation technique, a recursive descent parser should be easy to
> understand and code instead of learning automatic lexer and parser
> generator. Plus, structurally, Java is a very simple language, so AST
> transformation should be easy. With FPC 2.5.1, almost all Java constructs
> can be directly translated to FPC dialect, minus anonymous inner class only
> AFAIK.
> --
> View this message in context: http://free-pascal-general.1045716.n5.nabble.com/TPLY-tp3235828p3239905.html
> Sent from the Free Pascal - General mailing list archive at Nabble.com.
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: TPLY

Paul Nicholls
"Brian Winfrey" <[hidden email]> wrote in
message news:[hidden email]...
Thank you, What techiniques have you used in the past that you could
share to get me started?

On Wed, Oct 27, 2010 at 8:04 PM, leledumbo
<[hidden email]> wrote:
>
> Learn compilation technique, a recursive descent parser should be easy to
> understand and code instead of learning automatic lexer and parser
> generator. Plus, structurally, Java is a very simple language, so AST
> transformation should be easy. With FPC 2.5.1, almost all Java constructs
> can be directly translated to FPC dialect, minus anonymous inner class
> only
> AFAIK.

I would start with this site to learn how to create recursive descent
parsers using Pascal :)

http://compilers.iecc.com/crenshaw/

Using this information as a starting point, I have created pascal-like
script languages (compiled to byte code), and pascal-like HL language
compiled to virtual machine ML instructions :)

cheers,
Paul



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: TPLY

leledumbo
Administrator
> I would start with this site to learn how to create recursive descent
> parsers using Pascal :)

Definitely, but it doesn't build AST, which is required if you need to write a parser for a language that can't be parsed in single pass like Java.
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

tcoq
In reply to this post by bsquared
Brian,
thanks for the diff, I'll take it into account and publish an update.

On 28/10/2010 18:50, Brian Winfrey wrote:
...
> The changes I made in this diff were simply to get it to compile.
>
> Subsequently I renamed all files and folders to lowercase, converted
> spaces to underscores and added a prefix to eliminate duplicate file
> names where needed.
>
>    
...
>> Another approach would be to look at (and reverse engineer) the byte code.
>> If it's not obfuscated, it might even be easier to parse and port than the
>> native Java.
>>
>>      
> How would you suggest I proceed in that.
>    
>
Using the class file format (for example here:
http://en.wikipedia.org/wiki/Class_%28file_format%29),
it would be easy to parse through the tables, identify the class name,
its super class name, the interfaces it's implementing, and even the
public and private methods. The java compiler has done all the work into
translating the java code into nice tables. ;-)
I remember I did the exercise once. I've destroyed the code, but I could
do it again. I remember one of the more difficult parts was
understanding how java coded strings ;-) This was before anonymous
classes and methods, so this could be another difficulty. I don't know
how these are converted to byte code.
Once you have the structure, you can generate the pascal code. I would
recommend against generating one class per unit as Java does: since
pascal dependency rules are strict (no cycles), this would most
certainly result in uncompilable code. What I do when I translate Java
is to pre-declare all classes and interfaces at the top of the unit(s)
and then generate the full class interface further down.
Translating the statements inside the bytecode I haven't tried, since my
efforts were mostly for analyzing java code and measuring it.
I hope this helps,
Thierry

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: TPLY

Adriaan van Os-2
In reply to this post by Paul Nicholls
Paul Nicholls wrote:
> I would start with this site to learn how to create recursive descent
> parsers using Pascal :)
>
> http://compilers.iecc.com/crenshaw/

I recommend <http://www-old.oberon.ethz.ch/WirthPubl/CBEAll.pdf>

Regards,

Adriaan van Os
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: TPLY

tcoq
I second that.
...
>
> I recommend <http://www-old.oberon.ethz.ch/WirthPubl/CBEAll.pdf>
...
also Wirth's book on Project Oberon, where the compiler design is
explained, and its purpose in the whole project:

http://www.oberon.ethz.ch/WirthPubl/ProjectOberon.pdf

in the physical world: ISBN 0-201-54428-8
I was able to buy a copy!

Thierry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: TPLY

tcoq
Reply | Threaded
Open this post in threaded view
|

Re: Re: TPLY

David Riley
In reply to this post by Paul Nicholls
On Fri, 2010-10-29 at 09:24 +1100, Paul Nicholls wrote:

> "Brian Winfrey" <[hidden email]> wrote in
> message news:[hidden email]...
> Thank you, What techiniques have you used in the past that you could
> share to get me started?
>
> On Wed, Oct 27, 2010 at 8:04 PM, leledumbo
> <[hidden email]> wrote:
> >
> > Learn compilation technique, a recursive descent parser should be easy to
> > understand and code instead of learning automatic lexer and parser
> > generator. Plus, structurally, Java is a very simple language, so AST
> > transformation should be easy. With FPC 2.5.1, almost all Java constructs
> > can be directly translated to FPC dialect, minus anonymous inner class
> > only
> > AFAIK.
>
> I would start with this site to learn how to create recursive descent
> parsers using Pascal :)
>
> http://compilers.iecc.com/crenshaw/
>
> Using this information as a starting point, I have created pascal-like
> script languages (compiled to byte code), and pascal-like HL language
> compiled to virtual machine ML instructions :)
>
> cheers,
> Paul
>
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

A book I'd recommend reading in addition to the Dr. Jack Crenshaw
articles mentioned above would be "Compiler Construction" by Niklaus
Wirth.  It's goes in to a lot more detail than "Let's Build A Compiler"
but still start with the basics.  I found it here:
www-old.oberon.ethz.ch/WirthPubl/CBEAll.pdf .  Mr. (Dr. yet?) Florian
Klaempfl should write a book, he seems to have done pretty good with the
whole Pascal compiler thing.  With the entire FPC crew you'd each only
have to write a few chapters...  

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Re: TPLY

bsquared
Well, seems like you all have given some material to get me started.
As nobody suggested sticking with TPLY or plex/bison I will
back-burner that and proceed with crenshaw/oberon.

Thanks to everyone.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TPLY

bsquared
In reply to this post by tcoq
Thanks, I'll look into this as well.

On Fri, Oct 29, 2010 at 2:19 AM, Thierry Coq <[hidden email]> wrote:

> Brian,
> thanks for the diff, I'll take it into account and publish an update.
>
> On 28/10/2010 18:50, Brian Winfrey wrote:
> ...
>>
>> The changes I made in this diff were simply to get it to compile.
>>
>> Subsequently I renamed all files and folders to lowercase, converted
>> spaces to underscores and added a prefix to eliminate duplicate file
>> names where needed.
>>
>>
>
> ...
>>>
>>> Another approach would be to look at (and reverse engineer) the byte
>>> code.
>>> If it's not obfuscated, it might even be easier to parse and port than
>>> the
>>> native Java.
>>>
>>>
>>
>> How would you suggest I proceed in that.
>>
>
> Using the class file format (for example here:
> http://en.wikipedia.org/wiki/Class_%28file_format%29),
> it would be easy to parse through the tables, identify the class name, its
> super class name, the interfaces it's implementing, and even the public and
> private methods. The java compiler has done all the work into translating
> the java code into nice tables. ;-)
> I remember I did the exercise once. I've destroyed the code, but I could do
> it again. I remember one of the more difficult parts was understanding how
> java coded strings ;-) This was before anonymous classes and methods, so
> this could be another difficulty. I don't know how these are converted to
> byte code.
> Once you have the structure, you can generate the pascal code. I would
> recommend against generating one class per unit as Java does: since pascal
> dependency rules are strict (no cycles), this would most certainly result in
> uncompilable code. What I do when I translate Java is to pre-declare all
> classes and interfaces at the top of the unit(s) and then generate the full
> class interface further down.
> Translating the statements inside the bytecode I haven't tried, since my
> efforts were mostly for analyzing java code and measuring it.
> I hope this helps,
> Thierry
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
12