# Parsing visual basic

**URL:** <https://www.ruby-forum.com/t/parsing-visual-basic/71174>\
**Category:** Ruby\
**Created:** [October 5, 2006, 9:17pm UTC](https://www.ruby-forum.com/t/parsing-visual-basic/71174 "2006-10-05T21:17:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![FSSenault](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@FSSenault](https://www.ruby-forum.com/u/FSSenault)\
**Post date:** [October 5, 2006, 9:17pm UTC](https://www.ruby-forum.com/t/parsing-visual-basic/71174/1 "2006-10-05T21:17:33Z")

</div>

Hello.

Where I work, we have to develop and maintain a quite huge application  
fully written in Visual Basic 6 [1].

Quite a few tasks should be automated, and being the magical-one-liner-  
script guru of the workplace, I’m the one tasked with a bunch of things.

So, I could continue to throw together bunches of ugly ruby and perl  
scripts written each to achieve one specific goal, or I could try to  
think a bit further and try to implement something more elegant,  
powerful, and adaptable.

But, to do that, I need to parse advanced VB6 code, to a quite fine  
grained point. For instance, detecting dead code and dead variables.

I took a look at some projects out there, including full-fledged parsers  
(none in ruby, or none fully useable, AFAI), but I didn’t manage to do  
much.

Are there any solutions out there that I overlooked ? Someone around  
who has some experience in the domain to give pointers (though I’d  
gladly accept code too… 🙂 ) ?

Fred  
[1] : This is the point where everyone goes hiding behind the couch…

---

<div class="post-metadata">

**Author:** ![FSSenault](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@FSSenault](https://www.ruby-forum.com/u/FSSenault)\
**Post date:** [October 6, 2006, 12:05am UTC](https://www.ruby-forum.com/t/parsing-visual-basic/71174/2 "2006-10-06T00:05:59Z")

</div>

F. Senault wrote:

> think a bit further and try to implement something more elegant,  
> who has some experience in the domain to give pointers (though I’d  
> gladly accept code too… 🙂 ) ?
> 
> ## Fred [1] : This is the point where everyone goes hiding behind the couch…
> 
> Science is always discovering odd scraps of magical wisdom and making a  
> tremendous fuss about its cleverness. (Aleister Crowley)

Beware, that way lie patents.

---

<div class="post-metadata">

**Author:** ![FSSenault](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@FSSenault](https://www.ruby-forum.com/u/FSSenault)\
**Post date:** [October 6, 2006, 2:16am UTC](https://www.ruby-forum.com/t/parsing-visual-basic/71174/3 "2006-10-06T02:16:10Z")

</div>

Timothy G. wrote:

> > scripts written each to achieve one specific goal, or I could try to  
> > Are there any solutions out there that I overlooked ? Someone around

Timothy G., Can you explain what you mean by “Beware, that way lie  
patents” please.  
Cheers, Mike

---

<div class="post-metadata">

**Author:** ![FSSenault](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@FSSenault](https://www.ruby-forum.com/u/FSSenault)\
**Post date:** [October 6, 2006, 7:31pm UTC](https://www.ruby-forum.com/t/parsing-visual-basic/71174/4 "2006-10-06T19:31:05Z")

</div>

On 10/6/06, Jan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > scripts written each to achieve one specific goal, or I could try to  
> > Are there any solutions out there that I overlooked ? Someone around  
> > you end up writing a parser, you might have a look at his one (look  
> > for ‘Mongrel grammar file’ thread,  
> > [http://rubyforge.org/pipermail/mongrel-users/2006-August/001241.html](http://rubyforge.org/pipermail/mongrel-users/2006-August/001241.html))

I don’t think he’ll be able to use Ragel to handle VB6. From some  
searches, it looks like some of the VB6 syntax can’t be expressed in  
LALR, etc.  
That being said, there are some pretty cool parser generators for  
Ruby, so it could probably be done.

---

<div class="post-metadata">

**Author:** ![FSSenault](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@FSSenault](https://www.ruby-forum.com/u/FSSenault)\
**Post date:** [October 6, 2006, 10:41pm UTC](https://www.ruby-forum.com/t/parsing-visual-basic/71174/5 "2006-10-06T22:41:18Z")

</div>

Wilson B. wrote:

> That being said, there are some pretty cool parser generators for  
> Ruby, so it could probably be done.

Doesn’t the upcoming ANTLR support emitting Ruby code? You could try  
that. I think there’s also a project that tries to compile [ASP.NET](http://ASP.NET) to  
equivalent PHP using ANTLR, you could rip off^W^Wdraw inspiration from  
their grammars.

David V.

---

<div class="post-metadata">

**Author:** ![FSSenault](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@FSSenault](https://www.ruby-forum.com/u/FSSenault)\
**Post date:** [October 7, 2006, 2:35am UTC](https://www.ruby-forum.com/t/parsing-visual-basic/71174/6 "2006-10-07T02:35:42Z")

</div>

Mike he was alluding to the closed source nature of Microsoft products  
it was a joke.

---

<div class="post-metadata">

**Author:** ![FSSenault](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@FSSenault](https://www.ruby-forum.com/u/FSSenault)\
**Post date:** [October 6, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/parsing-visual-basic/71174/7 "2006-10-06T19:26:56Z")

</div>

On 10/5/06, F. Senault [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> think a bit further and try to implement something more elegant,  
> who has some experience in the domain to give pointers (though I’d  
> gladly accept code too… 🙂 ) ?

Just a few hints:

- Joel Spolsky said they have a compiler from VB to PHP, although I’m  
a bit sceptic about whether he will release that (see  
[Wasabi – Joel on Software](http://www.joelonsoftware.com/items/2006/09/01b.html))

- Zed S. has used ragel to build an http parser in mongrel, so if  
you end up writing a parser, you might have a look at his one (look  
for ‘Mongrel grammar file’ thread,  
[http://rubyforge.org/pipermail/mongrel-users/2006-August/001241.html](http://rubyforge.org/pipermail/mongrel-users/2006-August/001241.html))

J.

---

<div class="post-metadata">

**Author:** ![FSSenault](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@FSSenault](https://www.ruby-forum.com/u/FSSenault)\
**Post date:** [October 7, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/parsing-visual-basic/71174/8 "2006-10-07T19:26:28Z")

</div>

Le 6 octobre 2006 à 22:39, David V. a écrit :

> Wilson B. wrote:
> 
> > That being said, there are some pretty cool parser generators for  
> > Ruby, so it could probably be done.
> 
> Doesn’t the upcoming ANTLR support emitting Ruby code?

Yep. Still in beta, though (both ANTLR 3 and the Ruby target part).

> You could try that. I think there’s also a project that tries to compile  
> [ASP.NET](http://ASP.NET) to equivalent PHP using ANTLR, you could rip off^W^Wdraw  
> inspiration from their grammars.

I think it’s vastly different, alas. I’ll wait for the ANTLR release  
and try to write somthing on my own, but I’m afraid writing a whole  
grammar is way over my competence… 😑

Fred
