Lecture 9: More on Grammars

Similar documents
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

Grammars & Parsing, Part 1:

CS 598 Natural Language Processing

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

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

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

Parsing of part-of-speech tagged Assamese Texts

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

Language properties and Grammar of Parallel and Series Parallel Languages

Refining the Design of a Contracting Finite-State Dependency Parser

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

Context Free Grammars. Many slides from Michael Collins

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

GRAMMAR IN CONTEXT 2 PDF

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

A General Class of Noncontext Free Grammars Generating Context Free Languages

Proof Theory for Syntacticians

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

GACE Computer Science Assessment Test at a Glance

Some Principles of Automated Natural Language Information Extraction

WSU Five-Year Program Review Self-Study Cover Page

"f TOPIC =T COMP COMP... OBJ

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

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

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

Compositional Semantics

Chinese Language Parsing with Maximum-Entropy-Inspired Parser

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

AGS THE GREAT REVIEW GAME FOR PRE-ALGEBRA (CD) CORRELATED TO CALIFORNIA CONTENT STANDARDS

Natural Language Processing. George Konidaris

Hans-Ulrich Block, Hans Haugeneder Siemens AG, MOnchen ZT ZTI INF W. Germany. (2) [S' [NP who][s does he try to find [NP e]]s IS' $=~

South Carolina English Language Arts

Parallel Evaluation in Stratal OT * Adam Baker University of Arizona

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

The presence of interpretable but ungrammatical sentences corresponds to mismatches between interpretive and productive parsing.

Type Theory and Universal Grammar

Specifying Logic Programs in Controlled Natural Language

SINGLE DOCUMENT AUTOMATIC TEXT SUMMARIZATION USING TERM FREQUENCY-INVERSE DOCUMENT FREQUENCY (TF-IDF)

Learning to Think Mathematically With the Rekenrek

Grade 6: Correlated to AGS Basic Math Skills

BANGLA TO ENGLISH TEXT CONVERSION USING OPENNLP TOOLS

Rule discovery in Web-based educational systems using Grammar-Based Genetic Programming

COMPUTATIONAL COMPLEXITY OF LEFT-ASSOCIATIVE GRAMMAR

Hyperedge Replacement and Nonprojective Dependency Structures

Modeling Attachment Decisions with a Probabilistic Parser: The Case of Head Final Structures

Developing a concrete-pictorial-abstract model for negative number arithmetic

AQUA: An Ontology-Driven Question Answering System

arxiv: v1 [cs.cv] 10 May 2017

ARNE - A tool for Namend Entity Recognition from Arabic Text

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

Universiteit Leiden ICT in Business

Math 96: Intermediate Algebra in Context

The Discourse Anaphoric Properties of Connectives

preassessment was administered)

Physics 270: Experimental Physics

A Version Space Approach to Learning Context-free Grammars

CS 1103 Computer Science I Honors. Fall Instructor Muller. Syllabus

Statewide Framework Document for:

Numeracy Medium term plan: Summer Term Level 2C/2B Year 2 Level 2A/3C

Analysis of Probabilistic Parsing in NLP

Chunk Parsing for Base Noun Phrases using Regular Expressions. Let s first let the variable s0 be the sentence tree of the first sentence.

Math-U-See Correlation with the Common Core State Standards for Mathematical Content for Third Grade

Introduction to HPSG. Introduction. Historical Overview. The HPSG architecture. Signature. Linguistic Objects. Descriptions.

Welcome to the Purdue OWL. Where do I begin? General Strategies. Personalizing Proofreading

Content Language Objectives (CLOs) August 2012, H. Butts & G. De Anda

Efficient Normal-Form Parsing for Combinatory Categorial Grammar

Software Development: Programming Paradigms (SCQF level 8)

CS 101 Computer Science I Fall Instructor Muller. Syllabus

PowerTeacher Gradebook User Guide PowerSchool Student Information System

Computer Organization I (Tietokoneen toiminta)

Mathematics Assessment Plan

Chapter 4: Valence & Agreement CSLI Publications

Houghton Mifflin Online Assessment System Walkthrough Guide

Focus of the Unit: Much of this unit focuses on extending previous skills of multiplication and division to multi-digit whole numbers.

Netsmart Sandbox Tour Guide Script

Organizational Knowledge Distribution: An Experimental Evaluation

KBS : Knowledge Representation. Motivation. Epistemology. Objectives

Pre-Algebra A. Syllabus. Course Overview. Course Goals. General Skills. Credit Value

Learning Computational Grammars

NATURAL LANGUAGE PARSING AND REPRESENTATION IN XML EUGENIO JAROSIEWICZ

The Interface between Phrasal and Functional Constraints

Lesson M4. page 1 of 2

Introduction, Organization Overview of NLP, Main Issues

CAAP. Content Analysis Report. Sample College. Institution Code: 9011 Institution Type: 4-Year Subgroup: none Test Date: Spring 2011

Guidelines for Writing an Internship Report

School of Innovative Technologies and Engineering

Improving Fairness in Memory Scheduling

cambridge occasional papers in linguistics Volume 8, Article 3: 41 55, 2015 ISSN

DRAFT VERSION 2, 02/24/12

Mathematics. Mathematics

Identifying Novice Difficulties in Object Oriented Design

The Strong Minimalist Thesis and Bounded Optimality

The College Board Redesigned SAT Grade 12

Montana Content Standards for Mathematics Grade 3. Montana Content Standards for Mathematical Practices and Mathematics Content Adopted November 2011

MULTILINGUAL INFORMATION ACCESS IN DIGITAL LIBRARY

TABE 9&10. Revised 8/2013- with reference to College and Career Readiness Standards

School Inspection in Hesse/Germany

An Interactive Intelligent Language Tutor Over The Internet

Function Number 1 Work as part of a team. Thorough knowledge of theoretical procedures and ability to integrate knowledge and performance into

Transcription:

Lecture 9: More on Grammars Dr Kieran T. Herley Department of Computer Science University College Cork 2016/17 KH (11/10/16) Lecture 9: More on Grammars 2016/17 1 / 1

Expressive Power of CFGs Not every language is describable using CFG notation; e.g. {a n b n c n : n 0} But syntax of most programming languages can be captured by CFG and are generally designed with this in mind Many aspects of programming language syntax stem from this KH (11/10/16) Lecture 9: More on Grammars 2016/17 2 / 1

Extended Notations Backus-Naur Notation BNF Essentially our CFG notation: non-terminals in <>, terminals without 1 EBNF: Extended BNF Grammar metasymbols {α} mean zero or more occurrences of α Example: term factor { ( * / ) factor } means term can be replaced by factor followed by zero or more factor s separated by + s and - s. Terminals ater shown in red to distinguish terminal ( from metasymbol (. 1 But BNF traditionally uses ::= symbol instead of. KH (11/10/16) Lecture 9: More on Grammars 2016/17 3 / 1

Extended Notations EBNF Grammar for Simple Arithmetic Expressions expr term { ( + - ) term } term factor { ( * / ) factor } factor NUM ID ( expr ) KH (11/10/16) Lecture 9: More on Grammars 2016/17 4 / 1

Extended Notations Syntax Diagrams Diagrammatic representation occasionally used to summarize programming language syntax term factor { ( * / ) factor } Essentially one diagram per production. Arguably more human-friendly than BNF, but less useful for compiler tools as we will see later on KH (11/10/16) Lecture 9: More on Grammars 2016/17 5 / 1

Ambiguity Ambiguity Some grammars are ambiguous string string + string string string - string string 0 1 9 Allows two different parse-trees/derivations for some strings 2 Ambiguity is generally undesirable for programming-language grammars: allows alternative interpretations of what code means. 2 Technically sentences will have distinct right-derivations: derivation in which rightmost nonterminal is the one replaced at each stage. KH (11/10/16) Lecture 9: More on Grammars 2016/17 6 / 1

Ambiguity Example string string + string string string - string string 0 1 9 9 5 2? KH (11/10/16) Lecture 9: More on Grammars 2016/17 7 / 1

Ambiguity Another Example S S + S S S * S S ( S ) S a Here a stand for any integer literal KH (11/10/16) Lecture 9: More on Grammars 2016/17 8 / 1

Ambiguity Why Does It Matter? Ambiguity can cause complicate our attempt to understand the meaning of a string May get two different meanings or interpretations for ambiguous string: KH (11/10/16) Lecture 9: More on Grammars 2016/17 9 / 1

Ambiguity The Dangling Else Problem statement if-stmt other if-stmt if ( exp ) statement if ( exp ) statement else statement exp 0 1 Consider if (0) if (1) other else other Dilemma: to which if does the else belong? KH (11/10/16) Lecture 9: More on Grammars 2016/17 10 / 1

Ambiguity Two Possible Parse Trees Which is the correct interpretation for if (0) if (1) other else other? Some languages live with the ambiguity by adopting the rule that the else matches the most closely nested if not yet coupled with an else (i.e. second tree) KH (11/10/16) Lecture 9: More on Grammars 2016/17 11 / 1

Ambiguity Interpretation 1 if (0) if (1) other else other? Else attaches to outer if KH (11/10/16) Lecture 9: More on Grammars 2016/17 12 / 1

Ambiguity Interpretation 2 if (0) if (1) other else other Else attaches to inner if KH (11/10/16) Lecture 9: More on Grammars 2016/17 13 / 1

Ambiguity Aside Can also re-engineer grammar to work around the problem statement matched-stmt unmatched-stmt matched-stmt if ( exp ) matched-stmt else matched-stmt unmatched-stmt if ( exp ) statement if ( exp ) matched-stmt else unmatched-stmt exp 0 1 KH (11/10/16) Lecture 9: More on Grammars 2016/17 14 / 1

Grammar for Tiny Tiny Grammar program stmtseq stmtseq stmtseq ; statement statement statement ifstmt repeatstmt assignstmt readstmt writestmt Note: i) program as sequence of statements; (ii) each individual statement can be of be of five differnet varieties KH (11/10/16) Lecture 9: More on Grammars 2016/17 15 / 1

Grammar for Tiny Sequences Production stmtseq stmtseq ; statement statement Form stmtseq we can derive statement statement ; statement statement ; statement ; statement The grammar captures idea that semicolons separate statements KH (11/10/16) Lecture 9: More on Grammars 2016/17 16 / 1

Grammar for Tiny Tiny Grammar cont d ifstmt if exp then stmtseq end if exp then stmtseq else stmtseq end repeatstmt repeat stmtseq until exp assignstmt identifier := exp readstmt read identifier writestmt write exp KH (11/10/16) Lecture 9: More on Grammars 2016/17 17 / 1

Grammar for Tiny Dangling Else? ifstmt if exp then stmtseq end if exp then stmtseq else stmtseq end KH (11/10/16) Lecture 9: More on Grammars 2016/17 18 / 1

Grammar for Tiny Tiny Grammar cont d exp simple-expr comp-op simple-expr simple-expr comp-op < = simple-expr simple-expr addop term term addop + - term term mulop factor factor mulop * / factor ( exp ) number identifier KH (11/10/16) Lecture 9: More on Grammars 2016/17 19 / 1

Grammar for Tiny Grammar for Java cont d Can find grammars for most programming languages e.g. [Java Grammar] 3 Can use these to facilitate generation of parsers 3 Google bnf grammar for java KH (11/10/16) Lecture 9: More on Grammars 2016/17 20 / 1

Grammar for Tiny Some Tiny Examples test1.tny write 17 test2.tny read x; write x fact.tny { Sample program in TINY language computes factorial } read x; { input an integer } if 0 < x then { don t compute if x 0 } fact := 1; repeat fact := fact x; x := x 1 until x = 0; write fact { output factorial of x } end KH (11/10/16) Lecture 9: More on Grammars 2016/17 21 / 1

Grammar for Tiny Tiny Example 1 test1.tny write 17 KH (11/10/16) Lecture 9: More on Grammars 2016/17 22 / 1

Grammar for Tiny Tiny Example 2 test2.tny read x; write x KH (11/10/16) Lecture 9: More on Grammars 2016/17 23 / 1

Grammar for Tiny Tiny Example 3 KH (11/10/16) Lecture 9: More on Grammars 2016/17 24 / 1

CFGs and Pushdown Automata Fact For every regular expression there is an equivalent finite automaton and vice versa. Fact For every context-free grammar there is an equivalent pushdown automaton and vice versa. KH (11/10/16) Lecture 9: More on Grammars 2016/17 25 / 1

CFGs and Pushdown Automata Pushdown Automata Next Step dictated by next input symbol top stack symbol Each Step involves change state of finite control push/pop symbol on/off stack advance one symbol in input KH (11/10/16) Lecture 9: More on Grammars 2016/17 26 / 1