Chapter 13 1. Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.

Slides:



Advertisements
Similar presentations
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.,
Advertisements

COGN1001: Introduction to Cognitive Science Topics in Computer Science Formal Languages and Models of Computation Qiang HUO Department of Computer.
ISBN Chapter 3 Describing Syntax and Semantics.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
PZ02A - Language translation
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Compilers and Syntax.
Chapter 3: Formal Translation Models
Languages and Grammars MSU CSE 260. Outline Introduction: E xample Phrase-Structure Grammars: Terminology, Definition, Derivation, Language of a Grammar,
Language Translation Principles Part 1: Language Specification.
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Syntactic Analysis Dr. Hyunyoung Lee.
Chapter 13. Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Languages and Grammars Rosen, Chapter 12.1.
Copyright © Cengage Learning. All rights reserved.
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.
Languages & Strings String Operations Language Definitions.
Modeling Computation Rosen, ch. 12.
Introduction Syntax: form of a sentence (is it valid) Semantics: meaning of a sentence Valid: the frog writes neatly Invalid: swims quickly mathematics.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax.
Winter 2007SEG2101 Chapter 71 Chapter 7 Introduction to Languages and Compiler.
1 Chapter 3 Describing Syntax and Semantics. 3.1 Introduction Providing a concise yet understandable description of a programming language is difficult.
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.
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
Grammars CPSC 5135.
CSNB143 – Discrete Structure Topic 11 – Language.
ProgrammingLanguages Programming Languages Language Syntax This lecture introduces the the lexical structure of programming languages; the context-free.
C H A P T E R TWO Syntax and Semantic.
ISBN Chapter 3 Describing Syntax and Semantics.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
CMSC 330: Organization of Programming Languages Context-Free Grammars.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
Chapter 3 Describing Syntax and Semantics
ISBN Chapter 3 Describing Syntax and Semantics.
Syntax and Grammars.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
September1999 CMSC 203 / 0201 Fall 2002 Week #14 – 25/27 November 2002 Prof. Marie desJardins clip art courtesy of
Programming Languages and Design Lecture 2 Syntax Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Lecture 16: Modeling Computation Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output.
Formal Languages and Grammars
Discrete Structures ICS252 Chapter 5 Lecture 2. Languages and Grammars prepared By sabiha begum.
Chapter 4: Syntax analysis Syntax analysis is done by the parser. –Detects whether the program is written following the grammar rules and reports syntax.
C H A P T E R T W O Syntax and Semantic. 2 Introduction Who must use language definitions? Other language designers Implementors Programmers (the users.
1 CS Programming Languages Class 04 September 5, 2000.
Models of Computation by Dr. Michael P. Frank, University of Florida Modified and extended by Longin Jan Latecki, Temple University Rosen 7 th ed., Ch.
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Spring
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Syntax.
7.2 Programming Languages - An Introduction to Informatics WMN Lab. Hye-Jin Lee.
Organization of Programming Languages Meeting 3 January 15, 2016.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Formal Languages and Automata FORMAL LANGUAGES FINITE STATE AUTOMATA.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesAlgebraic.
Describing Syntax and Semantics Chapter 3: Describing Syntax and Semantics Lectures # 6.
PROGRAMMING LANGUAGES
PROGRAMMING LANGUAGES
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Introduction to Formal Languages
Concepts of Programming Languages
Classification of Languages
Discrete Mathematics and its Applications Rosen 7th ed., Ch. 13.1
Models of Computation by Dr. Michael P
Discrete Maths 13. Grammars Objectives
Models of Computation by Dr. Michael P
Languages and Grammer In TCS
Presentation transcript:

Chapter 13 1

Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing Machines 2

Section

Section Summary Phrase-Structure Grammars Types of Phrase-Structure Grammars Derivation Trees Backus-Naur Form 4

Introduction Syntax (form of a sentence) vs. semantics (meaning of a sentence) The sentence the frog writes neatly is a valid sentence according to the rules of English grammar. That is, it is syntactically correct, even though it’s nonsensical (unless we are talking about a fantasy world). The sequence of words swims quickly mathematics is not a valid sentence according to the rules of English grammar. 5

Grammars The rules that specify the syntactically correct sentences of a natural language such as English are complex. Instead of studying natural languages, we can define formal languages that have well-defined rules of syntax. These rules of syntax are important both in linguistics (the study of natural languages) and in the study of programming languages. 6

An Example Grammar An example sequence of replacements: noun phrase verb phrase article adjective noun verb phrase article adjective noun verb adverb the adjective noun verb adverb the large noun verb adverb the large rabbit verb adverb the large rabbit hops adverb the large rabbit hops quickly 1. a sentence is made up of a noun phrase followed by a verb phrase; 2. a noun phrase is made up of an article followed by an adjective followed by a noun, or 3. a noun phrase is made up of an article followed by a noun; 4. a verb phrase is made up of a verb followed by an adverb, or 5. a verb phrase is made up of a verb; 6. an article is a, or 7. an article is the; 8. an adjective is large, or 9. an adjective is hungry; 10. a noun is rabbit, or 11. a noun is mathematician; 12. a verb is eats, or 13. a verb is hops; 14. an adverb is quickly, or 15. an adverb is wildly. We use these rules to form valid sentences by making a series of replacements until no more rules can be used. Some additional valid sentences are: a hungry mathematician eats wildly, a large mathematician hops, the rabbit eats quickly, etc. But note that the following is not valid: the quickly eats mathematician 7

Phrase-Structure Grammars A vocabulary (or alphabet) V is a finite, nonempty set of elements called symbols. A word (or sentence) over V is a string of finite length of elements of V. The empty string or null string, denoted by λ, is the string containing no symbols. The set of all words over V is denoted by V*. A language over V is a subset of V*. The elements of V that can not be replaced by other symbols are called terminals, e.g., a, the, and rabbit in the example grammar. Those that can be replaced by other symbols are called nonterminals, e.g., sentence, noun phrase, etc. The rules that specify when we can replace a string V* with another string are called productions of the grammar. We denote by z 0 → z 1 the production that specifies that z 0 can be replaced by z 1 within a string. 8

Phrase-Structure Grammars (cont.) A phrase-structure grammar G =(V, T, S, P) consists of a vocabulary V, a subset T of V consisting of terminal symbols, a start symbol S from V, and a finite set of productions P. The set N = V − T is the set of nonterminal symbols. Every production in P must contain at least one nonterminal on its left side. ***Example (Grammar 1 ): Let G =(V, T, S, P), where V = {a, b, A, B, S}, T = {a,b}, S is the start symbol, and P = {S → A ba, A → BB, B →ab, AB →b}. 9

Derivations 10

Language Generation 11

Types of Phrase Structure Grammars Phrase-structure grammars are classified by the types of allowable productions. Type 2 grammars are called context-free grammars. A language generated by a context-free grammar is called a context-free language. Type 3 grammars are called context-sensitive grammars (or a regular grammar). A language generated by a context- sensitive grammar is called a context-sensitive language (or a regular language). Avram Noam Chomsky (Born 1928 ) 12

Derivation Trees We can represent a derivation in the language generated by a context- free grammar by an ordered rooted tree, called a derivation, or parse tree. The root of the tree represents the start symbol. The internal vertices represent the nonterminal symbols that arise in the derivation. The leaves represent the terminal symbols that arise. If the production A → w, where w is a word, arises in the derivation, the vertex that represents A has as children vertices that represent each symbol in w, in order from left to right. A derivation tree for the derivation of the hungry rabbit eats quickly, given the grammar described earlier. 13

Backus-Naur Form Backus-Naur form (BNF) is sometimes used to specify a type 2 grammar. It is often used to specify the syntactic rules of computer languages. The productions of a type 2 grammar have a single nonterminal symbol on their left-hand side. All the productions with the same nonterminal symbol on the left-hand side are combined into one statement using the symbol ::= instead of →. Additionally,, all nonterminal symbols are enclosed in brackets ( 〈〉 ), and the right-hand side of productions are spearated by bars. For example, the productions A → Aa, A → a, and A → AB are written as 〈 A 〉 ::= 〈 A 〉 a | a | 〈 A 〉 〈 B 〉. John Backus ( ) Peter Naur (Born 1928 ) 14

BNF and ALGOL 60 In the programming language ALGOL 60 an identifier consists of a string of alphanumeric characters and must begin with a letter. The BNF description of allowable identifiers is: 〈 identifier 〉 ::=〈 letter 〉 | 〈 identifier 〉〈 letter 〉 | 〈 identifier 〉〈 digit 〉 〈 letter 〉 ::= a | b | ⋯ | y | z 〈 digit 〉 ::= 0 | 1 | ⋯ | 8 | 9 x 99 a is a valid identifier since the first rule can be used to replace 〈 identifier 〉 by 〈 identifier 〉〈 letter 〉, the second rule to obtain 〈 identifier 〉 a, the first rule twice to obtain 〈 identifier 〉〈 digit 〉〈 digit 〉 a, the third rule twice to obtain 〈 identifier 〉99 a, the first rule to obtain 〈 letter 〉99 a, and finally the second rule to obtain x 99 a. 15