Roger that. I came to BNF through formal language and parsing study, especially as I've always had a big interest in natural language parsing. I also had to get to know it better when I implemented language support for several languages in one of the commercial program editors. Writing a full-blown parser using just regexes would be something of a beast, but it's really pretty trivial for a simple input filter. The only thing that makes regular expressions frightening for most people is the difficulty of reading complex expressions. Well, and you do have to know how they work at a fairly basic level to avoid surprises (and to understand just
why certain expressions even exist). What I guess I'm trying to say is that once you've learned it, and admittedly, it has a pretty steep learning curve (verging on asymptotic, it seemed at times
), it's easy to use in lots of situations. For example, the expression
looks pretty beastly, for all that it's pretty short, but once you come to terms with the specific subexpressions it's using, you can see what it does. I won't try to turn this into some kind of guessing game; it recursively finds matching pairs of parentheses in its input, a fairly useful and basic thing. Once you've done this sort of thing a lot, you'll have a pretty good library of such snippets you can reuse. In fact, I reused that one by going into the editor I mentioned and snagging it from the program's repository of such expressions. A good book on regexes is
Mastering Regular Expressions on the O'Reilley imprint.
I came to Chomsky sometime in the late 1970's when I picked up
Aspects of the Theory of Syntax on a whim. It's been interesting to see all the changes in his theory over the years. I didn't learn BNF or any sort of EBNF from him, though, but from compiler books. Holub's
Compiler Design in C is a particularly readable one, especially compared to the Dragon books.
But I digress...and digress...and digress...wups, time to pop stack!
Reid