02-25-2021, 09:54 PM
Continuing from where I left off yesterday, I know how to generate the C++ code but interfacing to the parser is where I start to run into trouble. A fully implemented parser may not lend itself to the "stone soup" approach of adding pieces little by little.
One central portion is the expression parser. If it generates a parse tree, converting the expression to C++ format may be as simple as implementing a inorder traversal of the tree, even if it generates a lot of extra grouping symbols. Complications include function calls because our non-structured call-stack will need some extra work to produce inline results from the equivalent of preloading local variables into a class structure and invoking the equivalent of a Gosub and having a temporary variable to copy the returned value into before executing a Return command. Perhaps passing a pointer to the result variable into the subroutine will work.
One central portion is the expression parser. If it generates a parse tree, converting the expression to C++ format may be as simple as implementing a inorder traversal of the tree, even if it generates a lot of extra grouping symbols. Complications include function calls because our non-structured call-stack will need some extra work to produce inline results from the equivalent of preloading local variables into a class structure and invoking the equivalent of a Gosub and having a temporary variable to copy the returned value into before executing a Return command. Perhaps passing a pointer to the result variable into the subroutine will work.