Blog Home  Home Feed your aggregator (RSS 2.0)  
Compiler tools for .NET - Manuel Abadia's ASP.NET stuff
 
# Friday, November 10, 2006

I have been playing lately with compiler generators and related stuff for something I’m working on. I had to re-read some parts of the dragon book (my memory is pretty bad) and I also found out that a new edition of the dragon book was released this year:

The best tool I have found is ANTLR. It is completely free, it can generate a lexer, a parser and a tree parser, so it can be used to generate all the needed stuff without having to use different tools. It supports C#, Java, C++ and Python. Also, it generates descendant recursive parsers so the code generated can be understood by a human (no more transition tables like yacc/bison). Even if predictive top down parsers can not handle all the context free grammars, this one supports pred-LL(k) grammars (LL(k) means Left to right Left most derivation with k tokens of lookahead, and the pred prefix means that it supports predicates to see if a rule has to be applied or not) with backtracking so it is really powerful.

The latest version (v3) is still in beta but it has some nice improvements over v2 so that’s the one I’m using. For v3 there isn’t much documentation so the learning curve is a bit high but it seems worth the effort. IMHO one of the bests things of ANTLR is that it has a great development IDE called ANTLRWorks that is amazing. Just look at this screenshots I took of some C# 2.0 grammar tests I did:










You have real time error checking, you can see a syntax diagram of the current rule, you can view the generated parse tree, debug the grammar, see rules dependencies, the DFA for the tokens, automatically remove left recursion from rules… awesome!

If you are wondering if ANTLR is good enough for you, think that JetBrains (the company that created ReSharper) uses it.

Enough talking, back to ANTLR…

Friday, November 10, 2006 12:06:09 AM (Romance Standard Time, UTC+01:00)  #    Comments [2]   ANTLR | Microsoft .NET Framework  | 
Monday, May 28, 2007 8:12:10 PM (Romance Daylight Time, UTC+02:00)
Hi

I browsed through this article, and I wanted to know if you might have a complete C# 2.0 Antlr grammar you would like to share, and send me?

Bjørnar
Bjørnar
Tuesday, May 29, 2007 9:36:34 AM (Romance Daylight Time, UTC+02:00)
Bjørnar,

I just played a bit with a few c# 2.0 productions based on the c# 2.0 specs, but in any way it was a complete grammar (I think I didn't do more than 10-15% of the rules). If you still want what I did let me know.
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview
Copyright © 2020 Manuel Abadia. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.