... | ... | @@ -46,10 +46,8 @@ Both `if_single_line` and `if_multi_line` and both grammars (i.e., 4 combination |
|
|
|
|
|
The parse tree is the most detailed tree which corresponds 1:1 with how exactly the code is written (usually it ignores white space, but that's about it). AST on the other hand is the most abstract tree that ignores as much about the code as it can, the only condition is that the code generated from AST, while inevitably different from the original code, must produce exactly the same results as the original when compiled by some compiler that correctly implements the language. An AST however is still able to represent different algorithms that produce the same results, such as array vs element-wise operations. In other words, AST abstracts equivalent syntax, but not equivalent algorithms.
|
|
|
|
|
|
Examples of parse trees and ASTs:
|
|
|
Some examples of parse trees and ASTs:
|
|
|
|
|
|
For Python: [parse tree](https://docs.python.org/3/reference/grammar.html) and [AST](https://docs.python.org/3/library/ast.html#abstract-grammar).
|
|
|
|
|
|
For C: [parse tree](https://www.lysator.liu.se/c/ANSI-C-grammar-y.html) and [AST](https://www.cs.utah.edu/flux/flick/current/doc/guts/gutsch6.html).
|
|
|
|
|
|
For Fortran: [parse tree](http://docs.cray.com/books/007-3694-003/html-007-3694-003/faxalchri.html) (see also the Appendix D in the [Fortran 2008 Standard](http://www.j3-fortran.org/doc/year/10/10-007.pdf) for another parse tree) and [AST](). |
|
|
\ No newline at end of file |
|
|
* Python: [parse tree](https://docs.python.org/3/reference/grammar.html) and [AST](https://docs.python.org/3/library/ast.html#abstract-grammar).
|
|
|
* C: [parse tree](https://www.lysator.liu.se/c/ANSI-C-grammar-y.html) and [AST](https://www.cs.utah.edu/flux/flick/current/doc/guts/gutsch6.html).
|
|
|
* Fortran: [parse tree](http://docs.cray.com/books/007-3694-003/html-007-3694-003/faxalchri.html) (see also the Appendix D in the [Fortran 2008 Standard](http://www.j3-fortran.org/doc/year/10/10-007.pdf) for another parse tree) and [AST](). |
|
|
\ No newline at end of file |