An Abstract Syntax Tree is a data structure that uses structure to eliminate parenthesis and other details of textual representation.
Operator precedence, a significant feature of textual representation, is, in the AST, encoded in the structure of the tree: whereas in textual form operator precedence is encoded using operator priority rules along with parenthesis to override (or even to emphasize) the standard rules.
To translate from AST back to textual representation is a form of code generation, or, some might call it pretty printing.
Naively, you'd generate all these binary operations textually enclosed within
() if you didn't have proper optimization to eliminate them, or understanding of operator precedence of the textual grammar.
So, your first tree example, would naively textually generate:
( ( a + ( b / c ) ) + d )
which when optimized for common operator precedence would allow for the removal of all the parenthesis.
Most interesting of the bunch is the lower left, because it requires
() in the textual representation that cannot be eliminated. However, in the tree form AST, as usual, no
() are required; the precedence override by
() in the textual representation to make the addition happen before the multiplication is now inherent and implicit in the structure of the tree and is thus no explicit
() are required in the AST form.
Have a look at (E)BNF, which is a common way of encoding a grammar (as text). Also see ANTLR, which is a parser generator tool that can parse LL(*) grammars (which are more powerful than of LALR(1) and LL(k) grammars.
An ETF grammar is a somewhat restricted expression of grammar in which there are limited levels of operator precedence, and in particular just sufficient levels of precedence to accommodate addition being lower precedence than multiplication along with
() allowed to override (or emphasize) the precedence. ETF, expression, term, factor, are effectively the three levels. Notice that
( E ), which is to say
F (high precedence) allows and any
E (low precedence) surrounded by
(), which allows the
() to override (e.g. raise) the precedence of the contained expression relative to the containing expression.
Let's also distinguish between parse trees and abstract syntax trees. Parse Trees (aka concrete syntax trees) manifest more nodes that correspond to the input syntax, i.e. the actually recognized productions in the grammar for a given input text in the languge. Thus for the lower left expression, you'd have a
() node in the tree immediately above the
+ operator (not to mention a whole lot more other stuff as well). By contrast, in AST form, these textual details are suppressed.