tags:

views:

246

answers:

1

We have been using regex for our grammar requirement. However there are about 20+ patterns that needs to be supported and maintaining RegEx has become very difficult when the patterns started becoming recursive. We tried migrating to ANTLR, and looked at the following two critical points required for us.

Performance Performance seems to be a concern whens some of the expressions were migrated. RegEx with compiled assembly is about 2x or 3x faster for some expressions.

Manageability ANTLR grammar seems to be lot easier to manage and develop. Accomodating new expressions/constructs was much simpler than RegEx.

Did anybody have similar experience of such a migration. Should we look at it or work with RegEx?

A: 

ANTLR's performance is heavily dependent on the grammar style you use - especially the placement and contents of predicates. After that, the recursive-descent grammars generated by ANTLR tend to suffer progressively based on the number of operators available in your expressions¹, but there are solutions available. Once you are familiar with ANTLR, you should definitely find it more maintainable for "significant sized tasks" than regular expressions. However, getting up and running is not the simplest of tasks right now. What language/IDE are you using?

¹ Talking strictly performance here. The recursive-descent parsers shine when it comes to understanding the generated code.

280Z28
We are using .NET completely and Visual Studio 2008 as the development environment. Context of the expressions will be more towards supporting various expressions (math, database like functions, custom functions etc.). We are at a point where, expressions have become nested and its getting really out of hand.