|
 |
scott wrote:
> I'm just curious, because I made a parser like this in C++ once (it was
> very hacky and basically just stepped along the string trying to
> identify what each byte was). Anyway, it worked ok for things like
> "-5*(4+2)" etc, but crashed with "-(4+2)". I guess the minus operator
> should be encoded as its own token and then let the parser sort out what
> it should do. Maybe I'll try a rewrite one day.
Yeah, this is one of the tricky edge-cases of expression parsing.
Operator precidence and unary/binary operators can get pretty ugly.
(Gets even harder if you want to report meaningful error messages if
there's an actua syntax error...)
Post a reply to this message
|
 |