3 ms·
I don't think you're using AST right. An abstract syntax tree in computer science is a lower level, barer representation than you seem to think. It is just the
by kazinator 8y ago
I don't think you're using AST right. An abstract syntax tree in computer science is a lower level, barer representation than you seem to think. It is just the raw syntax, without surface details.
A "parse tree" still has the commas, semicolons and parentheses and whatnot: all the tokens that appear in the BNF. The nodes in the parse tree correspond to the nonterminal symbols in the grammar, and the leaves are the tokens.
An "abstract syntax tree" is just the next level which abstracts away from those details. There are no more nonterminal and terminal symbols, but some sort of logical units. Lisp's abstract syntax tree is the object structure from the reader: the parentheses, consing dots, and other details are gone.
https://en.wikipedia.org/wiki/Abstract_syntax_tree https://en.wikipedia.org/wiki/Abstract_syntax_tree pretty much nails it.
The further processing of the AST where it is transformed into some much more semantically annotated tree or something else entirely is the "intermediate representation", IR.
- lispm 8y agoSee the example picture in the article. Lisp s-expressions have no concept like 'variable name: a'. The s-expressions simply does not represent that some symbol is a variable. In an AST this is common. In an AST the elements are already classified according to some syntax. In S-expressions this is not the case.