c++ - Advice on postfix-to-infix parsers -
i've come across proprietary stack-based scripting language looks simplified version of x86 asm.
i built stack-based linear parser language in c++ hope produce pseudo-c code make language lot easier read.
i've encountered @ least 1 serious issue feel has linear nature of parser... example, let's have following code:
push const int push const str call some_method pop const str pop const int return last return val
with current implementation, generate following:
retval = some_method(str, int) return retval
but following major pain:
return some_method(some_str, some_int)
when encounter instruction/opcode, aware of -variables- pushed onto stack, it...
what boils down can go postfix infix combination similar instructions (pushes + calls example), not multiple ones.
i unexperienced when comes language parsers go easy on me! suggestion?
what want symbolic execution. arrange have c++ representation of expressions, such as
class expression{...}; class stringconstant:public expression{...}; class functioncall:public expression{...};
then, make symbolic stack contain expression*
. when arrive at
return foo
compile to
cout<<"return "; foo_expr->print();
where each expression have appropriate (possibly recursive) print method.
edit: if there no return statement, need iterate on value stack, , perform ->print values haven't otherwise been consumed.
Comments
Post a Comment