Trees and Abstract Syntax Flashcards
What 3 elements comprise a while loop (root, left, right)
Why use abstract syntax trees (ASTs)
- Don’t need to be concerned with quirks of individual syntax
- Focuses on the semantics
- Trees vs. strings
- Root determines output type
Write the following expression as an abstract syntax tree:
What does a while loop look like as an AST
What is the arity of a symbol in AST grammar
What are the 4 elements that comprise tree grammar
What do tree production rules look like
What do parenthesis mean when writing ASTs inline
Means it is a sub-tree
What does it mean for one symbol to have higher precedence than another?
Eg: 4+5*2
- That symbol ‘binds-tigher’, meaning it claims the element first.
- Can be considered as adding parenthesis
- 4+(5*2)
How is precedence ranked
By number (higher is tighter)
Why do languages define the association of operators
- To tell us where the missing parenthesis should go when we write an expression that includes adjacent operators of the same precedence.
- 3-2-1+0 = ((3-2)-1) + 1 OR 3 - ((2 -1) + 0) OR …
What does left association mean
- Place parenthesis to the left
- Assume left association unless told otherwise
What does right association mean
- Place parenthesis to the right
What does this AST grammar look like in-line