Download presentation
Presentation is loading. Please wait.
Published byLucinda Simpson Modified over 8 years ago
1
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules
2
Example Grammar :
3
Definition: Context-Free Grammars Grammar Productions of the form: String of variables and terminals VariablesTerminal symbols Start variable Variable
4
Leftmost derivation: Rightmost derivation:
9
Derivation Tree
10
yield Derivation Tree
11
Simplifications of Context-Free Grammars
12
Example
13
Normal Forms for Context-free Grammars
14
Chomsky Normal Form Each productions has form: variable or terminal
15
Introduce variables for terminals:
16
Introduce intermediate variable:
18
Final grammar in Chomsky Normal Form: Initial grammar
19
Then, for every symbol : In productions: replace with Add production New variable:
20
Replace any production with New intermediate variables:
21
Greinbach Normal Form All productions have form: symbolvariables
22
Pushdown Automata PDAs
23
Pushdown Automaton -- PDA Input String Stack States
24
The States Input symbol Pop symbol Push symbol
25
top input stack Replace
26
Push top input stack
27
Pop top input stack
28
No Change top input stack
29
Pop top input stack Empty Stack empty The automaton HALTS No possible transition after
30
Pop top input stack A Possible Transition
31
Non-Determinism PDAs are non-deterministic Allowed non-deterministic transitions
32
Formalities for PDAs
33
Transition function:
35
Formal Definition Pushdown Automaton (PDA) States Input alphabet Stack alphabet Transition function Final states Stack start symbol Initial state
36
Instantaneous Description Current state Remaining input Current stack contents
37
A computation:
38
Deterministic PDAs - DPDAs
39
Deterministic PDA: DPDA Allowed transitions: (deterministic choices)
40
Allowed transitions: (deterministic choices)
41
Not allowed: (non deterministic choices)
42
PDAs Have More Power than DPDAs
43
Positive Properties of Context-Free languages
44
Context-free languages are closed under: Union is context free is context-free Union
45
Context-free languages are closed under: Concatenation is context free is context-free Concatenation
46
Context-free languages are closed under: Star-operation is context freeis context-free Star Operation
47
Negative Properties of Context-Free Languages
48
Context-free languages are not closed under: intersection is context free not necessarily context-free Intersection
49
Context-free languages are not closed under: complement is context freenot necessarily context-free Complement
50
Intersection of Context-free languages and Regular Languages
51
The intersection of a context-free language and a regular language is a context-free language context free regular context-free
52
An Application of Regular Closure Prove that: is context-free
53
Decidable Properties of Context-Free Languages
54
Membership Question: for context-free grammar find if string Membership Algorithms: Parsers Exhaustive search parser CYK parsing algorithm
55
Empty Language Question: for context-free grammar find if Algorithm: 1.Remove useless variables 2.Check if start variable is useless
56
Infinite Language Question: for context-free grammar find if is infinite Algorithm: 1. Remove useless variables 3. Create dependency graph for variables 4. If there is a loop in the dependency graph then the language is infinite 2. Remove unit and productions
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.