Download presentation
Presentation is loading. Please wait.
Published byWilfrid Lamb Modified over 9 years ago
1
Chapter 5 Context-Free Languages Regular language are effective in describing certain simple patterns. But it is not enough to describe programming languages. Context-Free languages cover more complicated languages. Context free
2
Linear grammars
3
It is not a linear grammar.
4
Leftmost and Rightmost Derivations Definition5.2 A derivation is said to be leftmost if in each step the leftmost variable in the sentential form is replaced. If in each step the rightmost variable is replaced, we call the derivation rightmost. S ABa bBbbBb
5
Definition 5.3 Let G=(V,T,S,P) be a context-free grammar. An ordered tree is a derivation tree for G if and only if it has the following properties: S ABa bBb bBb The root is labeled S.Each interior vertex has a label from V.
6
5.2 Parsing and Ambiguity Parsing and Membership To check if w is a member of L(G), we use the exhaustive search parsing method. It is a form of top-down.
8
Ambiguity in grammars and languages S bSabSabSabSa S S S
9
E E+E IE*EaIcI E E*E E+EIbIbaIc
10
5.3 Context-free Grammars and Programming Languages Why we learn the theory of formal languages?----We use the theory to design programming languages and to design the interpreters and compiles for them. Example if-then-else statement can be defined by context-free grammar as ::=If. A programming language has two aspects: syntax and semantics. Related to context-free grammar. .
11
Control unit (transition function δ) … Input file Initial state Finite Automata Stack Control unit (transition function δ) … Input file Initial state Pushdown Automata Chapter 7 Pushdown Automata
12
Definition 7.1 A nondeterministic pushdown accepter or npda is defined by the septuple
13
Theorem 7.1 For any context-free language L, there is an npda M such that L = L(M). Context-free Language and Pushdown Automata *
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.