C1.1 Introduction. Theory of Computer Science. Theory of Computer Science. C1.1 Introduction. C1.2 Alphabets and Formal Languages. C1.

Similar documents
Theory of Computer Science

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

C2.1 Regular Grammars

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

C2.1 Regular Grammars

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

Theory of Computation - Module 3

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

CS 133 : Automata Theory and Computability

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

C6.2 Push-Down Automata

Theory of Computation

FABER Formal Languages, Automata. Lecture 2. Mälardalen University

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y.

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008

CS Automata, Computability and Formal Languages

Harvard CS121 and CSCI E-121 Lecture 2: Mathematical Preliminaries

Automata: a short introduction

Pushdown Automata. Reading: Chapter 6

Parsing. Context-Free Grammars (CFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26

In English, there are at least three different types of entities: letters, words, sentences.

EXAMPLE CFG. L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa. L = {a n b : n 0 } L = {a n b : n 1 } S asb ab S 1S00 S 1S00 100

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Homework 4 Solutions. 2. Find context-free grammars for the language L = {a n b m c k : k n + m}. (with n 0,

CPSC 313 Introduction to Computability

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Concordia University Department of Computer Science & Software Engineering

Theory of Computation

Linear conjunctive languages are closed under complement

Automata Theory CS F-08 Context-Free Grammars

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

CFG Simplification. (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions

SFWR ENG 2FA3. Solution to the Assignment #4

Section 1.3 Ordered Structures

CSCI 340: Computational Models. Regular Expressions. Department of Computer Science

Sheet 1-8 Dr. Mostafa Aref Format By : Mostafa Sayed

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

5/10/16. Grammar. Automata and Languages. Today s Topics. Grammars Definition A grammar G is defined as G = (V, T, P, S) where:

Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009

CS375: Logic and Theory of Computing

Theory of Computation Turing Machine and Pushdown Automata

Homework 4. Chapter 7. CS A Term 2009: Foundations of Computer Science. By Li Feng, Shweta Srivastava, and Carolina Ruiz

Semigroup presentations via boundaries in Cayley graphs 1

CMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata

6.8 The Post Correspondence Problem

CMSC 330: Organization of Programming Languages

Section 1 (closed-book) Total points 30

Chapter 3. Regular grammars

Computability and Complexity

Chapter 5: Context-Free Languages

HW 3 Solutions. Tommy November 27, 2012

Einführung in die Computerlinguistik

Solutions to Problem Set 3

Finite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols

Nondeterministic Finite Automata and Regular Expressions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 373: Theory of Computation. Fall 2010

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

On Parsing Expression Grammars A recognition-based system for deterministic languages

Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings

Fundamentele Informatica II

Automata Theory and Formal Grammars: Lecture 1

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Context Free Grammars

{a, b, c} {a, b} {a, c} {b, c} {a}

download instant at Assume that (w R ) R = w for all strings w Σ of length n or less.

Einführung in die Computerlinguistik

Design and Analysis of Distributed Interacting Systems

What is this course about?

CS A Term 2009: Foundations of Computer Science. Homework 2. By Li Feng, Shweta Srivastava, and Carolina Ruiz.

Theory of Computer Science

Lecture 11 Context-Free Languages

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},

Embedded systems specification and design

UNIT-I. Strings, Alphabets, Language and Operations

CMSC 330: Organization of Programming Languages

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Context-Free Grammars. 2IT70 Finite Automata and Process Theory

Valence automata over E-unitary inverse semigroups

What Is a Language? Grammars, Languages, and Machines. Strings: the Building Blocks of Languages

Lecture 12 Simplification of Context-Free Grammars and Normal Forms

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

MA/CSSE 474 Theory of Computation

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Syntax of propositional logic. Syntax tree of a formula. Semantics of propositional logic (I) Subformulas

Languages. Languages. An Example Grammar. Grammars. Suppose we have an alphabet V. Then we can write:

Context Sensitive Grammar

Computational Theory

Theory Of Computation UNIT-II

where A, B, C N, a Σ, S ϵ is in P iff ϵ L(G), and S does not occur on the right-hand side of any production. 3.6 The Greibach Normal Form

COSE312: Compilers. Lecture 2 Lexical Analysis (1)

Chapter 1. Introduction

INSTITUTE OF AERONAUTICAL ENGINEERING

UNIT II REGULAR LANGUAGES

Transcription:

Theory of Computer Science March 20, 2017 C1. Formal Languages and Grammars Theory of Computer Science C1. Formal Languages and Grammars Malte Helmert University of Basel March 20, 2017 C1.1 Introduction C1.2 Alphabets and Formal Languages C1.3 Grammars C1.4 C1.5 Summary Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 1 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 2 / 25 Course Contents C1.1 Introduction Parts of the course: A. background mathematical foundations and proof techniques B. logic (Logik) How can knowledge be represented? How can reasoning be automated? C. automata theory and formal languages (Automatentheorie und formale Sprachen) What is a computation? D. computability theory (Berechenbarkeitstheorie) What can be computed at all? E. complexity theory (Komplexitätstheorie) What can be computed efficiently? Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 3 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 4 / 25

Example: Propositional Formulas Example: Propositional Formulas from the logic part: Definition (Syntax of Propositional Logic) Let A be a set of atomic propositions. The set of propositional formulas (over A) is inductively defined as follows: Every atom a A is a propositional formula over A. If ϕ is a propositional formula over A, then so is its negation ϕ. If ϕ and ψ are propositional formulas over A, then so is the conjunction (ϕ ψ). If ϕ and ψ are propositional formulas over A, then so is the disjunction (ϕ ψ). Let S A be the set of all propositional formulas over A. Such sets of symbol sequences (or words) are called languages. Sought: General concepts to define such (often infinite) languages with finite descriptions. today: grammars later: automata Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 5 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 6 / 25 Example: Propositional Formulas C1. Formal Languages and Grammars Alphabets and Formal Languages Example (Grammar for S {a,b,c} ) Grammar variables {F, A, N, C, D} with start variable F, terminal symbols {a, b, c,,,, (, )} and rules F A A a N F F N A b C (F F) F C A c D (F F) F D C1.2 Alphabets and Formal Languages Start with F. In each step, replace a left-hand side of a rule with its right-hand side until no more variables are left: F N F D (F F) (A F) (b F) (b A) (b c) Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 7 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 8 / 25

C1. Formal Languages and Grammars Alphabets and Formal Languages Alphabets and Formal Languages C1. Formal Languages and Grammars Alphabets and Formal Languages Languages: Examples Definition (Alphabets, Words and Formal Languages) An alphabet Σ is a finite non-empty set of symbols. A word over Σ is a finite sequence of elements from Σ. The empty word (the empty sequence of elements) is denoted by ε. Σ denotes the set of all words over Σ. We write w for the length of a word w. A formal language (over alphabet Σ) is a subset of Σ. German: Alphabet, Zeichen/Symbole, leeres Wort, formale Sprache Example Σ = {a, b} Σ = {ε, a, b, aa, ab, ba, bb,... } aba = 3, b = 1, ε = 0 Example (Languages over Σ = {a, b}) S 1 = {a, aa, aaa, aaaa,... } S 2 = Σ S 3 = {a n b n n 0} = {ε, ab, aabb, aaabbb,... } S 4 = {ε} S 5 = S 6 = {w Σ w contains twice as many as as bs} = {ε, aab, aba, baa,... } S 7 = {w Σ w = 3} = {aaa, aab, aba, baa, bba, bab, abb, bbb} Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 9 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 10 / 25 Grammars C1.3 Grammars Definition (Grammars) A grammar is a 4-tuple Σ, V, P, S with: 1 Σ finite alphabet of terminal symbols 2 V finite set of variables (nonterminal symbols) with V Σ = 3 P (V Σ) + (V Σ) finite set of rules (or productions) 4 S V start variable German: Grammatik, Terminalalphabet, Variablen, Regeln/Produktionen, Startvariable Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 11 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 12 / 25

Rule Sets Rules: Examples What exactly does P (V Σ) + (V Σ) mean? (V Σ) : all words over (V Σ) (V Σ) + : all non-empty words over (V Σ) in general, for set X : X + = X \ {ε} : Cartesian product (V Σ) + (V Σ) : set of all pairs x, y, where x non-empty word over (V Σ) and y word over (V Σ) Instead of x, y we usually write rules in the form x y. Example Let Σ = {a, b, c} and V = {X, Y, Z}. Some examples of rules in (V Σ) + (V Σ) : X XaY Yb a XY ε XYZ abc abc XYZ Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 13 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 14 / 25 Derivations Language Generated by a Grammar Definition (Derivations) Let Σ, V, P, S be a grammar. A word v (V Σ) can be derived from word u (V Σ) + (written as u v) if 1 u = xyz, v = xy z with x, z (V Σ) and 2 there is a rule y y P. We write: u v if v can be derived from u in finitely many steps (i. e., by using n derivations for n N 0 ). German: Ableitung Definition (Languages) The language generated by a grammar G = Σ, V, P, S L(G) = {w Σ S w} is the set of all words from Σ that can be derived from S with finitely many rule applications. German: erzeugte Sprache Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 15 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 16 / 25

Grammars Examples: blackboard C1.4 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 17 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 18 / 25 Grammars are organized into the Chomsky hierarchy. Definition () Every grammar is of type 0 (all rules allowed). Grammar is of type 1 (context-sensitive) if all rules w 1 w 2 satisfy w 1 w 2. Grammar is of type 2 (context-free) if additionally w 1 V (single variable) in all rules w 1 w 2. Grammar is of type 3 (regular) if additionally w 2 Σ ΣV in all rules w 1 w 2. Examples: blackboard special case: rule S ε is always allowed if S is the start variable and never occurs on the right-hand side of any rule. German: Chomsky-Hierarchie, Typ 0, Typ 1 (kontextsensitiv), Typ 2 (kontextfrei), Typ 3 (regulär) Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 19 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 20 / 25

Type k Language: Example Definition (Type 0 3 Languages) A language L Σ is of type 0 (type 1, type 2, type 3) if there exists a type-0 (type-1, type-2, type-3) grammar G with L(G) = L. Example Consider the language L generated by the grammar {a, b, c,,,, (, )}, {F, A, N, C, D}, P, F with the following rules P: F A A a N F F N A b C (F F) F C A c D (F F) F D Questions: Is L a type-0 language? Is L a type-1 language? Is L a type-2 language? Is L a type-3 language? Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 21 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 22 / 25 C1. Formal Languages and Grammars Summary C1.5 Summary regular languages (type 3) context free languages (type 2) context sensitive languages (type 1) Type-0 languages All languages Note: Not all languages can be described by grammars. (Proof?) Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 23 / 25 Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 24 / 25

C1. Formal Languages and Grammars Summary Summary Languages are sets of symbol sequences. Grammars are one possible way to specify languages. Language generated by a grammar is the set of all words (of nonterminal symbols) derivable from the start symbol. Chomsky hierarchy distinguishes between languages at different levels of expressiveness. following chapters: more about regular languages automata as alternative representation of languages Malte Helmert (University of Basel) Theory of Computer Science March 20, 2017 25 / 25