views:

146

answers:

2

I'm writing a simple text-template language for a web application I'm writing (think google's ctemplate). When finished, it'll feature only a small number of possible actions, simple stuff like "evaluate and execute", "evaluate and print", "evaluate and escape html", "comment". I was thinking of hand writing the whole parser from scratch, but I started looking at parser generators like lex, flex and antlr. These seem like way more than I need for my simple syntax. So the question is, at what point is it practical to use a parser generator?

+5  A: 
msw
+1 for "Sooner rather than later"
LeonixSolutions
+2  A: 

On the one hand if you don't have experience with one of these tools, and you have the time, then perhaps this is a good opportunity to learn one for this use case. I would imagine that if you were experienced in these tools, you'd simply use them, much like many grab for a regex for many parsing tasks.

On the other hand, simple parsers aren't that hard to do, they aren't even that hard to maintain. I like writing them, and I typically reach out for them when the task needs one rather than a tool (but I'm not super familiar with the tools). In many cases I prefer a simple parser over regex, depending on the task.

Will Hartung