Please enable JavaScript.
Coggle requires JavaScript to display documents.
(Compiler) - Coggle Diagram
Compiler
Phases
Syntax Analysis
Handle
Definition
A handle of a right sentential form ‘γ’ (γ=αδβ) is a production E→δ and a position in γ where δ can be found and substituted by E to get the previous step in the right most derivation of γ — previous and not “next” because we are doing rightmost derivation in REVERSE
Handle is a substring of a given input string which matches any production rule in the right hand side and reduces the left hand side of production in right most derivation(reverse manner)
-
-
Types
Bottom Up Parsing
Shiftreduce parsing
Types
-
LR(k) parsers
-
Viable prefix
- 3 more items...
-
-
-
Conflicts
-
Reduce-Reduce Conflict
A reduce/reduce conflict occurs if there are two or more rules that apply to the same sequence of input. This usually indicates a serious error in the grammar.
In general, bottomup parsing algorithms are more powerful than topdown methods,but not surprisingly, the constructions required are also more complex
-
Top Down Parsing
LL(k) grammars
-
-
-
Most used sub-classes
Simple LL(1)
-
That means, for a particular NT, each alternative rule starts
with different Terminal symbols
-
a i ∈ V T and α i ∈ (V T ∪ V N )*, A ∈ V N
-
LL(1) without ε-rules
We extend the simple LL(1) parser, by removing the restriction that the first symbol on the RHS be in V .t
Such grammars are as much powerful, no more no less, as the Simple LL(1) grammars
-
-
-
Parsing Function
- 2 more items...
LL(1) with ε-rules
-
-
-
LL(1) Grammar
- 3 more items...
Parsing Function
- 2 more items...
-
Can be parsed deterministically, i.e. without backtracking, by LL(k) methods
-
Analyze the stream of (tokens, value) pairs and find language syntactic constructs, like
ASSIGNMENT, IF-THEN-ELSE, WHILE, FOR, etc
-
Reduced Grammars
Redundancies
redundant NT, which does not generate any Terminal string
-
-
-
-
-
I/O
-
Output
Parse Tree
-
-
While reading yield from left to right, sentence of the grammar can be generated
Optimization
-
-
Basic Blocks
Properties
-
Does not contain any other labels, Jumps or Conditional Jumps
-
-
Flow Graphs
The concept of Basic Blocks is used to form what is known as Flow-graphs, wherein they appear as nodes
-
-
-
-
Data-flow analysis derives information about the dynamic
behavior of a program by only examining the static code
Liveness Analysis
A variable is live at a particular point in the program if its value at that point will be used in the future (dead, otherwise).
To compute liveness at a given point, we need to look into the future
CFG
A CFG is a graph whose nodes represent program statements and whose directed edges represent control flow
-
Liveliness
-
Data-flow
-
Direction of Flow
Liveness flows backwards through the CFG,
because the behavior at future nodes
determines liveness at a given node
-
-
-
-
-
Lexical Analysis
Usually,
these tokens are internally denoted by small
integers, e.g. 257 for NUMBER, 258 for
IDENTIFIER, 259 for OPERATOR, etc
Analyze individual character sequences
and find language tokens, like NUMBER,
IDENTIFIER, OPERATOR, etc
Lexical tokens are generally defined as
regular expressions (RE), for example:
NUMBER = [+|-]d*[.]d+
Send a stream of pairs (token-type, value) for
each language construct, to the Parser
-
-
-
Code Generation
-
Notation
-
Reverse Polish Notation
-
-
-
Extended RPN(ERPN)
We extend it to deal with programming control constructs also so that we can use it to represent Intermediate code
-
-
Semantic Analysis
It converts or maps syntax trees for each construct into a sequence of intermediate language statements
-
-
Runtime Environments
Activation
-
Activation Tree
-
-
-
The node for procedure ‘x’ is the parent of node for procedure ‘y’ if and only if the control flows from procedure x to procedure y
Activation Record
Information needed by a single execution of a procedure is managed using an activation record or frame
When a procedure is called, an activation record is pushed into the stack and as soon as the control returns to the caller function the activation record is popped
-
-
-
-
-