Comment by andai

2 days ago

Is that really the hard part? I figured that part out before I knew much programming: made a simple Excel type formula parser. (A horrible, horrible solution based around replacing strings and manually counting parentheses... but it worked!)

I never got much farther than that though, I've looked into making a compiler many times and got overwhelmed every time.

Good to know I wasn't alone in writing terrible expression parsers. Since I knew absolutely nothing about parsing, my parser/interpreter consisted of splitting on whitespace, followed by linear scanning to find the most high precedence operation, repeated until a single token remains (basically how a human would do it).

It's hard if:

1. You dont recognise the recursive nature of the problem,

Or

2. You don't recognise the stack-based nature in the problem (shunting yard algo, etc).

IOW, you did it the hard way :-).