4 ms·
Implementing an evaluator for infix parenthesized arithmetic expressions, like "5*(1+2)+60", is a good starting point. You can begin with writing a tiny lexer
by stiff 8y ago
Implementing an evaluator for infix parenthesized arithmetic expressions, like "5*(1+2)+60", is a good starting point.
You can begin with writing a tiny lexer and a recursive descent parser that simply writes out the value of an expression that the user typed in. Then you can make it generate assembly for computing the expression instead (hardcoding some further assembly to print the result out at the end of the execution of the program), turning it into either a traditional compiler or a JIT compiler. Once you do that, it should not be too hard to see how to add variables and simple loops. This will already demystify things quite a bit and make further learning easier.
I specifically recommend implementing your own parser and generating assembly on your own, at least if your primary goal is learning. You could instead use an existing parser generator and e.g. a library for generating JVM bytecode, but those ready-made components are high level enough to turn it all into the usual exercise in plumbing libraries together, rather than a learning experience across many layers of the computing stack.