0% found this document useful (0 votes)
5 views

Cheatsheet Generator

The document outlines the phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It describes various parsing techniques, such as top-down and bottom-up parsing, along with optimization methods like peephole optimization and left recursion elimination. Additionally, it touches on code linking and assembly, detailing the process of converting source code into executable machine code.

Uploaded by

j7g4n8iwtf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Cheatsheet Generator

The document outlines the phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It describes various parsing techniques, such as top-down and bottom-up parsing, along with optimization methods like peephole optimization and left recursion elimination. Additionally, it touches on code linking and assembly, detailing the process of converting source code into executable machine code.

Uploaded by

j7g4n8iwtf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

6/21/24, 9:44 PM Cheatsheet Generator

1. Compiler 2. Top-Down . Peephole 4. DAG 5. Left 6. Leading & 7


Design & Bottom- Optimization (Directed Recursion & Trailing
Phases A Up Parsing A technique Acyclic Left These terms
compiler (Complete in the code Graph) A Factoring are used in
translates Numerical) optimization Directed Left context-free
source code Parsing phase where Acyclic Recursion: A grammars,
written in a involves small sets of Graph is grammar is especially in
high-level analyzing a adjacent used in left- parser
programming string of instructions compiler recursive if construction.
language to a symbols, (a "peephole" optimization a non-
Leading: The set of
lower-level conforming of code) are to represent terminal has
terminals that can
language or to the rules examined expressions. itself as the
appear at the
machine of a formal and replaced It helps in leftmost
beginning of strings
code. The grammar. with shorter eliminating symbol in
derived from a non-
process or faster common one of its
Top-Down Parsing: terminal. Trailing: The
involves sequences if sub- productions.
Constructs the parse set of terminals that
several possible. expressions This can
tree from the top can appear at the end
phases: Examples and in cause issues
(start symbol) down of strings derived from
include: detecting in top-down
Lexical Analysis: to the leaves a non-terminal.
redundant parsers.
Converts the source (terminals). Example: Constant calculations. Attribute
code into tokens. Recursive Descent Folding: Example: A -> Aα | β synthesiz
Tokens are sequences Parsing. Replace Nodes represent (left-recursive) (calculate
of characters with a operations operations or Elimination of Left children)
collective meaning (e.g., Recursive Descent on constants operands. Edges Recursion: Convert it (calculate
keywords, operators, Parsing: A hand- with their represent into a right-recursive parent an
identifiers). written parser where results. dependencies form. siblings).
each non-terminal in Strength between nodes. For (Syntax-D
Syntax Analysis: Uses the grammar is Reduction: example, the Example: A -> βA', A' - Translatio
the tokens to create a represented by a Replace expression a = b + c; > αA' | ε Left SDD by e
parse tree, ensuring the function. This costly d = b + c; can be Factoring: Refactor a semantic
code follows the method can handle operations represented as: grammar to remove within pr
grammar rules of the LL(1) grammars, with cheaper common prefixes, rules to d
programming which are grammars ones (e.g., css Copy code making it suitable for produce
language. that can be parsed replace predictive parsing. intermed
with one lookahead +
Semantic Analysis: multiplication Example: Given A -> target co
token. Bottom-Up with
Checks for semantic Parsing: Constructs / \ => / αβ | αγ, refactor to A -
errors, such as type addition). b c b c Both a and d > αA', A' -> β | γ.
the parse tree from
mismatches, ensuring Eliminating point to the same
the leaves (terminals)
that the syntax tree Unreachable node +, optimizing
up to the root (start
follows the rules of the Code: storage and
symbol). Example: Remove code
language (e.g., type Shift-Reduce Parsing. computation.
checking, variable that will
never be
binding). Shift-Reduce Parsing:
Uses a stack to shift executed.
Intermediate Code
input symbols and
Generation: Translates reduce them to
the syntax tree into an grammar rules until
intermediate the start symbol is
representation, which is achieved. Can handle
easier to optimize and a larger class of
translate into machine grammars (LR).
code. Numerical Example
(Bottom-Up Parsing
Code Optimization:
Improves the with Shift-Reduce):
Given grammar:
intermediate code to
make it more efficient, css Copy code S ->
focusing on reducing aABe A -> Abc | b B -
resource consumption > d Parse string:
(e.g., time, memory). abccde
Code Generation:
Steps:
Converts the optimized
intermediate code into

https://cheatsheet-generator.vercel.app 1/2
6/21/24, 9:44 PM Cheatsheet Generator
target machine code or Shift a (stack: a). Shift
assembly language. b (stack: ab). Reduce
b to A (stack: aA).
Code Linking and Shift c (stack: aAc).
Assembly: Combines Shift c (stack: aAcc).
code from multiple Reduce Acc to A
sources into a single (stack: aA). Shift d
executable and resolves (stack: aAd). Reduce
memory addresses. d to B (stack: aAB).
Shift e (stack: aABe).
Reduce aABe to S
(stack: S).

https://cheatsheet-generator.vercel.app 2/2

You might also like