Context-Free Grammars

Similar documents
A General Class of Noncontext Free Grammars Generating Context Free Languages

Language properties and Grammar of Parallel and Series Parallel Languages

Context Free Grammars. Many slides from Michael Collins

RANKING AND UNRANKING LEFT SZILARD LANGUAGES. Erkki Mäkinen DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A ER E P S I M S

COMPUTATIONAL COMPLEXITY OF LEFT-ASSOCIATIVE GRAMMAR

A Version Space Approach to Learning Context-free Grammars

Syntax Parsing 1. Grammars and parsing 2. Top-down and bottom-up parsing 3. Chart parsers 4. Bottom-up chart parsing 5. The Earley Algorithm

CS 598 Natural Language Processing

Proof Theory for Syntacticians

Grammars & Parsing, Part 1:

Enumeration of Context-Free Languages and Related Structures

A R "! I,,, !~ii ii! A ow ' r.-ii ' i ' JA' V5, 9. MiN, ;

Erkki Mäkinen State change languages as homomorphic images of Szilard languages

"f TOPIC =T COMP COMP... OBJ

Informatics 2A: Language Complexity and the. Inf2A: Chomsky Hierarchy

Basic Parsing with Context-Free Grammars. Some slides adapted from Julia Hirschberg and Dan Jurafsky 1

Grade 5 + DIGITAL. EL Strategies. DOK 1-4 RTI Tiers 1-3. Flexible Supplemental K-8 ELA & Math Online & Print

Parsing of part-of-speech tagged Assamese Texts

Natural Language Processing. George Konidaris

11/29/2010. Statistical Parsing. Statistical Parsing. Simple PCFG for ATIS English. Syntactic Disambiguation

Enhancing Unlexicalized Parsing Performance using a Wide Coverage Lexicon, Fuzzy Tag-set Mapping, and EM-HMM-based Lexical Probabilities

PRODUCT PLATFORM DESIGN: A GRAPH GRAMMAR APPROACH

KLI: Infer KCs from repeated assessment events. Do you know what you know? Ken Koedinger HCI & Psychology CMU Director of LearnLab

GRAMMAR IN CONTEXT 2 PDF

AP Calculus AB. Nevada Academic Standards that are assessable at the local level only.

ENGBG1 ENGBL1 Campus Linguistics. Meeting 2. Chapter 7 (Morphology) and chapter 9 (Syntax) Pia Sundqvist

A Grammar for Battle Management Language

Name Class Date. Graphing Proportional Relationships

Machine Learning from Garden Path Sentences: The Application of Computational Linguistics

WSU Five-Year Program Review Self-Study Cover Page

BANGLA TO ENGLISH TEXT CONVERSION USING OPENNLP TOOLS

systems have been developed that are well-suited to phenomena in but is properly contained in the indexed languages. We give a

Developing a TT-MCTAG for German with an RCG-based Parser

Compositional Semantics

The New York City Department of Education. Grade 5 Mathematics Benchmark Assessment. Teacher Guide Spring 2013

MGSE: MGSE4.MD.1; MGSE4.MD.2; MGSE4.MD.3; MGSE4.MD.8; MGSE4.MD.4; MGSE4.MD.5; MGSE4.MD.6; MGSE4.MD.7

Parsing with Treebank Grammars: Empirical Bounds, Theoretical Models, and the Structure of the Penn Treebank

Chinese Language Parsing with Maximum-Entropy-Inspired Parser

IT Students Workshop within Strategic Partnership of Leibniz University and Peter the Great St. Petersburg Polytechnic University

Towards a MWE-driven A* parsing with LTAGs [WG2,WG3]

Efficient Normal-Form Parsing for Combinatory Categorial Grammar

Mktg 315 Marketing Research Spring 2015 Sec. 003 W 6:00-8:45 p.m. MBEB 1110

Spring 2016 Stony Brook University Instructor: Dr. Paul Fodor

TOPICS LEARNING OUTCOMES ACTIVITES ASSESSMENT Numbers and the number system

Introduction, Organization Overview of NLP, Main Issues

Parsing natural language

Computer Science 1015F ~ 2016 ~ Notes to Students

Computer Organization I (Tietokoneen toiminta)

Analysis of Probabilistic Parsing in NLP

preassessment was administered)

IAT 888: Metacreation Machines endowed with creative behavior. Philippe Pasquier Office 565 (floor 14)

Specifying Logic Programs in Controlled Natural Language

Teaching and Examination Regulations Master s Degree Programme in Media Studies

Discriminative Learning of Beam-Search Heuristics for Planning

Detecting English-French Cognates Using Orthographic Edit Distance

Chapter 4: Valence & Agreement CSLI Publications

Ch VI- SENTENCE PATTERNS.

An Introduction to the Minimalist Program

LNGT0101 Introduction to Linguistics

LTAG-spinal and the Treebank

ARNE - A tool for Namend Entity Recognition from Arabic Text

PH.D. IN COMPUTER SCIENCE PROGRAM (POST M.S.)

NATURAL LANGUAGE PARSING AND REPRESENTATION IN XML EUGENIO JAROSIEWICZ

Type Theory and Universal Grammar

1/20 idea. We ll spend an extra hour on 1/21. based on assigned readings. so you ll be ready to discuss them in class

Evolution of Collective Commitment during Teamwork

UNIVERSITY OF OSLO Department of Informatics. Dialog Act Recognition using Dependency Features. Master s thesis. Sindre Wetjen

ABSTRACT. A major goal of human genetics is the discovery and validation of genetic polymorphisms

Objectives. Chapter 2: The Representation of Knowledge. Expert Systems: Principles and Programming, Fourth Edition

GENERAL CHEMISTRY I, CHEM 1100 SPRING 2014

What the National Curriculum requires in reading at Y5 and Y6

LLD MATH. Student Eligibility: Grades 6-8. Credit Value: Date Approved: 8/24/15

PHYSICS 40S - COURSE OUTLINE AND REQUIREMENTS Welcome to Physics 40S for !! Mr. Bryan Doiron

CS 101 Computer Science I Fall Instructor Muller. Syllabus

AC : AUTOMATED ONLINE PROCESS TRAINING IN A VIR- TUAL ENVIRONMENT

Grade 6: Correlated to AGS Basic Math Skills

A relational approach to translation

Learning to Think Mathematically With the Rekenrek

School of Innovative Technologies and Engineering

1.11 I Know What Do You Know?

The Role of the Head in the Interpretation of English Deverbal Compounds

Hyperedge Replacement and Nonprojective Dependency Structures

General Physics I Class Syllabus

3. Examinations and final assessment of the degree programmes

An Interactive Intelligent Language Tutor Over The Internet

Houghton Mifflin Reading Correlation to the Common Core Standards for English Language Arts (Grade1)

Presentation skills. Bojan Jovanoski, project assistant. University Skopje Business Start-up Centre

KOREAN 305: ADVANCED KOREAN I (Fall 2017)

Foundations of Knowledge Representation in Cyc

The Interface between Phrasal and Functional Constraints

Character Stream Parsing of Mixed-lingual Text

On the Polynomial Degree of Minterm-Cyclic Functions

Office Location: LOCATION: BS 217 COURSE REFERENCE NUMBER: 93000

Accurate Unlexicalized Parsing for Modern Hebrew

Language Evolution, Metasyntactically. First International Workshop on Bidirectional Transformations (BX 2012)

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

Exploration. CS : Deep Reinforcement Learning Sergey Levine

CSC200: Lecture 4. Allan Borodin

Pre-Processing MRSes

Reinventing College Physics for Biologists: Explicating an Epistemological Curriculum

Transcription:

Context-Free Grammars 2017/09/12 Chapter 2.1 in Sipser Ø Announcement: q Slides for this lecture are here: http://www.public.asu.edu/~yzhan442/teaching/cse355/lectures/cfg.pdf 1

Last time Nonregular languages o Limitations of regular laguages o Pumping lemma o Proving for nonregularity Using pumping lemma FA (DFA & NFA) express Regular Expressions (RE) Using closure properties of RLs Ø Goals: o Learned the limitations of regular languages o Learned how to prove a language is not regular o Learned to use proof by contradiction 2

Summary so far Regular languages o Finite Automata (FA) o Regular expressions (REs) o Equivalence of FA and REs o Nonregular langauges FA (DFA & NFA) express Regular Expressions (RE) RL 3

Summary so far Regular languages Ø Simple computation with FA Ø Intuitive design with FA or RE Ø Decidable computing machine Ø Sometimes too simple e.g., {a n b n } FA (DFA & NFA) express Regular Expressions (RE) RL 4

Outline for today Context free langauges o Context free langauges o Context free grammars q Design CFGs q Ambiguities FA (DFA & NFA) express Regular Expressions (RE) CFL q Chomsky normal form Ø Goals: o Learn context free languages o Learn context free grammars 5

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules FA (DFA & NFA) express Regular Expressions (RE) CFL A! 0A1 B 6

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules Steps to generate a string in the language of a CFG: 1. Write down the start variable. It is the variable on the left-hand side of the top rule, unless specified otherwise. 2. Find a variable that is written down and a rule that starts with that variable. Replace the written down variable with the righthand side of that rule. 3. Repeat step 2 until no variables remain. A! 0A1 B 7

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules Generate 000#111: A 1. Write down the start variable. It is the variable on the left-hand side of the top rule, unless specified otherwise. 2. Find a variable that is written down and a rule that starts with that variable. Replace the written down variable with the right-hand side of that rule. 3. Repeat step 2 until no variables remain. 8

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules Generate 000#111: A => (yields) 0A1 1. Write down the start variable. It is the variable on the left-hand side of the top rule, unless specified otherwise. 2. Find a variable that is written down and a rule that starts with that variable. Replace the written down variable with the right-hand side of that rule. 3. Repeat step 2 until no variables remain. 9

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules Generate 000#111: A => (yields) 0A1 0A1 => 00A11 1. Write down the start variable. It is the variable on the left-hand side of the top rule, unless specified otherwise. 2. Find a variable that is written down and a rule that starts with that variable. Replace the written down variable with the right-hand side of that rule. 3. Repeat step 2 until no variables remain. 10

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules Generate 000#111: A => (yields) 0A1 0A1 => 00A11 00A11 => 000A111 1. Write down the start variable. It is the variable on the left-hand side of the top rule, unless specified otherwise. 2. Find a variable that is written down and a rule that starts with that variable. Replace the written down variable with the right-hand side of that rule. 3. Repeat step 2 until no variables remain. 11

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules Generate 000#111: A => (yields) 0A1 0A1 => 00A11 00A11 => 000A111 000A111 => 000B111 1. Write down the start variable. It is the variable on the left-hand side of the top rule, unless specified otherwise. 2. Find a variable that is written down and a rule that starts with that variable. Replace the written down variable with the right-hand side of that rule. 3. Repeat step 2 until no variables remain. 12

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules Generate 000#111: A => (yields) 0A1 0A1 => 00A11 00A11 => 000A111 000A111 => 000B111 000B111 => 000#111 1. Write down the start variable. It is the variable on the left-hand side of the top rule, unless specified otherwise. 2. Find a variable that is written down and a rule that starts with that variable. Replace the written down variable with the right-hand side of that rule. 3. Repeat step 2 until no variables remain. 13

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules Generate 000#111: A => (yields) 0A1 0A1 => 00A11 00A11 => 000A111 000A111 => 000B111 000B111 => 000#111 A => * (derives) 000#111 1. Write down the start variable. It is the variable on the left-hand side of the top rule, unless specified otherwise. 2. Find a variable that is written down and a rule that starts with that variable. Replace the written down variable with the right-hand side of that rule. 3. Repeat step 2 until no variables remain. 14

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules Generate 000#111: A => * (derives) 000#111 1. Write down the start variable. It is the variable on the left-hand side of the top rule, unless specified otherwise. 2. Find a variable that is written down and a rule that starts with that variable. Replace the written down variable with the right-hand side of that rule. 3. Repeat step 2 until no variables remain. 15

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules FA (DFA & NFA) express Regular Expressions (RE) CFL 16

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules a(b [ c)*c 17

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules a(b c)*c [ [ b c A b c 18

Context-Free Languages Context free grammars (CFGs) start variable variables terminals a(b c)*c [ [ b c A b c (b c)* B AB " [ substituation rules 19

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules a(b c)*c [ b c A b c (b c)* B AB " [ [ [ a(b c)*c C abc which one is the starting symbol? 20

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules a(b c)*c [ b c A b c (b c)* B AB " [ [ [ a(b c)*c C abc What does this tell us? which one is the starting symbol? 21

Context-Free Languages Context free grammars (CFGs) start variable variables terminals substituation rules a(b c)*c [ b c A b c (b c)* B AB " [ [ [ a(b c)*c C abc What does this tell us? CFL RL! which one is the starting symbol? 22

Outline for today Context free langauges o Context free langauges o Context free grammars q Design CFGs q Ambiguities FA (DFA & NFA) express Regular Expressions (RE) CFL q Chomsky normal form Ø Goals: o Learn context free languages o Learn context free grammars 23

Context-Free Human-aware Grammars Robo.cs (CFGs) The language of a CFG G, or L(G) is 24

Context-Free Human-aware Grammars Robo.cs (CFGs) G1: What is R? 25

Context-Free Human-aware Grammars Robo.cs (CFGs) G1: What is R? In exams or homework, you only need to write down the rules 26

Context-Free Human-aware Grammars Robo.cs (CFGs) G1: We can now match parenthesis. Is valid c programs a context free language? 27

Context-Free Human-aware Grammars Robo.cs (CFGs) <statement>!... <if> <for>... <if>! if (<expr>) <statement> if (<expr>) <statement> else <statement> <for>! for (<expr>; <expr>; <expr>) <statement> <expr>! (<expr>) <var> <<num> <var> == <num> <var>++ <num>! <num><num> 0 1... 9 <var>! i j We can now match parenthesis. Is valid c programs a context free language? 28

Context-Free Human-aware Grammars Robo.cs (CFGs) <statement>!... <if> <for>... <if>! if (<expr>) <statement> if (<expr>) <statement> else <statement> <for>! for (<expr>; <expr>; <expr>) <statement> <expr>! (<expr>) <var> <<num> <var> == <num> <var>++ <num>! <num><num> 0 1... 9 <var>! i j We can now match parenthesis. Is valid c programs a context free language? Not really int main() { return 0;} 29

Outline for today Context free langauges o Context free langauges o Context free grammars q Design CFGs q Ambiguities FA (DFA & NFA) express Regular Expressions (RE) CFL q Chomsky normal form Ø Goals: o Learn context free languages o Learn context free grammars 30

Designing CFG Many CFLs are union of simpler CFLs Construct the grammar G i for each simpler language L i with start variable S i Combine the rules with a new rule e.g., Connection between two parts {0 n 1 n } One structure within the another (recursive structures): <statement>!... <if> <for>... <if>! if (<expr>) <statement> if (<expr>) <statement> else <statement> <for>! for (<expr>; <expr>; <expr>) <statement> <expr>! (<expr>) <var> <<num> <var> == <num> <var>++ <num>! <num><num> 0 1... 9 <var>! i j 31

Designing CFG for RL Construct CFG for a regular language 1. Construct a DFA D = (Q,,,q 0,F) for the RL 2. Convert the DFA into CFG R i for each q i 2 Q R i! ar j if (q i,a)=q j R i! " if q i 2 F R 0 is the start variable 32

Designing CFG for RL Construct CFG for a regular language 1. Construct a DFA D = (Q,,,q 0,F) for the RL 2. Convert the DFA into CFG What does this tell us? CFL RL! R i for each q i 2 Q R i! ar j if (q i,a)=q j R i! " if q i 2 F R 0 is the start variable R 1! 0R 1 R 1! 1R 2 R 2! 1R 2 R 2! 0R 3 R 3! 0R 2 R 3! 0R 2 R 2! " 33

Outline for today Context free langauges o Context free langauges o Context free grammars q Design CFGs q Ambiguities FA (DFA & NFA) express Regular Expressions (RE) CFL q Chomsky normal form Ø Goals: o Learn context free languages o Learn context free grammars 34

Ambiguity Different meanings => Different parse trees Consider a + a 35

Ambiguity Different meanings => Different parse trees Consider a + a Even though the substitution orderings are different, the parse trees are the same So are the meanings! 36

Ambiguity Different meanings => Different parse trees Consider a + a A derivation of a string w in a grammar G is a leftmost derivation if at every step the leftmost remaining variable is the one replaced. Certain languages are inherently ambiguous 37

Ambiguity Consider a + a a 38

Ambiguity Consider a + a a Generate a + a x a (using leftmost derivation): 39

Ambiguity Consider a + a a Generate a + a x a (using leftmost derivation): E => E + T E + T => T + T T + T => F + T F + T => a + T a + T => a + T x F a + T x F => a + F x F a + F x F => a + a x F a + a x F => a + a x a 40

Outline for today Context free langauges o Context free langauges o Context free grammars q Design CFGs q Ambiguities q Chomsky normal form FA (DFA & NFA) express Regular Expressions (RE) CFL Ø Goals: o Learn context free languages o Learn context free grammars 41

Chomsky Normal Form 42

Chomsky Normal Form Remove "-rules Remove unit rules (with a single variable on the right hand side) Chomsky normal form Remove rules with more than two compnents (variables or terminals) 43

Chomsky Normal Form 44

Chomsky Normal Form 45

Chomsky Normal Form 46

Chomsky Normal Form 47

Chomsky Normal Form 48

Outline for today Context free langauges o Context free langauges o Context free grammars q Design CFGs q Ambiguities FA (DFA & NFA) express Regular Expressions (RE) CFL q Chomsky normal form Ø Goals: o Learned context free languages o Learned context free grammars Reading assignment for the next class: o Sipser Sec. 2.2 (up to page 118, before the formal proof) Quiz link will be sent out; due date is before the beginning of the next class 49