Classification of Languages

Slides:



Advertisements
Similar presentations
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Advertisements

COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou.
Regular Expressions, Backus-Naur Form and Reverse Polish Notation.
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.
Grammars, Languages and Parse Trees. Language Let V be an alphabet or vocabulary V* is set of all strings over V A language L is a subset of V*, i.e.,
COGN1001: Introduction to Cognitive Science Topics in Computer Science Formal Languages and Models of Computation Qiang HUO Department of Computer.
Chapter Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
CS5371 Theory of Computation
PZ02A - Language translation
Normal forms for Context-Free Grammars
Chapter 3: Formal Translation Models
COP4020 Programming Languages
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Languages and Grammars MSU CSE 260. Outline Introduction: E xample Phrase-Structure Grammars: Terminology, Definition, Derivation, Language of a Grammar,
Languages & Strings String Operations Language Definitions.
Introduction Syntax: form of a sentence (is it valid) Semantics: meaning of a sentence Valid: the frog writes neatly Invalid: swims quickly mathematics.
Winter 2007SEG2101 Chapter 71 Chapter 7 Introduction to Languages and Compiler.
A sentence (S) is composed of a noun phrase (NP) and a verb phrase (VP). A noun phrase may be composed of a determiner (D/DET) and a noun (N). A noun phrase.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
Grammars CPSC 5135.
CSNB143 – Discrete Structure Topic 11 – Language.
CMSC 330: Organization of Programming Languages Context-Free Grammars.
Review: Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol.
Discrete Mathematical Structures 4 th Edition Kolman, Busby, Ross © 2000 by Prentice-Hall, Inc. ISBN
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Grammars A grammar is a 4-tuple G = (V, T, P, S) where 1)V is a set of nonterminal symbols (also called variables or syntactic categories) 2)T is a finite.
Parsing and Code Generation Set 24. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program,
September1999 CMSC 203 / 0201 Fall 2002 Week #14 – 25/27 November 2002 Prof. Marie desJardins clip art courtesy of
Formal Languages and Grammars
GRAMMARS & PARSING. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program, referred to as a.
9/15/2010CS485, Lecture 2, Fall Lecture 2: Introduction to Syntax (Revised based on the Tucker’s slides)
Chapter 4: Syntax analysis Syntax analysis is done by the parser. –Detects whether the program is written following the grammar rules and reports syntax.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Lecture #2 Advanced Theory of Computation. Languages & Grammar Before discussing languages & grammar let us deal with some related issues. Alphabet: is.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesAlgebraic.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
PROGRAMMING LANGUAGES
Regular Expressions, Backus-Naur Form and Reverse Polish Notation
Chapter 3 – Describing Syntax
PROGRAMMING LANGUAGES
CHAPTER 3 SETS, BOOLEAN ALGEBRA & LOGIC CIRCUITS
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Context-Free Grammars: an overview
L-systems L-systems are grammatical systems introduced by Lyndenmayer to describe biological developments such as the growth of plants and cellular organisms.
Automata and Languages What do these have in common?
Natural Language Processing - Formal Language -
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Deterministic Finite Automata
Context-Free Languages
Deterministic Finite Automata
Context-Free Grammars
Intro to Data Structures
CHAPTER 2 Context-Free Languages
CSE 311: Foundations of Computing
R.Rajkumar Asst.Professor CSE
Context-Free Grammars 1
CS 3304 Comparative Languages
CS 3304 Comparative Languages
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Teori Bahasa dan Automata Lecture 9: Contex-Free Grammars
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Regular Grammars.
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Programming Languages 2nd edition Tucker and Noonan
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
COMPILER CONSTRUCTION
Terminology and Symbols
Presentation transcript:

Classification of Languages

Strings and Regular Expression Alphabet: The set A is not a set of numbers, but some set of symbols. Strings (words) : The set A* consisting of all finite sequences of letters or other symbols from the set A, written without the commas, are referred as strings. Empty String: The set A* contains empty string or empty sequence, containing no symbols, and we denote this string by Λ.

Catenation: If w1 = s1s2…sn and w2 = t1t2…tk are elements of A Catenation: If w1 = s1s2…sn and w2 = t1t2…tk are elements of A* for some set A, then the catenation of w1 and w2 as the sequence s1s2…snt1t2…tk. i.e. w1 * w2 = w1w2 = s1s2…snt1t2…tk.

Regular expression A regular expression over A is a string constructed from the elements of A and the symbols (, ), *, Λ. The symbol Λ is a regular expression. If x Є A, the symbol x is a regular expression. If α and β are regular expressions, then the expression αβ is regular. If α and β are regular expressions, then the expression αvβ is regular. If α is a regular expression, then (α)* is regular.

Example Following expressions are all regular expressions over A. (i) 0*(0v1)* (ii) 00*(0v1)*1

Eg 1. Let A = {a, b, c}. Then the regular expression a Eg 1. Let A = {a, b, c}. Then the regular expression a* corresponds to the set of all finite sequence of a’s, such as aaaa, aa, aaaaaaaa so on. The regular expression a(bvc) corresponds to the set {ab, ac} ⊆ A*. The regular expression ab(bc)* corresponds to abbc, abbcbcbc, and so on.

Regular Set Associated with each regular expression over A, there is a corresponding subset A*. Such sets are called regular subsets of A*or just regular sets if no response of A is needed.

Languages S: Set of words S*: The collection of all possible sentences. Syntax: The specification of the proper construction of sentences is called the syntax of a language. Phase structure grammar: The syntax of a class of languages

Grammar A Phase structure grammar G is defined to be a 4 –tuple (V,S, v0 and ↦), where V is a finite set, S is a subset of V, v0 Є V-S and ↦ is a finite relation on V*. V consists of S together with some other symbols. v0: The element v0 of V is a starting point of substitution. The relation ↦ on V* specifies allowable replacements, in the sense that, if w ↦ w’, we may replace w by w’ whenever the string w occurs.

Production of G: The statement w ↦ w’, is called a production of G Production of G: The statement w ↦ w’, is called a production of G. Then w and w’ are called left and right sides of the production, respectively. Terminal and Non terminal symbols: If G = (V, S, v0, ↦) is a phase structure grammar, then set S is the set of terminal symbols and N = V-S is the set of non terminal symbols. Note: V = S U N. Language: The set of all properly constructed sentences that can be produced using a grammar G is called the language of G and is denoted by L(G).

Eg1: Let S = { Ramesh, Seema, drives, jogs, carelessly, rapidly, frequently} & N = { sentence, noun, verbphase, verb, adverb} and let V = S U N. Let v0 = sentence, and suppose that the relation ↦ on V* is described by sentence ↦ noun verbphase noun ↦ Ramesh noun ↦ Seema verbphase ↦ verb adverb verb ↦ drives verb ↦ jogs adverb ↦ carelessly adverb ↦ rapidly adverb ↦ frequently The set S contains all the allowed words in the language; N consists of words that describe parts of sentences but that are not actually contained in the language. Write the derivation of the sentence “ Seema drives rapidly”. Also draw the derivation tree.

Eg2: Let V = { v0, w, a, b, c}, S = { a, b, c} and let ↦ be the relation on V* given by 1. v0 ↦ aw 2. w ↦ bbw 3. w ↦ c. Consider the phase structure grammar G = (V, S, v0, ↦). Derive the sentence ab6c. Also draw the derivation tree. Derive the sentence ab4c. Also draw the derivation tree.

Eg3: Let V = { v0, w, a, b, c}, S = { a, b, c} and let ↦ be the relation on V* given by 1. v0 ↦ aw 2. w ↦ bbw 3. w ↦ c. Consider the phase structure grammar G = (V, S, v0, ↦). Determine the form of allowable sentences in L(G). Eg: In examples 4 and 5, a grammar G is specified. In each case describe precisely the language, L(G), produced by this grammar; that is, describe all syntactically correct “sentences”.

4. G = (v, S, v0, ↦ ) V = {v0, v1, x, y, z}, S = {x, y, z} ↦: vo ↦ xvo, vo ↦ yv1, v1 ↦yv1, v1 ↦ z. 5. G = (v, S, v0, ↦ ) V = {v0,a, b}, S = {a, b} ↦: vo ↦ aavo, vo ↦ a, v0 ↦b Eg 6. Construct a phrase structure grammar G such that the language, L(G), of G is equal to the language L. (i) L = {anbn/ n≥ 3} (ii) L = { strings of 0’s and 1’s with an equal number n≥0}.

Classification of Phase structure Grammar Let G = (V, S, v0, ↦) be a phase structure grammar. Then we say that G is (i) Type 0: If no restrictions are placed on the production of G. Type 1. If for any production w1 ↦ w2, the length of w1 is less than or equal to the length of w2. Type 2. If the left hand side of each production is a single, non-terminal symbol and the right hand side consists of one or more symbols. Type 3.: If the left hand side of each production is a single, non-terminal symbol and the right hand side consists of one or more symbols, including at most one non-terminal symbol.

Type-2 or Type-3 Language: A language will be called typa-2 or type-3 if there is a grammar of type-2 or type-3 that produces it. BNF Notation: For Type-2 grammars, there are some useful alternative methods of displaying the productions.(Backus-Naur form) Step1: The symbol w, remains on the left and all RHS associated with w are listed together, separated by the symbol (∣). Step2.The relational symbol ↦ is replaced by the symbol (::=) . Step3. The non-terminal symbols, where ever they occur, are enclosed in pointed brackets < > .

Eg: The following grammar describes the syntax of decimal numbers and can be viewed as a mini-grammar whose corresponding language consists precisely of all properly formed decimal numbers. Let S = { 0,1,2,3,4,5,6,7,8,9,.} Let V be the union of S with the set N= {decimal-number, decimal fraction, unsigned-integer, digit} Let G be a grammar with symbol sets V and S, with starting symbol “decimal-number” and with productions given in BNF forms as follows.

1. <decimal-number> ::= <unsigned integer>∣ <decimal-fraction>∣ <unsigned integer> <decimal-fraction> 2. <decimal-fraction> ::= . <unsigned integer> 3. <unsigned integer> ::= <digit>∣<digit> < unsigned integer> 4. <digit> ::=0 ∣ 1 ∣ 2 ∣ 3 ∣4 ∣ 5 ∣ 6 ∣ 7 ∣ 8 ∣ 9 Example: By using above grammar draw derivation tree for 23.14

Syntax diagram: A second alternative method for displaying the production in some type-2 grammar is the syntax diagram

Finite State Machines Suppose that we have a finite set S = {s0, s1, …, sn}, a finite set I, and for each x є I, a function fx: S→S. Let F = {fx/ xє I}. The triplet (S, I, F) is called a finite state machine, S is called the state set of the machine and the elements of S are called states. The set I is called the input set of the machine. Thus ,if the machine is in the state si and input x occurs, the next state of the machine will be fx(si). Since the next fx(si) is uniquely determined by the pair (si, x), there is a function F: S x I → S given by F(si, x) = fx(si).

Moore Machine (Recognition Machine) It is defined as a sequence (S, I, F, s0, T), where (S, I, F) constitute a finite-state machine, s0 Є S and T⊆ S. The state s0 is called the starting state of M, and it will be used to represent the condition of the machine before it receives any input. The set T is called the set of acceptance state of M. These states will be used in language recognition. Note: In the digraph of Moore Machine, the acceptance states are indicated with two concentric circles.