UNIT III SYNTAX ANALYSIS

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

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

Grammars & Parsing, Part 1:

Parsing of part-of-speech tagged Assamese Texts

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

A Version Space Approach to Learning Context-free Grammars

Proof Theory for Syntacticians

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

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

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

GACE Computer Science Assessment Test at a Glance

Some Principles of Automated Natural Language Information Extraction

COMPUTATIONAL COMPLEXITY OF LEFT-ASSOCIATIVE GRAMMAR

Version Space. Term 2012/2013 LSI - FIB. Javier Béjar cbea (LSI - FIB) Version Space Term 2012/ / 18

Linking Task: Identifying authors and book titles in verbose queries

CS 598 Natural Language Processing

Natural Language Processing. George Konidaris

Software Maintenance

AQUA: An Ontology-Driven Question Answering System

Compositional Semantics

The Interface between Phrasal and Functional Constraints

An Introduction to the Minimalist Program

Grade 6: Correlated to AGS Basic Math Skills

Learning goal-oriented strategies in problem solving

Chinese Language Parsing with Maximum-Entropy-Inspired Parser

A Neural Network GUI Tested on Text-To-Phoneme Mapping

"f TOPIC =T COMP COMP... OBJ

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

An Interactive Intelligent Language Tutor Over The Internet

BANGLA TO ENGLISH TEXT CONVERSION USING OPENNLP TOOLS

Abstractions and the Brain

Disambiguation of Thai Personal Name from Online News Articles

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

Radius STEM Readiness TM

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

PRODUCT PLATFORM DESIGN: A GRAPH GRAMMAR APPROACH

Specifying Logic Programs in Controlled Natural Language

PowerTeacher Gradebook User Guide PowerSchool Student Information System

Ensemble Technique Utilization for Indonesian Dependency Parser

Multimedia Application Effective Support of Education

arxiv: v1 [cs.cv] 10 May 2017

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

Houghton Mifflin Online Assessment System Walkthrough Guide

Physics 270: Experimental Physics

ReinForest: Multi-Domain Dialogue Management Using Hierarchical Policies and Knowledge Ontology

Semi-supervised methods of text processing, and an application to medical concept extraction. Yacine Jernite Text-as-Data series September 17.

Language properties and Grammar of Parallel and Series Parallel Languages

Parallel Evaluation in Stratal OT * Adam Baker University of Arizona

Chapter 2 Rule Learning in a Nutshell

A Minimalist Approach to Code-Switching. In the field of linguistics, the topic of bilingualism is a broad one. There are many

OCR for Arabic using SIFT Descriptors With Online Failure Prediction

EdIt: A Broad-Coverage Grammar Checker Using Pattern Grammar

Millersville University Degree Works Training User Guide

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

A General Class of Noncontext Free Grammars Generating Context Free Languages

Moodle 2 Assignments. LATTC Faculty Technology Training Tutorial

Guidelines for Writing an Internship Report

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

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

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

Creating a Test in Eduphoria! Aware

South Carolina English Language Arts

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

Character Stream Parsing of Mixed-lingual Text

SEMAFOR: Frame Argument Resolution with Log-Linear Models

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

The Discourse Anaphoric Properties of Connectives

Using dialogue context to improve parsing performance in dialogue systems

The Smart/Empire TIPSTER IR System

Detecting English-French Cognates Using Orthographic Edit Distance

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

Prediction of Maximal Projection for Semantic Role Labeling

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

Implementing a tool to Support KAOS-Beta Process Model Using EPF

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

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

Circuit Simulators: A Revolutionary E-Learning Platform

DegreeWorks Advisor Reference Guide

Visual CP Representation of Knowledge

Hyperedge Replacement and Nonprojective Dependency Structures

Appendix L: Online Testing Highlights and Script

Preferences...3 Basic Calculator...5 Math/Graphing Tools...5 Help...6 Run System Check...6 Sign Out...8

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

Pre-Processing MRSes

Algebra 1, Quarter 3, Unit 3.1. Line of Best Fit. Overview

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

Module 12. Machine Learning. Version 2 CSE IIT, Kharagpur

On-Line Data Analytics

New Features & Functionality in Q Release Version 3.1 January 2016

School of Innovative Technologies and Engineering

NATURAL LANGUAGE PARSING AND REPRESENTATION IN XML EUGENIO JAROSIEWICZ

How to analyze visual narratives: A tutorial in Visual Narrative Grammar

Seminar - Organic Computing

Context Free Grammars. Many slides from Michael Collins

On the Polynomial Degree of Minterm-Cyclic Functions

have to be modeled) or isolated words. Output of the system is a grapheme-tophoneme conversion system which takes as its input the spelling of words,

Introduction to Causal Inference. Problem Set 1. Required Problems

Schoology Getting Started Guide for Teachers

LTAG-spinal and the Treebank

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

Transcription:

UNIT III SYNTAX ANALYSIS 2 Marks 1. Eliminate the left recursion from the following grammar A->Ac Aad bd c The rule to eliminate the left recursion is A Aα βâ can be converted as A βa and A αa ε. So the grammar after eliminating left recursion is A->bdA c A A ->c A ad A εå 2. What are the disadvantages of operator precedence parsing? The operator, like minus (unary and binary) has two different precedence. Hence it is hard to handle tokens like minus sign. This kind of parsing is applicable to only small class of grammars. 3. Construct a parse tree of (a+b)*c for the grammar E->E+E E*E (E) id. 4. Derive the string and construct a syntax tree for the input string ceaedbe using the grammar S->SaA A, A->AbB B, B->cSd e. Derivation: S=> A (S->A) => AbB (A->AbB) => BbB (A->B) => csdbb (B->cSd) => csaadbb (S->SaA) => caaadbb (S->A) => cbaadbb (A->B) => ceaadbb (B->e) =>ceabdbb (A->B) =>ceaedbb (B->e) =>ceaedbe (B->e)

5. List the factors to be considered for top-down parsing. Top down parsing is an attempt to find a leftmost derivation for an input string. Left recursive grammar can cause a top-down parser to go into an indefinite loop on writing procedure. Backtracking overhead may occur Due to backtracking, it may reject some valid sentences Left factoring Ambiguity The order in which alternates are tried can affect the language accepted When failure is reported, we have very little idea where the error actually occurred 6. What is an ambiguous grammar? A grammar G is said to be ambiguous if it generates more than one parse tree for some sentence of language L(G).i.e. both leftmost and rightmost derivations are same for the given sentence. 7. What is a predictive parser? It is a top down parser. It is a program based on a transition diagram attempts to match the terminal symbols against the input and makes a recursive procedure call whenever it has to follow an edge labeled by a non terminal. A non recursive predictive parser is a program that matches the terminal symbols against the input by maintaining a stack rather than using recursive calls. 8. What is CLR?

CLR stands for canonical LR parser. It is a bottom up parsing technique. L stands for left to right scanning of the input and R stands for constricting a rightmost derivation in reverse. 9. What do u meant by parser and its types? A parser for grammar G is a program that takes as input a string w and produces as output either a parse tree for w, if w is a sentence of G, or an error message indicating that w is not a sentence of G. it obtains a string of tokens from the lexical analyzer, verifies that the string generated by the grammar for the source language. a) Top down parsing b) Bottom up parsing 10. What are the different levels of syntax error handler? a) Lexical, such as misspelling an identifier, keyword, or operator. b) Syntactic, such as an arithmetic expression with unbalanced parentheses c) Semantic, such as operator applied to an incompatible operand d) Logical, such as an infinitely recursive call. 11. What are the goals of error handler in a parser? i) It should report the presence of errors clearly and accurately ii) It should recover from each error quickly enough to be able to detect subsequent errors iii) It should not significantly slow down the processing of correct programs. 12. What are error recovery strategies in parser? a) Panic mode b) Phrase level c) Error productions d) Global corrections 13. Define CFG? Many programming language has rules that prescribe the syntactic structure of well-formed programs. The syntax of programming language constructs can be described by CFG. Conditional statement defined by a rule such as ; If S1 and S2 are statements and E is an expression, then If E then S1 else S2 is a statement. 14. Mention the properties of parse tree. The root is labeled by the start symbol. Each leaf is labeled by a token or by. Each interior node is labeled by a non terminal.if A is the Non terminal, labeling some interior node and x1, x2, x3.xn are the labels of the children

15. When a grammar is said to be ambiguous? When a grammar produces more than one parse tree for a same sentence then the grammar is said to be ambiguous. 16. What do you mean by a syntax tree? Syntax tree is a variant of a parse tree in which each leaf represents an operand and each interior node represents an operator. 17. Compare production with reduction. The rules that define the ways in which the syntactic categories can be built are productions whereas the replacement of the string by an non-terminal according to a grammar production is called reduction. 18. What are the functions of parser? i. Representation of the tokens by codes (integers) ii. Grouping of tokens together into syntactic structure 19. Define handle pruning. A technique to obtain the rightmost derivation in reverse (called canonical reduction sequence) is known as handle pruning (i.e.) starting with a string of terminals w to be parsed. If w is the sentence of the grammar then = n where n is the nth right sentential form of unknown right most derivation. 20. List various types of grammars. i. Phase sensitive grammar ii. Context sensitive grammar iii. Context-free grammar iv. Regular grammar 21. What are the demerits of SLR? It will not produce uniquely defined parsing action tables for all grammars. Shift-Reduce conflict. 22. Why LR parsing is good and attractive? LR parsers can be constructed for all programming language constructs for which CFG can be written. LR parsing is Non-backtracking Shift-Reduce parsing. Grammars parsed using LR parsers are super set of the class of grammar. LR parser can detect syntactic error as soon as possible, when left-to-right scan of the input. 23. How will you change the given grammar to an augmented grammar? If G is a grammar with start symbol S then G is the augmented grammar for G, such that G is G with a new start symbol S and with production S S.

24. Find the item I0 for the following grammar using CLR parsing method. G: S AS S b A SA A a I0: S. S, $ S.AS, $ S.b, $ A.SA, a b A.a, a b S.AS, a b S.b, a b 25. Specify the advantages of LALR. Merging of states with common cores can never produce a shift/reduce conflict that was not present in any one of the original states. Because shift actions depends only one core, not the look ahead. 43. Mention the demerits of LALR parser. Merger will produce reduce / reduce conflict. On erroneous input, LALR parser may proceed to do some reductions after the LR parser has declared an error, but LALR parser never shift a symbol after the LR parser declares an error. 44. What is the syntax for YACC source specification program? Declarations %% Translation rules %% Supporting C-routines 45. How YACC resolves parsing action conflicts? A reduce/reduce conflict is resolved by choosing the conflicting production listed first in the YACC specification. A shift/reduce conflict is resolved by shifting action or introduce associativity and precedence. 46. What is the new production added to the YACC on error recovery When parser generated by YACC encounters errors, then YACC pops symbol from its stack until it finds the topmost state on its stack whose underlying set of items includes an item of the form A. error 47. Define LR parser?

LR parsers can be used to parse a large class of context free grammars. The technique is called LR (K) parsing. L denotes that input sequence is processed from left to right R denotes that the right most derivation is performed K denotes that atmost K symbols of the sequence are used to make a decision. 48. What are the drawbacks of LR parser? a) Parsing tables are too complicated to be generated by hand, need an automated parser generator. b) Cannot handle ambiguous grammar without special tricks. 49. Define Operator grammar. A grammar with no production right side is ε or no two adjacent Non Terminalsis called Operator grammar. 50. Define operator precedence grammar. Operator precedence grammar is an operator grammar having disjoint precedence relations between any pair of Terminals. 51.What are the different precedence relations in operator precedence parser? 52. What do you mean by precedence function? The precedence table can be encoded by two precedence functions f and g, that map the terminal symbols to integers. 16Marks 1. Construct predictive parsing table for the grammar S->(L) a L->L,S S Solution:

2. What are the different strategies that a parser can employ to recover from syntax errors? Panic mode recovery On discovering an error, the parser discards input symbols one at a time until one of a designated set of synchronizing tokens is found. Phrase level recovery On discovering an error, the parser may perform local correction on the remaining input; e.g. replace prefix of the remaining input by some string that allow the parser to continue Error productions Augment the grammar for the language with productions that generate the erroneous constructs. If it is being used by the parser, generate appropriate error diagnostics to indicate the erroneous construct that has been recognized in the input Global correction It does minimal changes in the incorrect input string to obtain a globally least-cost correction. 3. Construct the CLR parsing table from

4. Write Operator-precedence parsing algorithm.

5. Find the SLR parsing table for the given grammar and parse the sentence (a+b)*c. E->E+E E*E (E) id.

6. Given the following grammar S->AS b, A->SA a. Construct a SLR parsing table for the string baab.

7. Explain the role of parser in detail Parser obtains a string of tokens from the lexical analyzer and verifies that the string can be generated by the grammar for the source language. It can report any syntax error in an intelligible fashion. Errors can be of lexical, syntactic, semantic or logical. The error handler in a parser has simple-to-state goals: should report the presence of errors clearly and accurately should recover from each error quickly enough to be able to detect subsequent errors should not significantly slow down the processing of correct programs 8. Give the LALR parsing table for the grammar S-> L=R R L->*R id R->L.

1. What are the reasons for using LR parser technique? LR parsers can be constructed to recognize virtually all programming language constructs for which CFGs can be written LR parsing method is the most general non backtracking shift reduce parsing method known, yet it can be implemented as efficiently as other shift-reduce methods The class of grammars that can be parsed using LR methods is a proper superset of the class of grammars that can be parsed with predictive parsers

An LR parser can detect a syntactic error as soon as it is possible to do so on a left-to-right scan of the input 10. What is an operator grammar? Draw the precedence graph for the following table:

11. Write a note on error recovery in predictive parsing. An error is detected during predictive parsing, when the terminal on the top of the stack does not match the next input symbol or when non terminal A is on the top of the stack, a is the next input symbol, and the parsing table entry M [A, a] is empty. Panic mode error recovery is based on the idea of skipping symbols on the input until a token in a selected set of synchronizing tokens appears. Heuristics for choosing synchronizing token set: Place all the symbols in Follow(A) into synchronizing set for A Add to the synchronizing set of a lower construct the symbol that begin higher constructs Place all the symbols in First(A) into synchronizing set for A If a non terminal can generate the empty string, then the production deriving  can be used as default. If the terminal on top of stack does not match, just pop the terminal and issue a message saying that the terminal was inserted and continue parsing. Phrase-level recovery is implemented by filling in the blank entries in the predictive parsing table with pointers to error routines. These routines may insert, change or delete symbols on the input and issue appropriate error messages. 12. Write the LR parsing algorithm. Check whether the grammar is SLR (1) or not. Justify the answer with reasons. S->L=R R; L->*R id; R->L