Theory, examples of reversible parsers?

前端 未结 11 1281
滥情空心
滥情空心 2021-01-13 22:50

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. Mathematicall

11条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-13 23:22

    That sounds a lot like the back end of a non-optimizing compiler that has it's target language the same as it's source language.

    One question would be whether you require the "unparsed" code to be identical to the original, or just functionally equivalent.

    For example, would it be OK for the output to use a different indentation style than the original? That information wouldn't normally be stored in the AST because it's not semantically important.

    One thing to look at would be automatic code refactoring tools.

提交回复
热议问题