Chapter 9. Syntax Analysis. Contents. Context free grammars Top-down parsing Bottom-up parsing Attribute grammars Dynamic semantics Tools for syntax analysis Chomsky’s hierarchy. The Role of Parser. 9.1: Context Free Grammars.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
*
*
*
*
+
*
SEG2101 Chapter 9
+
+
SEG2101 Chapter 9
EEAE|(E)|-E|id
A+|-|*|/|
E-E-(E+E)-(id+E)-(id+id)
We write E-(id+id)
*
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
A A’
A’A’|
A1A’|2A’|…|nA’|
A’1A’|2A’|… mA’|
+
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
Grammar:
Input string
w = cad
SEG2101 Chapter 9
ScAd
AaA’
A’b|
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
*
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
FIRST()FIRST()=
FIRST(FOLLOW(A))FIRST(FOLLOW(A))=
*
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
“synch” indicating synchronizing tokens obtained from FOLLOW set of the nonterminal in question.
If the parser looks up entry M[A,a] and finds that it is blank, the input symbol a is skipped.
If the entry is synch, the the nonterminal on top of the stack is popped.
If a token on top of the stack does not match the input symbol, then we pop the token from the stack.
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
Grammar for expression
Can be rewritten as
With the precedence relations inserted, id + id * id can be written as:
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
<bin_num> 0
| 1
| <bin_num> 0
| <bin_num> 1
SEG2101 Chapter 9
9.6: Tools for Syntax Analysis (YACC)
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9
SEG2101 Chapter 9