On 2021-Jun-20, at 9:19 PM, ben via cctalk wrote:
On 2021-06-20 9:01 p.m., Brent Hilpert via cctalk
wrote:
On 2021-Jun-20, at 7:38 PM, ben via cctech
wrote:
On 2021-06-20 8:13 p.m., Toby Thain via cctech
wrote:
Tried the Shunting Yard algorithm? But watch out,
it was invented by a
quiche eater...
The problem needs backtracking to generate correct code. Stack or muilti-register
machines don't have this problem with temporaries.
Ben.
The parser generates a tree of the algebraic expression, the tree is
representative of the evaluation order of the expression, earlier evals lower in the tree,
the node at the top is the last evaluated. Then walk the tree from the bottom up to
generate code.
I think code to do this (efficient compiler code generation) has been done like a
gazillion-billion times since 1960.
Computer science people seem to like to brag about how to parse.
Whatever that means.
Walking a tree does not solve the tree was built in
the wrong order.
No. If the tree was built in the "wrong order", then you screwed up in writing
your parser.
There is no great difficulty in parsing into a tree representation which can be walked to
resolve your initial issue.
Parenthesis first implies input string re-scanning and
text movement.
Whatever that means.
You don't have to "move text" to accomplish this.
This what I can't seem to find a good algorithm
for.
In summary fashion, I told you how it's done.
If you don't understand state machines and parsing that's your problem.
As it is, you are running into the same issue a thousand minicomputer & microproc
manufacturers and designers ran into in the 60/70s: building and maintaining the support
ecosystem for a machine architecture is not trivial.
But I should know better than to bother.
FORTRAN II and IV did quite well before all this
computer science. FORTRAN solved real world problems, ALGOL has yet to have I/O. LISP
still can't be compiled.PASCAL is only educational problems, and C mutated into
Monster. JAVA is not open source.
Very little new stuff is on multi-pass parsing.I have a 70's computer design of
modest word length (20 bits) that needs 1970's computer science, and 64KB of memory
and removable disks.
Ben.