# Ruby equivalent of Lex (or Flex)?

**URL:** <https://www.ruby-forum.com/t/ruby-equivalent-of-lex-or-flex/56255>\
**Category:** Ruby\
**Created:** [January 5, 2006, 7:57pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-lex-or-flex/56255 "2006-01-05T19:57:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![twp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c89c15/32.png) [@twp](https://www.ruby-forum.com/u/twp)\
**Post date:** [January 5, 2006, 7:57pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-lex-or-flex/56255/1 "2006-01-05T19:57:28Z")

</div>

I’m interested in writing compilers in Ruby. It appears that Racc is  
a suitable replacement for Yacc, but I’ve not found any replacement  
for Lex. I’ve probably missed something. In any case, I’d much  
appreciate some help in finding something.

Thanks in advance,  
Tom P.

---

<div class="post-metadata">

**Author:** ![twp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c89c15/32.png) [@twp](https://www.ruby-forum.com/u/twp)\
**Post date:** [January 5, 2006, 9:51pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-lex-or-flex/56255/2 "2006-01-05T21:51:41Z")

</div>

Rex?

[http://raa.ruby-lang.org/project/rex/](http://raa.ruby-lang.org/project/rex/)

-Justin

---

<div class="post-metadata">

**Author:** ![twp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c89c15/32.png) [@twp](https://www.ruby-forum.com/u/twp)\
**Post date:** [January 5, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-lex-or-flex/56255/3 "2006-01-05T22:27:46Z")

</div>

It’s worth noting that, thanks to grammarian Martin Traverso, the  
latest version of ANTLR v3 can generate parsers in Ruby.

[split-s: ANTLR for Ruby](http://split-s.blogspot.com/2005/12/antlr-for-ruby.html)

It’s still pre-alpha, but things only get better from here!

I believe there’s also a native Ruby port of ANTLR v2 bopping about  
out there, though google isn’t helping me out much right now.

A decent LL parser generator really is worth it, though. LALR  
sucks.

Incidentally, it looks like Martin will be writing much of the ANTLR  
v3 grammar for Ruby. He’s got quite a bit done in SVN already.

-mental

---

<div class="post-metadata">

**Author:** ![twp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c89c15/32.png) [@twp](https://www.ruby-forum.com/u/twp)\
**Post date:** [January 5, 2006, 10:33pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-of-lex-or-flex/56255/4 "2006-01-05T22:33:47Z")

</div>

Two popular parser generators have or will have ruby support:

ANTLR 3.0 (still in alpha and likely to remain so for another year or  
two) will have ruby support too apparently:  
[http://split-s.blogspot.com/2005/12/antlr-for-ruby.html](http://split-s.blogspot.com/2005/12/antlr-for-ruby.html)  
They are even working on an antlr 3.0 grammar for ruby itself:  
[http://rubyforge.org/projects/rubygrammar](http://rubyforge.org/projects/rubygrammar)

Also (not in alpha), there is a ruby version of Coco:  
[http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/](http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/)  
[http://www.zenspider.com/ZSS/Products/CocoR/](http://www.zenspider.com/ZSS/Products/CocoR/)  
[http://rubyforge.org/projects/coco-ruby/](http://rubyforge.org/projects/coco-ruby/)
