Week 9 Day 1 And 2 Flashcards

1
Q

Concrete Syntax Tree

A

Rooted, directed graph that contains no cycles
- start to terminals where: start is the roots, terminal is the leaves, interior nodes are nonterminals

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

What kind of representation for Concrete Syntax Tree?

A

Graphical IR

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

Concrete Syntax Tree Pros

A
  1. Faithful representation of the original parse of the source code
    - Perfectly represents all of the production rules when parsing
  2. Since its a tree, there are a lot of algorithms for it
  3. They are primary IR for attribute grammar systems
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Concrete Syntax Tree Cons

A
  1. Large
  2. Contains unnecessary information
  3. Requires careful consideration of implementation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Abstract Syntax Tree (AST)

A

Concrete parse tree with many details abstracted away
- Nonterminal nodes are typically replaced by the terminal they map to

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

What representation for Abstract Syntax Tree (AST)?

A

Graphical IR

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

Abstract Syntax Tree (AST) Pros

A
  • Smaller than a CST
  • Retains essential structure of the source code (precedence)
  • sometimes collapses to a binary tree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Abstract Syntax Tree (AST) Cons

A
  • Still near source level
  • requires careful consideration for implementation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Directed Acyclic Graph (DAG)

A

A directed graph with no cycles
- represents POSET
- nodes represented repeated values or subexpressions are combined

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

What representation is DAG?

A

Graphical IR

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

DAG Pros

A
  • smaller than AST
  • captures redundancies and some dead branches in local code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

DAG cons

A
  • trickier to traverse than a tree
  • still a graph, so implementation must be carefully considered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Post Fix Notation

A

Also called reverse Polish Notation
- every expression is writes with the operator at the “end” as in far right side

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

What representation is Post-Fix Notation

A

Linear IR

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

Post Fix Notation Pros

A
  • concise representation
  • easy to generate from bottom up parse
  • easy to process using a stack based approach
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Post Fix Notation Cons

A
  • strange to read
  • needs careful management of stack
17
Q

Three address code (TAC)

A
  • resembles assembly for modern machines
  • 4-Tuple = (O, D, S1, S2)
18
Q

What representation is TAC?

A

Linear IR

19
Q

Three-address Code Pros

A
  • compact and concise
  • near target representation
  • highly amenable to optimization
20
Q

Three Address Code Cons

A
  • requires careful consideration of the namespace for operations and memory
  • initial start is highly unoptimized and bloated
  • user more abstract registers than physical registers available
21
Q

Intermediate Languages

A

Front end of a compiler translates the source code program into another language that isn’t the assembly or machine code of the target machine
- C, LLVM (any existing programming language)

22
Q

Intermediate languages Pros

A
  • completely decouples the front and back ends
  • has interpreter or compiler
  • useful for debugging
23
Q

Intermediate Languages Cons

A
  • if language paradigm is sufficiently different than the IR language, translation will be more complicated
  • depending on the tooling and environment of whichever IR language you choose
24
Q

Semantic Analysis

A

The phase of the compiler that checks the source program for semantic consistency with the language of the definition

25
Q

Jobs of semantic analyzer

A

Type checking, type coercion/conversion, variable declaration, access control, scope checking, function parameter count and consistency

26
Q

Attribute

A

Is any quality associated with a programming construct which we represent with our grammar symbols

27
Q

Synthesized attribute

A

Of a nonterminal A at a parse-tree node N is directly defined by a semantic rule associated with the production of N. Production must feature A as the LHS ( the “head” of the production)

28
Q

Inherited attribute

A

For nonterminal B at a parse tree node N is defined by a semantic rule associated with the production at parent of N. The production must feature B in the RHS (the “body” of the production)

29
Q

Semantic Rule

A

Is a specification declaring which attributes or actions to associate with a given nonterminal