[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] RecDescent, perhaps? math expression parsing



It's been a _way_ long time since I've written a recursive-descent
parser by hand, like (uurk) 17 years or so, but if the parser
implementation does a depth-first recursion on the first match, then
I think you want to re-order the elements in the recursive
definition to put all the more specific items first. Anything that
can be trivially distinguished based on punctuation I'd put up at
the top, and leave the messier ones that take a good bit of
look-ahead further on down.

Also, you want to guarantee that each recursion consumes something.
So when you've got a production like

	TERM ::= TERM OP_H TERM

then you need to rig the token stream so that the LHS recursion sees
only sees the first component term and the RHS recursion likewise
only sees the trailing tokens.

-Bennett

PGP signature