Theory, examples of reversible parsers?

前端 未结 11 1183
滥情空心
滥情空心 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:32

    The "Visitor Pattern" idea is good. But, I should consider "Visitor" pattern as a lineal list pattern, or, as a generic pattern, and add patterns for more specific cases like Lists, Matrices, and Trees.

    Look for a "Hierarchical Visitor Pattern" or "Tree Visitor Pattern" on the web.

    You have a tree data structure ("Collection") and want to do something with the data, each time you "visit", "iterate" or "read" an item from the tree.

    In your case, you have a tree data structure, that represents the result of scanning/parsing some source code. Then you have read each item's data, and transform it into destination code.

提交回复
热议问题