# Ruby tools to develop compilers

**URL:** <https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724>\
**Category:** Ruby\
**Created:** [March 2, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724 "2008-03-02T17:37:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/u/Le_Lann_Jean-Christ)\
**Post date:** [March 2, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724/1 "2008-03-02T17:37:10Z")

</div>

Hi,

For some days now, I have been trying to find the best Ruby tools to  
develop compilers : lexer, parser and possibly more (ast, visitor).

There seems to be plenty of small tools, but it is difficult to know  
whether they are mature or not.

So I would like to have feeback on your own experience in this field.

Thanks  
JC

---

<div class="post-metadata">

**Author:** ![Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/u/Le_Lann_Jean-Christ)\
**Post date:** [March 2, 2008, 9:09pm UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724/2 "2008-03-02T21:09:10Z")

</div>

Le Lann Jean-Christophe wrote:

> Thanks  
> JC

It depends more on the scope of the compiler(s), languages, operating  
systems where the compilers will run, etc., then it does on the “tools”.  
If you’re looking for a highly portable compiler for a variety of  
architectures and operating systems, for example, you’re probably better  
off building a front end for the languages to the GCC intermediate and  
code generation pieces. And if you’re building a compiler for a language  
already handled by GCC, the best advice I can give you is, “don’t  
bother”.

That said, the Ruby _parser_ that seems to have the best user interface  
is Treetop. I’ve only done a couple of small things in it, but it’s a  
lot easier to read Treetop code than it is to read, say, racc.

---

<div class="post-metadata">

**Author:** ![Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/u/Le_Lann_Jean-Christ)\
**Post date:** [March 3, 2008, 7:19am UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724/3 "2008-03-03T07:19:11Z")

</div>

> BTW, please share your finds!

I agree! 🙂

---

<div class="post-metadata">

**Author:** ![Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/u/Le_Lann_Jean-Christ)\
**Post date:** [March 3, 2008, 8:42pm UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724/4 "2008-03-03T20:42:29Z")

</div>

fedzor a écrit :

> BTW, please share your finds!

Well, ok. ‘Plenty’ is not the right word, nor ‘small tools’ (I guess)

RACC  
ANTLR (ruby generator)  
Treetop  
Ruby-lex, Ruby- yacc

Any other one ? Which one do you use ?

Bye!  
JC

---

<div class="post-metadata">

**Author:** ![Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/u/Le_Lann_Jean-Christ)\
**Post date:** [March 3, 2008, 3:42am UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724/5 "2008-03-03T03:42:03Z")

</div>

On Mar 2, 2008, at 11:36 AM, Le Lann Jean-Christophe wrote:

> Hi,
> 
> For some days now, I have been trying to find the best Ruby tools  
> to develop compilers : lexer, parser and possibly more (ast, visitor).
> 
> There seems to be plenty of small tools, but it is difficult to  
> know whether they are mature or not.

-\> ASM Compilers or interpreters?

BTW, please share your finds!

-------------------------------------------------------|  
~ Ari  
Careful - I’m like Stallman with katanas!

---

<div class="post-metadata">

**Author:** ![Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/u/Le_Lann_Jean-Christ)\
**Post date:** [March 5, 2008, 9:48pm UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724/6 "2008-03-05T21:48:45Z")

</div>

On Mon, Mar 3, 2008 at 1:40 PM, Le Lann Jean-Christophe  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Ruby-lex isn’t a lexer written in Ruby usable for other grammars, it  
is a lexer for the ruby language itself.

Treetop is by far the easiest to work with.  
Also not on your list, is ragel, which builds very fast state machines.

Daniel Brumbaugh K.

---

<div class="post-metadata">

**Author:** ![Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/u/Le_Lann_Jean-Christ)\
**Post date:** [March 8, 2008, 7:41pm UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724/7 "2008-03-08T19:41:57Z")

</div>

On 3/2/08, Le Lann Jean-Christophe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> For some days now, I have been trying to find the best Ruby tools to  
> develop compilers : lexer, parser and possibly more (ast, visitor).
> 
> There seems to be plenty of small tools, but it is difficult to know  
> whether they are mature or not.
> 
> So I would like to have feeback on your own experience in this field.

I’ll join the chorus for TreeTop: it’s pleasant to work with…  
though, it doesn’t produce the fastest parsers around.

There’s also Ruby parsec if you want to go the parser combinator route:  
[http://docs.codehaus.org/display/JPARSEC/Ruby+Parsec](http://docs.codehaus.org/display/JPARSEC/Ruby+Parsec)  
I have not played with it, though.

Phil

---

<div class="post-metadata">

**Author:** ![Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/u/Le_Lann_Jean-Christ)\
**Post date:** [March 8, 2008, 7:10pm UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724/8 "2008-03-08T19:10:48Z")

</div>

On Wed, Mar 5, 2008 at 2:47 PM, Daniel Brumbaugh K. wrote:

> Ruby-lex isn’t a lexer written in Ruby usable for other grammars, it  
> is a lexer for the ruby language itself.

Please forgive my error, I was thinking of the RubyLex class included  
in IRB. It appears there is a project of the same name that can be  
found at the links below. To add to the confusion, RubyLex files end  
in .rl, the same as Ragel. For the education of this mailing list,  
I’ve copied the introduction of its README.

Lexical analyzer generator V1.3 by Harald Grosse.

This extension adds to ruby a functionality to work with lex for C  
programs  
as well as for ruby Code. It reads the grammar specification, modify  
the  
code so that lex accepted the ruby elements, compile this code with  
flex  
to lex.yy.c and build an comparable Ruby coded analayzer from this  
file.

Not all features of lex are implemented.

[http://raa.ruby-lang.org/project/ruby-lex/](http://raa.ruby-lang.org/project/ruby-lex/)  
[http://www.less.de/download/ruby-lex-1.4.tgz](http://www.less.de/download/ruby-lex-1.4.tgz)

Daniel Brumbaugh K.

---

<div class="post-metadata">

**Author:** ![Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Le\_Lann\_Jean-Christ](https://www.ruby-forum.com/u/Le_Lann_Jean-Christ)\
**Post date:** [March 9, 2008, 1:33pm UTC](https://www.ruby-forum.com/t/ruby-tools-to-develop-compilers/130724/9 "2008-03-09T13:33:34Z")

</div>

Phil T. a écrit :

> There’s also Ruby parsec if you want to go the parser combinator route:  
> [http://docs.codehaus.org/display/JPARSEC/Ruby+Parsec](http://docs.codehaus.org/display/JPARSEC/Ruby+Parsec)  
> I have not played with it, though.

Thanks all for your answers,

Regarding TreeTop, there is a tutorial by its author at  
[http://rubyconf2007.confreaks.com/d1t1p5\_treetop.html](http://rubyconf2007.confreaks.com/d1t1p5_treetop.html).  
My preference goes to Treetop too, because it seems elegant and based on  
efficient algorithms. (I will give my own feedback on real grammars,  
when ready)

Nobody is using Antlr with Ruby output ? Antlr seemed great because it  
gives you access to a bunch of various grammars, already described.

Regards,  
JC
