News for hackers. Stuff that matters.
Re:How Microsoft rewrote its C# compiler in C# and made it o... by Karliss on Tuesday February 11, 2020 @05:47PM (#22303817)
There is reason AST is called abstract syntax tree not just syntax tree. Many syntax details like parentheses or choice between alternative syntax forms are there only to avoid syntactic ambiguity, improve readability or historical reasons and don't affect the semantics or even error messages. It's not surprising for compiler authors to choose discarding some of the unnecessary information as early as possible to save memory.
Re:How Microsoft rewrote its C# compiler in C# and made it o... by ygra on Tuesday February 11, 2020 @06:19PM (#22304047)
Notable a lot of JavaScript AST libraries at least a while back omitted comments and whitespace, which is fine for writing a minifier, but horrible when trying to implement source code transformations.

What I really like about Roslyn's AST (and I guess TypeScript's looks about the same) is that all those details are put into Trivia; ignoring those is just passing one flag to the visitor; you don't have to be aware of how many different types of AST nodes there are that might be ignorable. It also means that each and every whitespace and comment belongs to a syntax token instead of being other nodes interleaved with the normal nodes. This helps keeping comments where they belong even after re-arranging code in the AST – something that, e.g. ReSharper is atrociously bad at.

Re:How Microsoft rewrote its C# compiler in C# and made it o... by lonelappde on Tuesday February 11, 2020 @07:05PM (#22304363)
It's called abstract syntax tree because the concrete syntax is not a tree, it's an list of characters. Not because it makes semantic-invariant transformations.
Re:How Microsoft rewrote its C# compiler in C# and made it o... by yatac42 on Wednesday February 12, 2020 @06:29AM (#22307939)
> It's called abstract syntax tree because the concrete syntax is not a tree, it's an list of characters.

It's called abstract syntax tree to distinguish it from parse trees (a.k.a. concrete syntax trees).