Managed Lex and Yacc

Buried deep in the docs for v3 of the Visual Studio SDK is something called the Managed Babel System. Babel – in the context of Visual Studio – is the framework for creating language services for stuff like syntax highlighting, brace matching, and IntelliSense completion. As part of the Managed version of Babel, the VS SDK includes the Managed Package Lex Scanner Generator (MPLEX) and the Managed Package Parser Generator (MPPG). Online docs are pretty thin, but there are a few white papers in the additional documentation of the VS SDK install.

Interestingly enough, the white papers were written by John Gough of QUT’s Programming Languages and Systems group. John wrote Compiling for the .NET Common Language Runtime and PLAS has several interesting language projects including Metaphor and Ruby.NET. As you might expect for a group that focuses on languages on .NET, they have a managed version of YACC called GPPG available and John said at Lang.NET that they would be releasing a managed version of LEX “soon”. I’m thinking that QUT’s GPPG/GPLEX combo has been absorbed into the VS SDK and renamed MPPG/MPLEX. Unfortunately, my laptop power connector is broken, so I can’t verify this until Monday.

It’s not a Rosetta stone and the lex/yacc model is getting pretty long in the tooth, but I’m thinking at least Larry O’Brien will be interested in these tools.

Update: Apparently, this is somewhat old news, as per Aaron Marten:

The tools we’re including are called MPPG & MPLex (which stand for Managed Package Parser Generator and Managed Package Lexer). They are derivative works from the open-source GPPG/GPLex tools developed at the Queensland University of Technology.
[Managed Language Tools in Visual Studio 2005 SDK]

Gamer Card Plugin for WL Writer

In my last post, I wanted to include a link to my gamer card, showing the NHL 07 logo on it. It turns out that in addition to the “official” gamer card from Xbox.com, there’s also the MyGamerCard.net site which provides both image and flash versions of gamer cards. Since I’m using Windows Live Writer, and I hear it’s really easy to extend, I decided to throw together a plugin for inserting Gamer Cards. It was, as advertised, extremely easy. I spent more time laying out the dialog box than I did writing the code to interface with WL Writer.

The plug in provides basically five Gamer Card options:

  • Standard Xbox.com Gamer Card
  • MGC.net Gamer Card image with link to Xbox.com Profile
  • MGC.net Gamer Card image with link to MGC.net Profile
  • MGC.net Gamer Card image only
  • MGC.net Gamer Card flash movie

I’m interested in feedback and suggestions for future versions. MyGamerCard.net provides ten different Gamer Card styles (that’s my Gamer Card to the left) so that’s an obvious enhancement for another day. I’d also like to evolve the plugin into a “Smart Content Source”, which allows you to edit the content after it’s been created (like the default “Insert Map” option). Finally, I’m thinking of adding support for GamerScoreChart.com.

Download GamerCard.WriterPlugin.Setup.zip (142.41 KB) and enjoy. Let me know what you think.

Python and DSLs

When I read Larry O’Brien’s post IronPython as a Foundation for DSLs, I had a strong sense of deja-vu. I went thru a very similar thought process when I discovered the early versions of IronPython were written in Python. I figured that meant Python must have some support that makes building compilers easier. Unfortunately, that doesn’t turn out to be the case. Python provides a standard module called parser which “provides an interface to Python’s internal parser”. That means that compiling Python is easy, but there’s no support for compiling any language other than Python.

I’ve been doing a little experimenting in this space. First, as I’ve written before, I’ve been playing with parsing expression grammars. Second, I want to take a close look at Metaphor from QUT:

Metaphor is a programming language with support for type-safe run-time code generation — a form of meta-programming. Metaphor is based on a subset of C# or Java and combines the imperative, object-oriented nature of these languages with the multi-stage programming constructs from MetaOCaml. Metaphor uses the static type system of multi-stage languages to achieve compile-time safety of run-time generated code…

Metaphor is implemented as a compiler on the Microsoft CLR.

Finally, I need to take a closer look at ANTLR. Don’t know how I missed it, but I had never seen ANTLRWorks until Larry linked to it.

Language Features I Wish C# Had – Symbols

Ruby’s symbols are often talked about in terms of efficiency – taking up less memory and executing faster. While these are both laudable goals, symbols are more than just performance improvers. The ability to name things is valuable semantically. Take a look thru p&p’s Composite UI AppBlock and you’ll see strings used as names for things all over the place. It’s great for loose coupling, you see. But how do you tell the difference between a string used as a name and a string used for some other reason like user input? You can’t.

Rails makes extensive use of symbols – anyone who has Rolled on Rails has seen “scaffold :recipe”. That’s just the tip of the iceberg. Rails uses symbols extensively across both ActionPack and ActiveRecord (and probably others I’m not familiar with). It’s a great approach, but one that’s unique to Ruby as far as I’m aware.

Language Features I Wish C# Had – Tuples

Several languages, such as Python, have the concept of a Tuple built into the lanugage. One of things it’s used for in Python is multiple return values. So you can call “return x,y” to return two values. Of course, C# can only return one. If you need to return more values, you have to define out parameters.

LINQ / C# 3.0 / VB 9 support the idea of anonymous types, which is similar to a tuple. The big difference is that, because they’re anonymous, they can’t leave the scope they’re defined in. In other words, they’re great within a function, but if you want to pass them out of your function type-safely, you have to define a non-anonymous type for them.

Interestingly enough, F# supports tuples, though it a bit of a hack. Since the CLR doesn’t support tuples, F# basically defines different Tuple classes for up to seven tuple parameters (i.e. Tuple<t1,t2,t3,t4,t5,t6,t7>), For .NET 1.x, it’s even worse – they have to define different type names (Tuple2, Tuple3, etc). Ugh.

Update: Robert Pickering pointed out that F#’s tuple implementation is entirely transparent inside of F#. He’s right – I was writing from the perspective of a C# developer using F#’s implementation of tuples. Maybe I need to be looking closer at F#?