From: "M. Edward (Ed) Borasky" Date: 2007-07-27T23:12:28+09:00 Subject: Re: How to write a ruby compiler using Java??? 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.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/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? ;)