160 likes | 458 Views
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. Linear grammars. It is not a linear grammar. S. a. A.
E N D
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
S a A B b b B B b b 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 The root is labeled S. a A B Each interior vertex has a label from V. b b B B b b 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:
To check if w is a member of L(G), we use the exhaustive search parsing method. It is a form of top-down. 5.2Parsing and Ambiguity Parsing and Membership
S S S a a a a S S S S b b b b Ambiguity in grammars and languages S
E E E * E E + E I I E E * + E E a b a c I I I I c b
. Example if-then-else statement can be defined by context-free grammar as <if_statement>::=If<expression><then_clause><else_clase>. 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. A programming language has two aspects: syntax and semantics. Related to context-free grammar.
Initial state Initial state Finite Automata Stack Input file Input file … … Control unit (transition function δ) Control unit (transition function δ) Chapter 7 Pushdown Automata Pushdown Automata
Definition 7.1 A nondeterministic pushdown accepter or npda is defined by the septuple
* Context-free Language and Pushdown Automata Theorem 7.1 For any context-free language L, there is an npda M such that L = L(M).