Search code examples
language-agnosticparsingcode-generationtheory

Theory, examples of reversible parsers?


Does anyone out there know about examples and the theory behind parsers that will take (maybe) an abstract syntax tree and produce code, instead of vice-versa. Mathematically, at least intuitively, I believe the function of code->AST is reversible, but I'm trying to find work/examples of this... besides the usual resources like the Dragon book and such. Any ideas?


Solution

  • Such thing is called a Visitor. Is traverses the tree and does whatever has to be done, for example optimize or generate code.