Quoteing hgs / dmu.ac.uk, on Thu, Jan 27, 2005 at 02:08:04AM +0900:
> I seem to have run into my parsing problem again.  Whatever I'm
> doing I usually end up having to parse non-simplistic input, and I'm
> still not happy about the apparently available solutions to this.
> So I'm wondering what other people do.
> 
> The application is immaterial at the moment, but the problem is that
> I need to do more than can be done with a simple case statement, and
> if I were to use case statements managing the problem would get too
> big.
> 
> The conventional wisdom is to use some form of parser
> generator (Yacc, Bison, Racc, Rockit,...) but I don't have
> confidence in my ability to get these working well.[1].
> I have had great difficulty in the past, certainly.

snip

> [1] I find that thinking in the manner of a shift/reduce parser is
> particularly unnatural to me.  This might just be a weakness on my
> part or may have something to do with people's difficulties in
> handling modal interfaces: it is hard to switch contexts rapidly.
> Maybe there is something I can read which will turn the problem
> around, so it becomes easy to handle?

Hi Hugh.

Two suggestions:

Most of the docs for parser-generators assume some (lots?) knowledge of
compiler theory. An exception is the O'Reilly Lex&Yacc book. If any of
the generators you mention above is anything like Yacc, I think you
might like the book. Its at a practical level, it assumes you are a
competent programmer, you just haven't taken a compiler course. The
first few chapters got me up to speed very quickly (I think you develop
a calculator). After that, the example used is generating a
mini-language to specify curses screen layouts. I don't do any curses
stuff, but the examples were used to good effect.

I think that if you do this often, mastering one of these tools will be
a life skill you'll never regret! And yacc (or one of the others) is a
mini-language in its own right, always good to learn another.

On another track, I have deliberately NOT used these grammers when
parseing the BNF for internet email. In my experience, if you can write
the grammer down in BNF, its usually pretty easy to write a recursive
descent parser for it. It's a little tedious though, which is why all
the tools exist to generate the code for you...

Have fun,
Sam