4 ms·
> why use a concrete syntax tree at all? Do you mean instead of an AST? I find the syntax tree better for non-compiler applications like translators.
by parrt 10y ago
> why use a concrete syntax tree at all?
Do you mean instead of an AST? I find the syntax tree better for non-compiler applications like translators.
- chubot 10y agoMy claim is that neither the parse tree/CST or AST is good for applications like translators. Instead I defined another term Lossless Syntax Tree, which is the data structure I want: http://www.oilshell.org/blog/2017/02/11.html http://www.oilshell.org/blog/2017/02/11.html I researched "production" implementations, and found that they use something like a Lossless Syntax Tree (not an AST or CST): https://github.com/oilshell/oil/wiki/Lossless-Syntax-Tree-Pattern https://github.com/oilshell/oil/wiki/Lossless-Syntax-Tree-Pa... Examples: Clang, Microsoft's Roslyn platforms, RedBaron/lib2to3 for Python, scalameta, and Go. The defining property of the LST is that it can be round-tripped back to the source. This is called out in this C# design doc, along with some conventions for associating whitespace with syntax tree nodes: https://github.com/dotnet/roslyn/wiki/Roslyn-Overview https://github.com/dotnet/roslyn/wiki/Roslyn-Overview What do you think of that claim? (If you prefer not to use this deep comment thread, feel free to contact me by e-mail instead at andychup@gmail.com.)