On Jun 21, 2021, at 5:23 AM, ben via cctalk <cctalk
at classiccmp.org> wrote:
...
I want to transformatiom before full parsing expressions, as a text process.
string "a+(b+c)*c" becomes "((b+c)*c)a+".
As an academic exercise that's pretty trivial. But why would you want to do that?
Apparently some people think that this is how you create expression parsers, but that
isn't actually a useful or necessary approach. It's entirely trivial to do a
sequential scan over the expression tokens and produce corresponding code, in one pass
without backtracking or text manipulation.
BTW, on code generation: it's true that this is complex, and a still evolving field,
if you consider optimization. But a straightforward code generator fed by the parse tree
isn't very hard, and requires no great magic. I still have the one I wrote in
compiler class back in 1976; it took a week of work and that included learning Pascal and
linked lists.
paul