Skip navigation.

exploreopera

| Help

Sign up | Help

There is no spoon

It is not the spoon that bends, it is only yourself

Posts tagged with "DSL"

DSL Implementation: ANTLR or custom code?

, , , ...

I've started this week to work on a DSL implementation. It was already designed, reviewed and I had a pretty good idea of what I want from it but I still had problems doing it. This shows once again that defining and implementing programming languages is a difficult task, even it the language is very simple, well defined and allows simple parsing.

The first approach was to use ANTLR for defining the language. It is a very natural language for defining languages, plus it has the advantage of providing a GUI for defining, validating and testing the language.

Unfortunately, despite all its advantages, it has a few problems.
For starters, I didn't manage to automatically skip white spaces, even if I tried all the methods from the documentation, forums and blogs.

The second problem is that there's no simple way to match the start and end of line in the parser. It's true that the language is not meant to be used for line-by-line parsing, but it's a nice to have feature, since it's needed in most programming languages.

I tried to work around those issues, but I found that there were matching problems, due to whitespaces and empty statements. So, in the end, I decided to stop using it and start writing the parser code in C#. About four hours later, I had the parser done, except for complex expressions.

Even if it turned that way, I don't think trying ANTLR was a waste of time. It allowed me to define in my mind a detailed model of the language. I don't think that writing the code in C# from the first place would have given the same results.

Anyway, now I'm fighting with expressions. They are slightly more difficult to parse, but I think I have the solution.


Personal advertisement: I am PassionIT and I help teams develop high quality software. I train, I help improving and I work hands-on, depending on the needs. Contact me if you need help.
Alexandru Bolboaca-Diaconu



Add to Technorati Favorites  Digg!