Week 9 Day 1 And 2 Flashcards
Concrete Syntax Tree
Rooted, directed graph that contains no cycles
- start to terminals where: start is the roots, terminal is the leaves, interior nodes are nonterminals
What kind of representation for Concrete Syntax Tree?
Graphical IR
Concrete Syntax Tree Pros
- Faithful representation of the original parse of the source code
- Perfectly represents all of the production rules when parsing - Since its a tree, there are a lot of algorithms for it
- They are primary IR for attribute grammar systems
Concrete Syntax Tree Cons
- Large
- Contains unnecessary information
- Requires careful consideration of implementation
Abstract Syntax Tree (AST)
Concrete parse tree with many details abstracted away
- Nonterminal nodes are typically replaced by the terminal they map to
What representation for Abstract Syntax Tree (AST)?
Graphical IR
Abstract Syntax Tree (AST) Pros
- Smaller than a CST
- Retains essential structure of the source code (precedence)
- sometimes collapses to a binary tree
Abstract Syntax Tree (AST) Cons
- Still near source level
- requires careful consideration for implementation
Directed Acyclic Graph (DAG)
A directed graph with no cycles
- represents POSET
- nodes represented repeated values or subexpressions are combined
What representation is DAG?
Graphical IR
DAG Pros
- smaller than AST
- captures redundancies and some dead branches in local code
DAG cons
- trickier to traverse than a tree
- still a graph, so implementation must be carefully considered
Post Fix Notation
Also called reverse Polish Notation
- every expression is writes with the operator at the “end” as in far right side
What representation is Post-Fix Notation
Linear IR
Post Fix Notation Pros
- concise representation
- easy to generate from bottom up parse
- easy to process using a stack based approach