540 likes | 702 Views
Introduction to Computability Theory. Lecture5: Context Free Languages Prof. Amos Israeli. Introduction and Motivation. On the last lecture we completed our study of regular languages. (There is still a lot to learn but our time is limited…). Introduction and Motivation.
E N D
Introduction to Computability Theory Lecture5: Context Free Languages Prof. Amos Israeli
Introduction and Motivation On the last lecture we completed our study of regular languages. (There is still a lot to learn but our time is limited…).
Introduction and Motivation In our study of RL-s we Covered: • Motivation and definition of regular languages. • DFA-s, NFA-s, RE-s and their equivalence. • Non Regular Languages and the Pumping Lemma.
Introduction and Motivation In this lecture, we turn to Context Free Grammars and Context Free Languages. The class of Context Free Languages is an intermediate class between the class of regular languages and the class of Decidable Languages (To be defined).
Introduction and Motivation A Context Free Grammar is a “machine” that creates a language. A language created by a CF grammar is called A Context Free Language. (We will show that) The class of Context Free Languages Properly Contains the class of Regular Languages.
Context Free Grammar - Example Consider grammar : A CFL consists of substitution rules called Productions. The capital letters are theVariables. The other symbols are the Terminals.
Context Free Grammar - Example Consider grammar : The grammar generates the language called the language of ,denoted by .
Context Free Grammar - Example Consider grammar : This is a Derivation of the word by : On each step, a single rule is activated. This mechanism is nondeterministic.
Context Free Grammar - Example This is A Parse Treeof the word by :
Context Free Grammar - Example Each internal node of the tree is associated with a single production.
CF Grammar – A Formal Definition A Context Free Grammar is a 4-tupple where: • is a finite set called the variables. • is a finite set, disjoint from V called the terminals. • is a set of rules, where a rule is a variable and a string of variables and terminals, and • is the start variable . ,
A Derivation – A Formal Definition A word is a string of terminals. A derivation of a word w from a context Free Grammaris a sequence of strings ,over , where: • is the start variable of G. • For each , is obtained by activating a single production (rule) of G on one of the variables of .
CF Grammar – A Formal Definition A word w is in the Language of grammar G, denoted by , if there exists a derivation whose rightmost string is w . Thus,
Example2: Arithmetical EXPS Grammar : Rules: 1. 2. 3.
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar : input output rule
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar : input output rule
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar : input output rule
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar : input output rule
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar : input output rule
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar : input output rule
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar : input output rule
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar : output rule
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar : output rule
Example2: Arithmetical EXPS Derivation of by Grammar : input
Example2: Arithmetical EXPS Derivation of by Grammar : input rule
Example2: Arithmetical EXPS Derivation of by Grammar :
Example2: Arithmetical EXPS Derivation of by Grammar : Note: There is more than one derivation.
Example3: The Language of WF ( ) To be Demonstrated on the blackboard
Ambiguity We already saw that a word may have more then a single derivation from the same grammar. A Leftmost Derivation is a derivation in which rules are applied in order left to right. A grammar is ambiguous if it has Two parse trees.
Ambiguity Reminder: Two parse trees are equal if they are equal as trees and if all productions corresponding to inner nodes are also equal .
Example4: Similar to Arith. EXPS Grammar : Rules: , ,