Trees and Abstract Syntax Flashcards

1
Q

What 3 elements comprise a while loop (root, left, right)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why use abstract syntax trees (ASTs)

A
  • Don’t need to be concerned with quirks of individual syntax
  • Focuses on the semantics
  • Trees vs. strings
  • Root determines output type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write the following expression as an abstract syntax tree:

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does a while loop look like as an AST

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the arity of a symbol in AST grammar

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the 4 elements that comprise tree grammar

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What do tree production rules look like

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What do parenthesis mean when writing ASTs inline

A

Means it is a sub-tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does it mean for one symbol to have higher precedence than another?
Eg: 4+5*2

A
  • That symbol ‘binds-tigher’, meaning it claims the element first.
  • Can be considered as adding parenthesis
  • 4+(5*2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is precedence ranked

A

By number (higher is tighter)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why do languages define the association of operators

A
  • 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 …
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does left association mean

A
  • Place parenthesis to the left
  • Assume left association unless told otherwise
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does right association mean

A
  • Place parenthesis to the right
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does this AST grammar look like in-line

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly