Ambiguous grammar - Wikipedia, the free encyclopedia

Similar documents
Language properties and Grammar of Parallel and Series Parallel Languages

COMPUTATIONAL COMPLEXITY OF LEFT-ASSOCIATIVE GRAMMAR

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

A General Class of Noncontext Free Grammars Generating Context Free Languages

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

Enumeration of Context-Free Languages and Related Structures

Proof Theory for Syntacticians

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

A Version Space Approach to Learning Context-free Grammars

GRAMMAR IN CONTEXT 2 PDF

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

An Interactive Intelligent Language Tutor Over The Internet

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

Parsing of part-of-speech tagged Assamese Texts

Grammars & Parsing, Part 1:

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

On the Polynomial Degree of Minterm-Cyclic Functions

Context Free Grammars. Many slides from Michael Collins

AQUA: An Ontology-Driven Question Answering System

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

Refining the Design of a Contracting Finite-State Dependency Parser

Action Models and their Induction

The Strong Minimalist Thesis and Bounded Optimality

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

Specification and Evaluation of Machine Translation Toy Systems - Criteria for laboratory assignments

Abstractions and the Brain

GUIDE TO THE CUNY ASSESSMENT TESTS

GACE Computer Science Assessment Test at a Glance

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

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

The Interface between Phrasal and Functional Constraints

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

Specifying Logic Programs in Controlled Natural Language

CS 598 Natural Language Processing

Approaches to control phenomena handout Obligatory control and morphological case: Icelandic and Basque

Colossians Study Guide Executable Outlines

Grade 6: Module 1: Unit 2: Lesson 5 Building Vocabulary: Working with Words about the Key Elements of Mythology

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

Data Structures and Algorithms

Fragment Analysis and Test Case Generation using F- Measure for Adaptive Random Testing and Partitioned Block based Adaptive Random Testing

Self Study Report Computer Science

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

Sample Problems for MATH 5001, University of Georgia

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

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

Natural Language Processing. George Konidaris

ARNE - A tool for Namend Entity Recognition from Arabic Text

The Discourse Anaphoric Properties of Connectives

Efficient Normal-Form Parsing for Combinatory Categorial Grammar

Introduction to Ensemble Learning Featuring Successes in the Netflix Prize Competition

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' $=~

Different Requirements Gathering Techniques and Issues. Javaria Mushtaq

Program Matrix - Reading English 6-12 (DOE Code 398) University of Florida. Reading

Loughton School s curriculum evening. 28 th February 2017

Ensemble Technique Utilization for Indonesian Dependency Parser

Procedia - Social and Behavioral Sciences 154 ( 2014 )

What the National Curriculum requires in reading at Y5 and Y6

Notes on The Sciences of the Artificial Adapted from a shorter document written for course (Deciding What to Design) 1

Some Principles of Automated Natural Language Information Extraction

Aspectual Classes of Verb Phrases

and secondary sources, attending to such features as the date and origin of the information.

International School of Kigali, Rwanda

Hyperedge Replacement and Nonprojective Dependency Structures

Type Theory and Universal Grammar

POLA: a student modeling framework for Probabilistic On-Line Assessment of problem solving performance

arxiv: v1 [math.at] 10 Jan 2016

LTAG-spinal and the Treebank

A Context-Driven Use Case Creation Process for Specifying Automotive Driver Assistance Systems

PIRLS. International Achievement in the Processes of Reading Comprehension Results from PIRLS 2001 in 35 Countries

The College Board Redesigned SAT Grade 12

Lecture 1: Machine Learning Basics

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

Pre-Processing MRSes

Probability and Game Theory Course Syllabus

Automating the E-learning Personalization

AGENDA. Truths, misconceptions and comparisons. Strategies and sample problems. How The Princeton Review can help

Diagnostic Test. Middle School Mathematics

An Introduction to the Minimalist Program

Analysis of Probabilistic Parsing in NLP

THESIS GUIDE FORMAL INSTRUCTION GUIDE FOR MASTER S THESIS WRITING SCHOOL OF BUSINESS

Shared Mental Models

Assignment 1: Predicting Amazon Review Ratings

South Carolina English Language Arts

Pragmatic Use Case Writing

Transfer Learning Action Models by Measuring the Similarity of Different Domains

CLASSIFICATION OF TEXT DOCUMENTS USING INTEGER REPRESENTATION AND REGRESSION: AN INTEGRATED APPROACH

I N T E R P R E T H O G A N D E V E L O P HOGAN BUSINESS REASONING INVENTORY. Report for: Martina Mustermann ID: HC Date: May 02, 2017

University of Groningen. Systemen, planning, netwerken Bosman, Aart

IS USE OF OPTIONAL ATTRIBUTES AND ASSOCIATIONS IN CONCEPTUAL MODELING ALWAYS PROBLEMATIC? THEORY AND EMPIRICAL TESTS

Learning to Think Mathematically with the Rekenrek Supplemental Activities

Practical Research Planning and Design Paul D. Leedy Jeanne Ellis Ormrod Tenth Edition

We are strong in research and particularly noted in software engineering, information security and privacy, and humane gaming.

Parsing natural language

Bittinger, M. L., Ellenbogen, D. J., & Johnson, B. L. (2012). Prealgebra (6th ed.). Boston, MA: Addison-Wesley.

LEXICAL COHESION ANALYSIS OF THE ARTICLE WHAT IS A GOOD RESEARCH PROJECT? BY BRIAN PALTRIDGE A JOURNAL ARTICLE

Software Security: Integrating Secure Software Engineering in Graduate Computer Science Curriculum

21st CENTURY SKILLS IN 21-MINUTE LESSONS. Using Technology, Information, and Media

A Comparison of Standard and Interval Association Rules

Grade 5: Module 3A: Overview

Learning Disability Functional Capacity Evaluation. Dear Doctor,

Transcription:

Ambiguous grammar From Wikipedia, the free encyclopedia In computer science, an ambiguous grammar is a context-free grammar for which there exists a string that can have more than one leftmost derivation, while an unambiguous grammar is a context-free grammar for which every valid string has a unique leftmost derivation. Many languages admit both ambiguous and unambiguous grammars, while some languages admit only ambiguous grammars. Any non-empty language admits an ambiguous grammar by taking an unambiguous grammar and introducing a duplicate rule or synonym (the only language without ambiguous grammars is the empty language). A language that only admits ambiguous grammars is called an inherently ambiguous language, and there are inherently ambiguous context-free languages. Deterministic context-free grammars are always unambiguous, and are an important subclass of unambiguous CFGs; there are non-deterministic unambiguous CFGs, however. For real-world programming languages, the reference CFG is often ambiguous, due to issues such as the dangling else problem. If present, these ambiguities are generally resolved by adding precedence rules or other context-sensitive parsing rules, so the overall phrase grammar is unambiguous. Contents 1 Examples 1.1 Trivial language 1.2 Unary string 1.3 Addition and subtraction 1.4 Dangling else 2 Recognizing ambiguous grammars 3 Inherently ambiguous languages 4 See also 5 References 6 External links Examples Trivial language The simplest example is the following ambiguous grammar for the trivial language, which consists of only the empty string: 1 of 6 15-01-29 7:51 AM

A ε B ε meaning that the empty string ϵ can be produced by either of two equivalent productions, and thus has two leftmost derivations. Another ambiguous grammar for the trivial language is: A A ε meaning that a production can either be itself again, or the empty string. Thus the empty string has leftmost derivations of length 1, 2, 3, and indeed of any length, depending on how many times the rule A A is used. This language also has the unambiguous grammar, consisting of a single production rule: A ε meaning that the unique production can only produce the empty string, which is the unique string in the language. In the same way, any grammar for a non-empty language can be made ambiguous by adding duplicates. Unary string The regular language of unary strings of a given character, say 'a' (the regular expression a*), has the unambiguous grammar: A aa ε but also has the ambiguous grammar: A aa Aa ε These correspond to producing a right-associative tree (for the unambiguous grammar) or allowing both left- and right- association. This is elaborated below. Addition and subtraction The context free grammar A A + A A A a is ambiguous since there are two leftmost derivations for the string a + a + a: 2 of 6 15-01-29 7:51 AM

A A + A A A + A a + A a + A + A a + a + A a + a + a A + A + A (First A is replaced by A+A. Replacement of the second A would yield a similar derivation) a + A + A a + a + A a + a + a As another example, the grammar is ambiguous since there are two parse trees for the string a + a a: The language that it generates, however, is not inherently ambiguous; the following is a non-ambiguous grammar generating the same language: A A + a A a a Dangling else A common example of ambiguity in real-world programming languages is the dangling else problem. In many languages, the else in an If then( else) statement is optional, which results in nested conditionals being ambiguous, at least in terms of the CFG. Concretely, in many languages one may write conditionals in two forms: the if-then form, and the if-then-else form the else clause is optional: In a grammar containing the rules Statement = if Condition then Statement if Condition then Statement else Statement... Condition =... some ambiguous phrase structures can appear. The expression if a then if b then s else s2 3 of 6 15-01-29 7:51 AM

can be parsed as either if a then (if b then s) else s2 or as if a then (if b then s else s2) depending on whether the else is associated with the first if or second if. This is resolved in various ways in different languages. Sometimes the CFG is modified so that it is unambiguous, such as by requiring an endif statement or making else mandatory. In other cases the CFG is left ambiguous, but the ambiguity is resolved by making the overall phrase grammar contextsensitive, such as by associating an else with the nearest if. In this latter case the grammar is unambiguous, but the CF grammar is ambiguous. Recognizing ambiguous grammars The general decision problem of whether a grammar is ambiguous is undecidable because it can be shown that it is equivalent to the Post correspondence problem. [1] At least, there are tools implementing some semi-decision procedure for detecting ambiguity of context-free grammars. [2] The efficiency of context-free grammar parsing is determined by the automaton that accepts it. Deterministic context-free grammars are accepted by deterministic pushdown automata and can be parsed in linear time, for example by the LR parser. [3] This is a subset of the context-free grammars which are accepted by the pushdown automaton and can be parsed in polynomial time, for example by the CYK algorithm. Unambiguous context-free grammars can be nondeterministic. For example, the language of even-length palindromes on the alphabet of 0 and 1 has the unambiguous context-free grammar S 0S0 1S1 ε. An arbitrary string of this language cannot be parsed without reading all its letters first which means that a pushdown automaton has to try alternative state transitions to accommodate for the different possible lengths of a semi-parsed string. [4] Nevertheless, removing grammar ambiguity may produce a deterministic context-free grammar and thus allow for more efficient parsing. Compiler generators such as YACC include features for resolving some kinds of ambiguity, such as by using the precedence and associativity constraints. Inherently ambiguous languages Inherent ambiguity was proven with Parikh's theorem in 1961 by Rohit Parikh in an MIT research report. [5] While some context-free languages (the set of strings that can be generated by a grammar) have both ambiguous and unambiguous grammars, there exist context-free languages for which no unambiguous context-free grammar can exist. An example of an inherently ambiguous language is the union of 4 of 6 15-01-29 7:51 AM

with. This set is context-free, since the union of two context-free languages is always context-free. But Hopcroft & Ullman (1979) give a proof that there is no way to unambiguously parse strings in the (non-context-free) subset which is the intersection of these two languages. [6] See also GLR parser, a type of parser for ambiguous and nondeterministic grammars Chart parser, another type of parser for ambiguous grammars Semantic ambiguity References 1. ^ Hopcroft, Motwani, Ullman (2001), Theorem 9.20, p.405-406 2. ^ Axelsson, Roland; Heljanko, Keijo; Lange, Martin (2008). "Analyzing Context-Free Grammars Using an Incremental SAT Solver". Proceedings of the 35th International Colloquium on Automata, Languages and Programming (ICALP'08), Reykjavik, Iceland. Lecture Notes in Computer Science 5126. Springer-Verlag. pp. 410 422. 3. ^ Knuth, D. E. (July 1965). "On the translation of languages from left to right" (http://www.cs.dartmouth.edu /~mckeeman/cs48/mxcom/doc/knuth65.pdf). Information and Control 8 (6): 607 639. doi:10.1016/s0019-9958(65)90426-2 (https://dx.doi.org/10.1016%2fs0019-9958%2865%2990426-2). Retrieved 29 May 2011. 4. ^ Hopcroft, John; Motwani, Rajeev; Ullman, Jeffrey (2001). Introduction to automata theory, languages, and computation (2nd ed.). Addison-Wesley. pp. 249 253. 5. ^ Parikh, Rohit (January 1961). Language-generating devices. Quarterly Progress Report, Research Laboratory of Electronics, MIT. 6. ^ p.99-103, Sect.4.7 Gross, Maurice (September 1964). "Inherent ambiguity of minimal linear grammars". Information and Control (Information and Control) 7 (3): 366 368. doi:10.1016/s0019-9958(64)90422-x (https://dx.doi.org/10.1016%2fs0019-9958%2864%2990422-x). Michael, Harrison (1978). Introduction to Formal Language Theory. Addison-Wesley. ISBN 0201029553. Hopcroft, John E.; Ullman, Jeffrey D. (1979). Introduction to Automata Theory, Languages, and Computation (1st ed.). Addison-Wesley. Hopcroft, John; Mowani, Rajeev; Ullman, Jeffrey (2001). Introduction to Automata Theory, Languages and Computation (2nd ed.). Addison Wesley. p. 217. Brabrand, Claus; Giegerich, Robert; Møller, Anders (March 2010). "Analyzing Ambiguity of 5 of 6 15-01-29 7:51 AM

Context-Free Grammars". Science of Computer Programming (Elsevier) 75 (3): 176 191. doi:10.1016/j.scico.2009.11.002 (https://dx.doi.org/10.1016%2fj.scico.2009.11.002). External links dk.brics.grammar (http://www.brics.dk/grammar) - a grammar ambiguity analyzer. CFGAnalyzer (http://www2.tcs.ifi.lmu.de/~mlange/cfganalyzer/index.html) - tool for analyzing context-free grammars with respect to language universality, ambiguity, and similar properties. Retrieved from "http://en.wikipedia.org/w/index.php?title=ambiguous_grammar&oldid=637748029" Categories: Formal languages This page was last modified on 12 December 2014, at 09:05. Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization. 6 of 6 15-01-29 7:51 AM