How to write a ruby compiler using Java?

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.ruby-lang.org.
Many Thanks.

Best Rgds,
Shiwei

2007/7/27, shiwei zhang [email protected]:

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.ruby-lang.org.

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

Kind regards

robert

shiwei zhang wrote:

not a complete grammar definition for ruby lang at
http://www.ruby-lang.org.
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 at Directnic 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 R.-to-bytecode compiler based on that AST.

  • Charlie

Charles Oliver N. wrote:

complete grammar definition for ruby lang? E.G., like C99(ISO

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? :wink:

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