[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to write a ruby compiler using Java???

Shiwei Zhang

7/27/2007 8:29:00 AM

Hi,

I am using Java to write a Ruby compiler. I build up the editor by
Java SWing.
Now the tough task for me is syntax parser. Does someone have some
suggestions about how to check the validity of ruby codes in the editor
and how to mark the grammar-incompliant points? Are there some plugins I
can make use of, or do I need to parse the grammar by myself? If I want
to parse the grammar by myself, where is the complete grammar definition
for ruby lang? E.G., like C99(ISO 9899:1999) for C lang. Seems there is
not a complete grammar definition for ruby lang at http://www.rub....
Many Thanks.

Best Rgds,
Shiwei

4 Answers

Robert Klemme

7/27/2007 8:40:00 AM

0

2007/7/27, shiwei zhang <shiwei.zhang@oracle.com>:
> I am using Java to write a Ruby compiler. I build up the editor by
> Java SWing.
> Now the tough task for me is syntax parser. Does someone have some
> suggestions about how to check the validity of ruby codes in the editor
> and how to mark the grammar-incompliant points? Are there some plugins I
> can make use of, or do I need to parse the grammar by myself? If I want
> to parse the grammar by myself, where is the complete grammar definition
> for ruby lang? E.G., like C99(ISO 9899:1999) for C lang. Seems there is
> not a complete grammar definition for ruby lang at http://www.rub....

Why not join http://jruby.code... There you might also find
answers to your questions.

Kind regards

robert

Charles Oliver Nutter

7/27/2007 9:24:00 AM

0

shiwei zhang wrote:
> Hi,
>
> I am using Java to write a Ruby compiler. I build up the editor by
> Java SWing.
> Now the tough task for me is syntax parser. Does someone have some
> suggestions about how to check the validity of ruby codes in the editor
> and how to mark the grammar-incompliant points? Are there some plugins I
> can make use of, or do I need to parse the grammar by myself? If I want
> to parse the grammar by myself, where is the complete grammar definition
> for ruby lang? E.G., like C99(ISO 9899:1999) for C lang. Seems there is
> not a complete grammar definition for ruby lang at
> http://www.rub....
> Many Thanks.

There are basically two known good grammars for Ruby. One is the
original Ruby 1.8 YACC-based parser grammar and variations of it (JRuby,
Rubinius, and Ruby.NET/IronRuby all use variations or ports of that
grammar). The other is an ANTLR grammar used by the XRuby project. Only
the YACC grammars are known to be "compatible" at present, but XRuby's
ANTLR grammar seems to be very close.

If you are looking for a grammar/AST to use for an editor, your best bet
is probably JRuby's. Not only do we have the most popular grammar and
AST for Java-based editors, but we have an additional set of utility
code to allow inspecting, reversing, and manipulating the AST. NetBeans,
Eclipse, and JEdit-based Ruby editors are based on our parser and AST,
as is (I believe) the IntelliJ Ruby editor. We also have been building
the JRuby Ruby-to-bytecode compiler based on that AST.

- Charlie

M. Edward (Ed) Borasky

7/27/2007 2:12:00 PM

0

Charles Oliver Nutter wrote:
> shiwei zhang wrote:
>> Hi,
>>
>> I am using Java to write a Ruby compiler. I build up the editor by
>> Java SWing.
>> Now the tough task for me is syntax parser. Does someone have some
>> suggestions about how to check the validity of ruby codes in the
>> editor and how to mark the grammar-incompliant points? Are there some
>> plugins I can make use of, or do I need to parse the grammar by
>> myself? If I want to parse the grammar by myself, where is the
>> complete grammar definition for ruby lang? E.G., like C99(ISO
>> 9899:1999) for C lang. Seems there is not a complete grammar
>> definition for ruby lang at http://www.rub....
>> Many Thanks.
>
> There are basically two known good grammars for Ruby. One is the
> original Ruby 1.8 YACC-based parser grammar and variations of it (JRuby,
> Rubinius, and Ruby.NET/IronRuby all use variations or ports of that
> grammar). The other is an ANTLR grammar used by the XRuby project. Only
> the YACC grammars are known to be "compatible" at present, but XRuby's
> ANTLR grammar seems to be very close.
>
> If you are looking for a grammar/AST to use for an editor, your best bet
> is probably JRuby's. Not only do we have the most popular grammar and
> AST for Java-based editors, but we have an additional set of utility
> code to allow inspecting, reversing, and manipulating the AST. NetBeans,
> Eclipse, and JEdit-based Ruby editors are based on our parser and AST,
> as is (I believe) the IntelliJ Ruby editor. We also have been building
> the JRuby Ruby-to-bytecode compiler based on that AST.
>
> - Charlie
>
>
Just out of curiosity, where do the "Zen" tools (ParseTree, Ruby2Ruby,
etc.) fit into this scheme of things?

Also, is there such a thing as Test Driven/Behavior Driven parser
development? Should there be? ;)

Charles Oliver Nutter

7/27/2007 7:13:00 PM

0

M. Edward (Ed) Borasky wrote:
> Just out of curiosity, where do the "Zen" tools (ParseTree, Ruby2Ruby,
> etc.) fit into this scheme of things?

Most of the tools you're thinking of depend on C code that can access or
expose the Ruby 1.8 AST. There is a port of ParseTree for JRuby called
JParseTree, and it's mostly complete but not being used for anything.
Several of the other libraries, like Ruby2Ruby, depend mostly? only? on
ParseTree.

RubyInline depends on both C code/compilers and the Ruby 1.8 APIs, and
as yet there is no port.

I believe others in the zen family would qualify as "stock" extensions.
Of course Ryan can give a more specific overview; my perspective is
mostly that of an alternative implementer.

- Charlie