1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.

Slides:



Advertisements
Similar presentations
Context-Free Languages
Advertisements

1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
Grammars, constituency and order A grammar describes the legal strings of a language in terms of constituency and order. For example, a grammar for a fragment.
ISBN Chapter 3 Describing Syntax and Semantics.
CFGs and PDAs Sipser 2 (pages ). Last time…
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Costas Busch - RPI1 Grammars. Costas Busch - RPI2 Grammars Grammars express languages Example: the English language.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Courtesy Costas Busch - RPI
1 Grammars. 2 Grammars express languages Example: the English language.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Balanced Parentheses G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\}
Costas Busch - RPI1 Context-Free Languages. Costas Busch - RPI2 Regular Languages.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
Courtesy Costas Busch - RPI1 Context-Free Languages.
1 Reverse of a Regular Language. 2 Theorem: The reverse of a regular language is a regular language Proof idea: Construct NFA that accepts : invert the.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Chapter 3: Formal Translation Models
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Lecture 9UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 9.
Fall 2004COMP 3351 Context-Free Languages. Fall 2004COMP 3352 Regular Languages.
Prof. Busch - LSU1 Context-Free Languages. Prof. Busch - LSU2 Regular Languages Context-Free Languages.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Fall 2005Costas Busch - RPI1 Context-Free Languages.
Context-Free Languages Hinrich Schütze CIS, LMU, Slides based on RPI CSCI 2400 Thanks to Costas Busch.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
Formal Grammars Denning, Sections 3.3 to 3.6. Formal Grammar, Defined A formal grammar G is a four-tuple G = (N,T,P,  ), where N is a finite nonempty.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2005.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2010.
Classification of grammars Definition: A grammar G is said to be 1)Right-linear if each production in P is of the form A  xB or A  x where A and B are.
Grammars CPSC 5135.
Context-free Languages
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory V Context-Free Grammars andLanguages.
CS 3240: Languages and Computation Context-Free Languages.
Context Free Grammars. Context Free Languages (CFL) The pumping lemma showed there are languages that are not regular –There are many classes “larger”
Midterm 1 Breakdown >79 3 >29 7 >69 5 >19 5 >59 7 >49 9 >39 7.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Context Free Grammars 1. Context Free Languages (CFL) The pumping lemma showed there are languages that are not regular –There are many classes “larger”
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Grammars Hopcroft, Motawi, Ullman, Chap 5. Grammars Describes underlying rules (syntax) of programming languages Compilers (parsers) are based on such.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
Context-Free Languages. Regular Languages Context-Free Languages.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Chapter 5 Context-Free Languages Regular language are effective in describing certain simple patterns. But it is not enough to describe programming languages.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Formal grammars A formal grammar is a system for defining the syntax of a language by specifying sequences of symbols or sentences that are considered.
Compiler Construction Lecture Five: Parsing - Part Two CSC 2103: Compiler Construction Lecture Five: Parsing - Part Two Joyce Nakatumba-Nabende 1.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Context-Free Languages
Formal Language & Automata Theory
G. Pullaiah College of Engineering and Technology
CSE322 LEFT & RIGHT LINEAR REGULAR GRAMMAR
فصل دوم Context-Free Languages
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 2 Context-Free Language - 01
Theory of Computation Lecture #
… NPDAs continued.
Presentation transcript:

1 Context-Free Languages

2 Regular Languages

3 Context-Free Languages

4 Pushdown Automata Context-Free Grammars stack automaton

5 Context-Free Grammars

6 Grammars Grammars express languages Example: the English language

7

8 A derivation of “the dog walks”:

9 A derivation of “a cat runs”:

10 Language of the grammar: L = { “a cat runs”, “a cat walks”, “the cat runs”, “the cat walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” }

11 Notation VariableTerminal Production Rules

12 Another Example Grammar: Derivation of sentence :

13 Grammar: Derivation of sentence :

14 Other derivations:

15 Language of the grammar

16 More Notation Grammar Set of variables Set of terminal symbols Start variable Set of Production rules

17 Example Grammar :

18 More Notation Sentential Form: A sentence that contains variables and terminals Example: Sentential Formssentence

19 We write: Instead of:

20 In general we write: If:

21 By default:

22 Example Grammar Derivations

23 Grammar Example Derivations

24 Another Grammar Example Grammar : Derivations:

25 More Derivations

26 Language of a Grammar For a grammar with start variable : String of terminals

27 Example For grammar : Since:

28 A Convenient Notation

29 Example A context-free grammar : A derivation:

30 A context-free grammar : Another derivation:

31 (((( )))) Describes parentheses:

32 A context-free grammar : A derivation: Example

33 A context-free grammar : Another derivation:

34

35 A context-free grammar : A derivation: Example

36 A context-free grammar : A derivation:

37 () ((( ))) (( )) Describes matched parentheses:

38 Definition: Context-Free Grammars Grammar Productions of the form: String of variables and terminals VariablesTerminal symbols Start variable Variable

39 Definition: Context-Free Languages A language is context-free if and only if there is a context-free grammar with

40 Derivation Order Leftmost derivation: Rightmost derivation:

41 Leftmost derivation: Rightmost derivation:

42 Derivation Trees

43

44

45

46

47 Derivation Tree

48 yield Derivation Tree

49 Partial Derivation Trees Partial derivation tree

50 Partial derivation tree

51 Partial derivation tree sentential form yield

52 Same derivation tree Sometimes, derivation order doesn’t matter Leftmost: Rightmost:

53 Ambiguity

54 leftmost derivation

55 Rightmost derivation

56 Two derivation trees

57 The grammar is ambiguous: stringhas two derivation trees

58 stringhas two leftmost derivations The grammar is ambiguous:

59 Definition: A context-free grammar is ambiguous if some string has: two or more derivation trees

60 In other words: A context-free grammar is ambiguous if some string has: two or more leftmost derivations (or rightmost)

61 Why do we care about ambiguity? take

62

63

64 Correct result:

65 We want to remove ambiguity Ambiguity is bad for programming languages