Presentation is loading. Please wait.

Presentation is loading. Please wait.

Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.

Similar presentations


Presentation on theme: "Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany."— Presentation transcript:

1 Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany

2 Overview Context free grammars Pushdown Automata Equivalence of PDAs and CFGs Non-context free grammars –Pumping lemma

3 Context free languages Extend regular languages First studied for natural languages Often used in computer languages –Compilers –Parsers Pushdown automata

4 Key Concepts

5

6

7 Definition Context free grammar

8 Parsing –Construct meaning (parse tree)

9 Constructing CFGs As the union of simpler CFGs

10 Constructing CFGs When given a DFA

11 Constructing CFGs Languages consisting of “linked” strings

12 Constructing CFGs Strings that may contain structures that appear recursively as part of other (or the same) structures

13 Ambiguity If generates the same string in several wasy, then the grammar is ambiguous E.g. Grammar does not capture usual precedence relations One of the main problems in natural language processing “the boy touches the girl with the flower”

14

15 Defining ambiguity Leftmost derivation : –At every step in the derivation the leftmost variable is replaced A string is derived ambiguously in a CFG if it has two or more different leftmost derivations A grammar is ambiguous if it generates some string ambiguously Some context free languages are inherently ambiguous, ie. every grammar for the language is ambiguous

16 Chomsky Normal Form

17

18

19

20

21 Pushdown automata Schema of a finite automaton

22 Pushdown automaton Includes a stack –Push something on top of stack –Pop something from top of stack –Last in first out principle –As in cafeteria – tray

23 An example PDA

24 Formal definition

25

26 Computation with PDAs

27

28 Another example Non determinism essential for this language

29 Another example

30 A CFL accepts a string if there exists a derivation of the string Involves intermediate strings Represent intermediate strings on PDA

31 Substitute variables by strings Replace top variable by string

32

33 Resulting PDA

34 A construction to substitute variable by a string

35

36

37

38

39

40

41

42

43 Pumping lemma

44

45

46

47

48 Overview Context free grammars Pushdown Automata Equivalence of PDAs and CFGs Non-context free grammars –Pumping lemma


Download ppt "Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany."

Similar presentations


Ads by Google