Bottom up parsing
LECTURE 8
Bottom-up parsing is more general than
(deterministic) top-down parsing
And just as efficient
Builds on ideas in top-down parsing
Bottom-up is the preferred method
WHAT IS BOTTOM-UP PARSING?
Idea: Apply productions in reverse
Syntax Analysis
LECTURE 6
SYNTAX ANALYSIS
WHAT IS SYNTAX ANALYSIS?
After lexical analysis (scanning), we have a
series of tokens.
In syntax analysis (or parsing), we want to
interpret what those tokens mean.
Goal: Recover the structure described by that
LECTURE 7
REMOVING INDIRECT LEFT RECURSION
REMOVING INDIRECT LEFT RECURSION
Let any ordering of the nonterminals of G be
A1,.,Am,
we will remove indirect left recursion by
constructing an equivalant grammar G such
that
If Ai Aja is any production of G,
FINITE AUTOMATE
1
PATTERNS FOR TOKEN
digit [0-9]
digits digit+
Letter [A Z a-z]
If if
then ten
else else
Relop <|<=|=|<>|>|>=
Idletter(letter|digit)*
Numdigits+ (.digits+)?(E(+|-)?digits+)?
ws (blank|tab|newline)+
2
TRANSITION DIAGRAM
A transition diagram
LECTURE 5
CONSTRUCTION OF AN NFA FROM
REGULAR EXPRESSION
2
CONSTRUCTION OF AN NFA FROM REGULAR
EXPRESSION
Recursive construction
Base cases follow base case definitions of regular
expressions
: -NFA that accepts the empty string
a single state that is th
CS510
Compiler
Lecture 2
Phase Ordering of Front-Ends
Lexical analysis (lexer)
Break input string into words called tokens
Syntactic analysis (parser)
Recover structure from the text and put it in a parse tree
Semantic Analysis
Discover meaning (e.g
CS510
Compiler
Lecture 3
REMMEMBER
3
NFA
4
DFA
5
DFA
Is special case of NFA where:
There are no moves on input
For each state s and input symbol a , there exactly one edge out of
a labeled a.
6
DFA
Deterministic Finite Automata (DFA)
One transition
CS510
Compiler
Lecture 4
Syntax Analysis
What is Syntax Analysis?
After lexical analysis (scanning), we have a series of
tokens.
In syntax analysis (or parsing), we want to interpret
what those tokens mean.
Goal: Recover the structure described by that
Cairo University
Institute of Statistical Studies and Research
Computer Science Dept.
Cs510
Compiler
Sheet1
1.
Writearegularexpressiontodescribeinputsoverthealphabetcfw_a,b,cthat
areinsortedorder
2.
Writearegularexpressionforeachofthefollowingsetsofbinary