Please enable JavaScript.
Coggle requires JavaScript to display documents.
Compiler - Coggle Diagram
Compiler
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
- 9 more items...
-
DFA State Comparison
- 2 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
-
ai ∈ Terminal and αi ∈ (Terminal ∪ Non-Terminal )*, A ∈ Non-Terminal
-
LL(1) without ε-rules
We extend the simple LL(1) parser, by removing the restriction that the first symbol on the RHS be a terminal
Such grammars are as much powerful, no more no less, as the Simple LL(1) grammars
-
-
-
Parsing Function
- 2 more items...
LL(1) Table
- 2 more items...
Time Complexity
- 1 more item...
-
LL(1) with ε-rules
-
-
-
LL(1) Grammar Check
- 1 more item...
Parsing Function
- 2 more items...
-
-
Can be parsed deterministically, i.e. without backtracking, by LL(k) methods
Predictive parsing is possible only for the class of LL(k) grammars, which are the context-free grammars for which there exists some positive integer k that allows a recursive descent parser to decide which production to use by examining only the next k tokens of input
-
Types
Recursive Descent Parser
Types
Non-Backtracking
- 1 more item...
-
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
-
-
-
Local Optimization
-
-
Loop
Code Motion
Loop-invariant code consists of statements or expressions which can be moved outside the body of a loop without affecting the semantics of the program
Loop-invariant code motion (also called hoisting or scalar promotion) is a compiler optimization which performs this movement automatically.
-
-
-
-
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
-
-
-
-
-
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
Contains
-
-
-
Access link (optional)
An access link from record A points to the record of the closest enclosing block in the program. The chain of access links traces the static structure (think: scopes) of the program.
-
Control link (optional):
A control link from record A points to the previous record on the stack. The chain of control links traces the dynamic execution of the program.
-
-
-
Parameter Passing
-
-
Call by copy-restore is similar to call by reference except that the values of actual parameters are changed when the called function ends, unlike call by reference
-
-
Assembler/Linker/Loader
Assembler
The C compiler, compiles the program and translates it to assembly program (low-level language)
-
Linker
A linker tool is used to link all the parts of the program together for execution (executable machine code)
-
-
Attributes
Types
-
Inherited attributes
An attribute of a nonterminal on the right-hand side of a production is called an inherited attribute
The attribute can take value either from its parent or from its siblings (variables in the LHS or RHS of the production)
-
S-attributed SDT
If an SDT uses only synthesized attributes, it is called as S-attributed SDT
S-attributed SDTs are evaluated in bottom-up parsing, as the values of the parent nodes depend upon the values of the child nodes
-
L-attributed SDT
If an SDT uses both synthesized attributes and inherited attributes with a restriction that inherited attribute can inherit values from left siblings only, it is called as L-attributed SDT
-
-
-
If right sibling attribute is used, it is neither L attributed or S attributed