The expression twice f 1
is parsed as a pair of applications: first twice
is applied to f
, then that result is applied to 1
.
There is no token in the expression that corresponds to application, as application is just represented by juxtaposition (two tokens next to each other). That doesn't mean, though, that there is no node in the tree to represent application. So, we start with a root node that represents the act of applying:
apply
This node has two children; the thing being applied, which is another application, and the thing being applied to.
apply
/ \
/ \
apply value
/ \ |
/ \ number "1"
/ \
value value
| |
identifier identifier
"twice" "f"
The structure of the tree encodes the precedence of function application. If your expression were twice (f 1)
, there would be no parentheses explicitly stored in the tree; rather, the structure of the tree itself would change.
apply
/ \
/ \
value apply
| / \
identifier / \
"twice" / \
value value
| |
identifier number "1"
"f"
twice f 1
does not include the definition off
. It doesn't even matter whether any of the constituents have definitions; the tree fordingo koala wombat
has the same structure. – molbdnilo