Ambiguity. Lecture 8. CS 536 Spring


 Claud Heath
 3 years ago
 Views:
Transcription
1 Ambiguity Lecture 8 CS 536 Spring
2 Announcement Reading Assignment ContextFree Grammars (Sections 4.1, 4.2) Programming Assignment 2 due Friday! Homework 1 due in a week (Wed Feb 21) not Feb 25! CS 536 Spring
3 Ambiguity = program structure not defined + () id String id * id + id has two parse trees: + * * id id + id id id id CS 536 Spring
4 Ambiguity A grammar is ambiguous if, for any string it has more than one parse tree, or there is more than one rightmost derivation, or there is more than one leftmost derivation. (the three conditions are equivalent) Ambiguity is BAD Leaves meaning of some programs illdefined CS 536 Spring
5 Dealing with Ambiguity There are several ways to handle ambiguity We ll discuss two of them: rewriting the grammar parsergenerator declarations CS 536 Spring
6 Outline Rewriting: xpression Grammars precedence associativity IFTHNLS the DanglingLS problem Declarations xpression Grammars precedence associativity CS 536 Spring
7 xpression Grammars (precedence) Rewrite the grammar use a different nonterminal for each precedence level start with the lowest precedence (MINUS)  / ( ) id rewrite to  T T T / T F F id ( ) CS 536 Spring
8 xample parse tree for id id / id  T T T / T F F id ( ) T  T F T F / T F id id id CS 536 Spring
9 TST YOURSLF #1 Attempt to construct a parse tree for idid/id that shows the wrong precedence. Question: Why do you fail to construct this parse tree? CS 536 Spring
10 Associativity The grammar captures operator precedence, but it is still ambiguous! fails to express that both subtraction and division are left associative; e.g., is equivalent to: ((53)2) and not to: (5(32)). TST YOURSLF #3 Draw two parse trees for the expression using the grammar given above; one that correctly groups 53, and one that incorrectly groups 32. CS 536 Spring
11 Recursion A grammar is recursive in nonterminal X if: X + X recall that + means in one or more steps, X derives a sequence of symbols that includes an X A grammar is left recursive in X if: X + X in one or more steps, X derives a sequence of symbols that starts with an X A grammar is right recursive in X if: X + X in one or more steps, X derives a sequence of symbols that ends with an X CS 536 Spring
12 How to fix associativity The grammar given above is both left and right recursive in nonterminals exp and term try at home: write the derivation steps that show this. To correctly expresses operator associativity: For left associativity, use left recursion. For right associativity, use right recursion. Here's the correct grammar: T T T T / F F F id ( ) CS 536 Spring
13 Ambiguity: The Dangling lse Consider the grammar if then if then else pr This grammar is also ambiguous CS 536 Spring
14 The Dangling lse: xample The expression if 1 then if 2 then 3 else 4 has two parse trees if if 1 if 4 1 if Typically we want the second form CS 536 Spring
15 The Dangling lse: A Fix else matches the closest unmatched then We can describe this in the grammar MIF /* all then are matched */ UIF /* some then are unmatched */ MIF if then MIF else MIF pr UIF if then if then MIF else UIF Describes the same set of strings CS 536 Spring
16 The Dangling lse: xample Revisited The expression if 1 then if 2 then 3 else 4 if if 1 if 1 if A valid parse tree (for a UIF) Not valid because the then expression is not a MIF CS 536 Spring
17 Precedence and Associativity Declarations Instead of rewriting the grammar Use the more natural (ambiguous) grammar Along with disambiguating declarations Most parser generators allow precedence and associativity declarations to disambiguate grammars xamples CS 536 Spring
18 Associativity Declarations Consider the grammar  Ambiguous: two parse trees of Left associativity declaration: %left + CS 536 Spring
19 Precedence Declarations Consider the grammar + * And the string + * * + + * Precedence declarations: %left + %left * CS 536 Spring
Grammars and ambiguity. CS164 3:305:00 TT 10 Evans. Prof. Bodik CS 164 Lecture 8 1
Grammars and ambiguity CS164 3:305:00 TT 10 vans 1 Overview derivations and parse trees different derivations produce may produce same parse tree ambiguous grammars what they are and how to fix them 2
More informationParsing: Derivations, Ambiguity, Precedence, Associativity. Lecture 8. Professor Alex Aiken Lecture #5 (Modified by Professor Vijay Ganesh)
Parsing: Derivations, Ambiguity, Precedence, Associativity Lecture 8 (Modified by Professor Vijay Ganesh) 1 Topics covered so far Regular languages and Finite automaton Parser overview Contextfree grammars
More informationE E+E E E (E) id. id + id E E+E. id E + E id id + E id id + id. Overview. derivations and parse trees. Grammars and ambiguity. ambiguous grammars
Overview Grammars and ambiguity CS164 3:305:00 TT 10 vans derivations and parse trees dferent derivations produce may produce same parse tree ambiguous grammars what they are and how to fix them 1 2 Recall:
More information( ) i 0. Outline. Regular languages revisited. Introduction to Parsing. Parser overview. Contextfree grammars (CFG s) Lecture 5.
Outline Regular languages revisited Introduction to Parsing Lecture 5 Parser overview Contextfree grammars (CFG s) Derivations Prof. Aiken CS 143 Lecture 5 1 Ambiguity Prof. Aiken CS 143 Lecture 5 2 Languages
More informationOutline. Regular languages revisited. Introduction to Parsing. Parser overview. Contextfree grammars (CFG s) Lecture 5. Derivations.
Outline Regular languages revisited Introduction to Parsing Lecture 5 Parser overview Contextfree grammars (CFG s) Derivations Prof. Aiken CS 143 Lecture 5 1 Ambiguity Prof. Aiken CS 143 Lecture 5 2 Languages
More informationIntroduction to Parsing. Lecture 5. Professor Alex Aiken Lecture #5 (Modified by Professor Vijay Ganesh)
Introduction to Parsing Lecture 5 (Modified by Professor Vijay Ganesh) 1 Outline Regular languages revisited Parser overview Contextfree grammars (CFG s) Derivations Ambiguity 2 Languages and Automata
More informationIntroduction to Parsing. Lecture 5
Introduction to Parsing Lecture 5 1 Outline Regular languages revisited Parser overview Contextfree grammars (CFG s) Derivations Ambiguity 2 Languages and Automata Formal languages are very important
More informationIntroduction to Parsing. Lecture 5
Introduction to Parsing Lecture 5 1 Outline Regular languages revisited Parser overview Contextfree grammars (CFG s) Derivations Ambiguity 2 Languages and Automata Formal languages are very important
More informationIntroduction to Parsing Ambiguity and Syntax Errors
Introduction to Parsing Ambiguity and Syntax rrors Outline Regular languages revisited Parser overview Contextfree grammars (CFG s) Derivations Ambiguity Syntax errors Compiler Design 1 (2011) 2 Languages
More informationIntroduction to Parsing Ambiguity and Syntax Errors
Introduction to Parsing Ambiguity and Syntax rrors Outline Regular languages revisited Parser overview Contextfree grammars (CFG s) Derivations Ambiguity Syntax errors 2 Languages and Automata Formal
More informationAmbiguity, Precedence, Associativity & TopDown Parsing. Lecture 910
Ambiguity, Precedence, Associativity & TopDown Parsing Lecture 910 (From slides by G. Necula & R. Bodik) 9/18/06 Prof. Hilfinger CS164 Lecture 9 1 Administrivia Please let me know if there are continued
More informationContextFree Grammars
CFG2: Ambiguity ContextFree Grammars CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilersclass Ambiguity  /  / ( )  / /  160622 2 Ambiguity Grammar is ambiguous if more
More informationContextFree Grammars
ContextFree Grammars Lecture 7 http://webwitch.dreamhost.com/grammar.girl/ Outline Scanner vs. parser Why regular expressions are not enough Grammars (contextfree grammars) grammar rules derivations
More informationAmbiguity. Grammar E E + E E * E ( E ) int. The string int * int + int has two parse trees. * int
Administrivia Ambiguity, Precedence, Associativity & opdown Parsing eam assignments this evening for all those not listed as having one. HW#3 is now available, due next uesday morning (Monday is a holiday).
More informationIntro To Parsing. Step By Step
#1 Intro To Parsing Step By Step #2 SelfTest from Last Time Are practical parsers and scanners based on deterministic or nondeterministic automata? How can regular expressions be used to specify nested
More informationAmbiguity and Errors SyntaxDirected Translation
Outline Ambiguity (revisited) Ambiguity and rrors SyntaxDirected Translation xtensions of CFG for parsing Precedence declarations rror handling Semantic actions Constructing a parse tree CS780(Prasad)
More informationOutline. Parser overview Contextfree grammars (CFG s) Derivations SyntaxDirected Translation
Outline Introduction to Parsing (adapted from CS 164 at Berkeley) Parser overview Contextfree grammars (CFG s) Derivations SyntaxDirected ranslation he Functionality of the Parser Input: sequence of
More informationFormal Languages and Compilers Lecture V: Parse Trees and Ambiguous Gr
Formal Languages and Compilers Lecture V: Parse Trees and Ambiguous Grammars Free University of BozenBolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/
More informationParsing Part II. (Ambiguity, Topdown parsing, Leftrecursion Removal)
Parsing Part II (Ambiguity, Topdown parsing, Leftrecursion Removal) Ambiguous Grammars Definitions If a grammar has more than one leftmost derivation for a single sentential form, the grammar is ambiguous
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 5: Syntax Analysis (Parsing) Zheng (Eddy) Zhang Rutgers University January 31, 2018 Class Information Homework 1 is being graded now. The sample solution
More informationCompilers Course Lecture 4: Context Free Grammars
Compilers Course Lecture 4: Context Free Grammars Example: attempt to define simple arithmetic expressions using named regular expressions: num = [09]+ sum = expr "+" expr expr = "(" sum ")" num Appears
More informationIntroduction to Parsing. Lecture 8
Introduction to Parsing Lecture 8 Adapted from slides by G. Necula Outline Limitations of regular languages Parser overview Contextfree grammars (CFG s) Derivations Languages and Automata Formal languages
More informationDefining syntax using CFGs
Defining syntax using CFGs Roadmap Last time Defined contextfree grammar This time CFGs for specifying a language s syntax Language membership List grammars Resolving ambiguity CFG Review G = (N,Σ,P,S)
More informationOutline. Limitations of regular languages. Introduction to Parsing. Parser overview. Contextfree grammars (CFG s)
Outline Limitations of regular languages Introduction to Parsing Parser overview Lecture 8 Adapted from slides by G. Necula Contextfree grammars (CFG s) Derivations Languages and Automata Formal languages
More information3. Contextfree grammars & parsing
3. Contextfree grammars & parsing The parsing process sequences of tokens parse tree or syntax tree a / [ / index / ]/= / 4 / + / 2 The parsing process sequences of tokens parse tree or syntax tree a
More informationCOMPILER (CSE 4120) (Lecture 6: Parsing 4 Bottomup Parsing )
COMPILR (CS 4120) (Lecture 6: Parsing 4 Bottomup Parsing ) Sungwon Jung Mobile Computing & Data ngineering Lab Dept. of Computer Science and ngineering Sogang University Seoul, Korea Tel: +8227058930
More informationPrinciples of Programming Languages COMP251: Syntax and Grammars
Principles of Programming Languages COMP251: Syntax and Grammars Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong, China Fall 2006
More information([19] 1[02]):[05][09](AM PM)? What does the above match? Matches clock time, may or may not be told if it is AM or PM.
What is the corresponding regex? [29]: ([19] 1[02]):[05][09](AM PM)? What does the above match? Matches clock time, may or may not be told if it is AM or PM. CS 230  Spring 2018 41 More CFG Notation
More informationMIDTERM EXAMINATION  CS130  Spring 2003
MIDTERM EXAMINATION  CS130  Spring 2003 Your full name: Your UCSD ID number: This exam is closed book and closed notes Total number of points in this exam: 120 + 10 extra credit This exam counts for
More informationLecture 8: Deterministic BottomUp Parsing
Lecture 8: Deterministic BottomUp Parsing (From slides by G. Necula & R. Bodik) Last modified: Fri Feb 12 13:02:57 2010 CS164: Lecture #8 1 Avoiding nondeterministic choice: LR We ve been looking at general
More informationConflicts in LR Parsing and More LR Parsing Types
Conflicts in LR Parsing and More LR Parsing Types Lecture 10 Dr. Sean Peisert ECS 142 Spring 2009 1 Status Project 2 Due Friday, Apr. 24, 11:55pm The usual lecture time is being replaced by a discussion
More informationParsing II Topdown parsing. Comp 412
COMP 412 FALL 2018 Parsing II Topdown parsing Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled
More informationDefining syntax using CFGs
Defining syntax using CFGs Roadmap Last 8me Defined contextfree grammar This 8me CFGs for syntax design Language membership List grammars Resolving ambiguity CFG Review G = (N,Σ,P,S) means derives derives
More informationEng. Maha Talaat Page 1
ElShorouk cademy cad. Year : 2013 / 2014 Higher Institute for Computer & Term : 2nd Information Technology Year : 4th Computer Science Department Supervisor: Prof. Dr. hmed bbassy Section contents: mbiguity
More informationBottomUp Parsing. Lecture 1112
BottomUp Parsing Lecture 1112 (From slides by G. Necula & R. Bodik) 2/20/08 Prof. Hilfinger CS164 Lecture 11 1 Administrivia Test I during class on 10 March. 2/20/08 Prof. Hilfinger CS164 Lecture 11
More informationCS153: Compilers Lecture 4: Recursive Parsing
CS153: Compilers Lecture 4: Recursive Parsing Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Proj 1 out Due Thursday Sept 20 11:59 Start soon if you haven t! Proj 2 released today
More informationSyntax Analysis Check syntax and construct abstract syntax tree
Syntax Analysis Check syntax and construct abstract syntax tree if == = ; b 0 a b Error reporting and recovery Model using context free grammars Recognize using Push down automata/table Driven Parsers
More informationEDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised:
EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing Görel Hedin Revised: 20170904 This lecture Regular expressions Contextfree grammar Attribute grammar
More informationΕΠΛ323  Θεωρία και Πρακτική Μεταγλωττιστών
ΕΠΛ323  Θεωρία και Πρακτική Μεταγλωττιστών Lecture 5a Syntax Analysis lias Athanasopoulos eliasathan@cs.ucy.ac.cy Syntax Analysis Συντακτική Ανάλυση Contextfree Grammars (CFGs) Derivations Parse trees
More informationLecture 7: Deterministic BottomUp Parsing
Lecture 7: Deterministic BottomUp Parsing (From slides by G. Necula & R. Bodik) Last modified: Tue Sep 20 12:50:42 2011 CS164: Lecture #7 1 Avoiding nondeterministic choice: LR We ve been looking at general
More informationRecursive Descent Parsers
Recursive Descent Parsers Lecture 7 Robb T. Koether HampdenSydney College Wed, Jan 28, 2015 Robb T. Koether (HampdenSydney College) Recursive Descent Parsers Wed, Jan 28, 2015 1 / 18 1 Parsing 2 LL Parsers
More informationADTS, GRAMMARS, PARSING, TREE TRAVERSALS
1 Prelim 1 2 Where: Kennedy Auditorium When: ALib: 5:307 LieZ: 7:309 (unless we explicitly notified you otherwise) ADS, GRAMMARS, PARSING, R RAVRSALS Lecture 13 CS2110 Spring 2016 Pointers to material
More informationBottomUp Parsing. Lecture 1112
BottomUp Parsing Lecture 1112 (From slides by G. Necula & R. Bodik) 9/22/06 Prof. Hilfinger CS164 Lecture 11 1 BottomUp Parsing Bottomup parsing is more general than topdown parsing And just as efficient
More informationIntroduction to BottomUp Parsing
Introduction to BottomUp Parsing Lecture 11 CS 536 Spring 2001 1 Outline he strategy: shiftreduce parsing Ambiguity and precedence declarations Next lecture: bottomup parsing algorithms CS 536 Spring
More informationLecture 14: Parser Conflicts, Using Ambiguity, Error Recovery. Last modified: Mon Feb 23 10:05: CS164: Lecture #14 1
Lecture 14: Parser Conflicts, Using Ambiguity, Error Recovery Last modified: Mon Feb 23 10:05:56 2015 CS164: Lecture #14 1 Shift/Reduce Conflicts If a DFA state contains both [X: α aβ, b] and [Y: γ, a],
More informationCSE431 Translation of Computer Languages
CSE431 Translation of Computer Languages Top Down Parsers Doug Shook Top Down Parsers Two forms: Recursive Descent Table Also known as LL(k) parsers: Read tokens from Left to right Produces a Leftmost
More informationMidterm I (Solutions) CS164, Spring 2002
Midterm I (Solutions) CS164, Spring 2002 February 28, 2002 Please read all instructions (including these) carefully. There are 9 pages in this exam and 5 questions, each with multiple parts. Some questions
More informationEECS 6083 Intro to Parsing Context Free Grammars
EECS 6083 Intro to Parsing Context Free Grammars Based on slides from text web site: Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. 1 Parsing sequence of tokens parser
More informationADTS, GRAMMARS, PARSING, TREE TRAVERSALS
1 Pointers to material ADS, GRAMMARS, PARSING, R RAVRSALS Lecture 13 CS110 all 016 Parse trees: text, section 3.36 Definition of Java Language, sometimes useful: docs.oracle.com/javase/specs/jls/se8/html/index.html
More informationProgramming Languages & Translators PARSING. Baishakhi Ray. Fall These slides are motivated from Prof. Alex Aiken: Compilers (Stanford)
Programming Languages & Translators PARSING Baishakhi Ray Fall 2018 These slides are motivated from Prof. Alex Aiken: Compilers (Stanford) Languages and Automata Formal languages are very important in
More informationCPS 506 Comparative Programming Languages. Syntax Specification
CPS 506 Comparative Programming Languages Syntax Specification Compiling Process Steps Program Lexical Analysis Convert characters into a stream of tokens Lexical Analysis Syntactic Analysis Send tokens
More informationBuilding a Parser II. CS164 3:305:00 TT 10 Evans. Prof. Bodik CS 164 Lecture 6 1
Building a Parser II CS164 3:305:00 TT 10 Evans 1 Grammars Programming language constructs have recursive structure. which is why our handwritten parser had this structure, too An expression is either:
More informationafewadminnotes CSC324 Formal Language Theory Dealing with Ambiguity: Precedence Example Office Hours: (in BA 4237) Monday 3 4pm Wednesdays 1 2pm
afewadminnotes CSC324 Formal Language Theory Afsaneh Fazly 1 Office Hours: (in BA 4237) Monday 3 4pm Wednesdays 1 2pm January 16, 2013 There will be a lecture Friday January 18, 2013 @2pm. 1 Thanks to
More informationCSE 3302 Programming Languages Lecture 2: Syntax
CSE 3302 Programming Languages Lecture 2: Syntax (based on slides by Chengkai Li) Leonidas Fegaras University of Texas at Arlington CSE 3302 L2 Spring 2011 1 How do we define a PL? Specifying a PL: Syntax:
More informationAdministrativia. WA1 due on Thu PA2 in a week. Building a Parser III. Slides on the web site. CS164 3:305:00 TT 10 Evans.
Administrativia Building a Parser III CS164 3:305:00 10 vans WA1 due on hu PA2 in a week Slides on the web site I do my best to have slides ready and posted by the end of the preceding logical day yesterday,
More informationAnnouncements. Written Assignment 1 out, due Friday, July 6th at 5PM.
Syntax Analysis Announcements Written Assignment 1 out, due Friday, July 6th at 5PM. xplore the theoretical aspects of scanning. See the limits of maximalmunch scanning. Class mailing list: There is an
More informationCompiler Design Concepts. Syntax Analysis
Compiler Design Concepts Syntax Analysis Introduction First task is to break up the text into meaningful words called tokens. newval=oldval+12 id = id + num Token Stream Lexical Analysis Source Code (High
More informationAdministrativia. PA2 assigned today. WA1 assigned today. Building a Parser II. CS164 3:305:00 TT 10 Evans. First midterm. Grammars.
Administrativia Building a Parser II CS164 3:305:00 TT 10 Evans PA2 assigned today due in 12 days WA1 assigned today due in a week it s a practice for the exam First midterm Oct 5 will contain some projectinspired
More informationChapter 3: CONTEXTFREE GRAMMARS AND PARSING Part2 3.3 Parse Trees and Abstract Syntax Trees
Chapter 3: CONTEXTFREE GRAMMARS AND PARSING Part2 3.3 Parse Trees and Abstract Syntax Trees 3.3.1 Parse trees 1. Derivation V.S. Structure Derivations do not uniquely represent the structure of the strings
More informationCS 536 Midterm Exam Spring 2013
CS 536 Midterm Exam Spring 2013 ID: Exam Instructions: Write your student ID (not your name) in the space provided at the top of each page of the exam. Write all your answers on the exam itself. Feel free
More informationOutline. Limitations of regular languages Parser overview Contextfree grammars (CFG s) Derivations SyntaxDirected Translation
Outline Introduction to Parsing Lecture 8 Adapted from slides by G. Necula and R. Bodik Limitations of regular languages Parser overview Contextfree grammars (CG s) Derivations SyntaxDirected ranslation
More informationADTS, GRAMMARS, PARSING, TREE TRAVERSALS
3//15 1 AD: Abstract Data ype 2 Just like a type: Bunch of values together with operations on them. Used often in discussing data structures Important: he definition says ntthing about the implementation,
More informationCS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Syntax Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Limits of Regular Languages Advantages of Regular Expressions
More informationSyntax/semantics. Program <> program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing
Syntax/semantics Program program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing Metamodels 8/27/10 1 Program program execution Syntax Semantics
More informationCompilation 2013 Parser Generators, Conflict Management, and MLYacc
Compilation 2013 Parser Generators, Conflict Management, and MLYacc Erik Ernst Aarhus University Parser generators, MLYacc LR parsers are tedious to write, but can be generated, e.g., by MLYacc Input:
More informationUniversity of Technology Department of Computer Sciences. Final Examination st Term. Subject:Compilers Design
Subject:Compilers Design Division: All Branches Examiner:Dr. Abeer Tariq University of Technology Department of Computer Sciences 2102 Final Examination 20112012 1 st Term Year:Third Time: 3 Hours Date:
More informationBuilding a Parser III. CS164 3:305:00 TT 10 Evans. Prof. Bodik CS 164 Lecture 6 1
Building a Parser III CS164 3:305:00 TT 10 Evans 1 Overview Finish recursive descent parser when it breaks down and how to fix it eliminating left recursion reordering productions Predictive parsers (aka
More informationIntroduction to Parsing
Introduction to Parsing The Front End Source code Scanner tokens Parser IR Errors Parser Checks the stream of words and their parts of speech (produced by the scanner) for grammatical correctness Determines
More informationIn One Slide. Outline. LR Parsing. Table Construction
LR Parsing Table Construction #1 In One Slide An LR(1) parsing table can be constructed automatically from a CFG. An LR(1) item is a pair made up of a production and a lookahead token; it represents a
More informationsyntax tree  * * *  * * * * * 2 1 * * 2 * (2 * 1)  (1 + 0)
0//7 xpression rees rom last time: we can draw a syntax tree for the Java expression ( 0). 0 ASS, GRAMMARS, PARSING, R RAVRSALS Lecture 3 CS0 all 07 Preorder, Postorder, and Inorder Preorder, Postorder,
More informationParsing #1. Leonidas Fegaras. CSE 5317/4305 L3: Parsing #1 1
Parsing #1 Leonidas Fegaras CSE 5317/4305 L3: Parsing #1 1 Parser source file get next character scanner get token parser AST token A parser recognizes sequences of tokens according to some grammar and
More informationLR Parsing  Conflicts
LR Parsing  Conflicts Lecture 15 Sections 4.5, 4.6 Robb T. Koether HampdenSydney College Fri, Feb 20, 2015 Robb T. Koether (HampdenSydney College) LR Parsing  Conflicts Fri, Feb 20, 2015 1 / 15 1 Shift/Reduce
More informationQuestion Points Score
CS 453 Introduction to Compilers Midterm Examination Spring 2009 March 12, 2009 75 minutes (maximum) Closed Book You may use one side of one sheet (8.5x11) of paper with any notes you like. This exam has
More informationADTS, GRAMMARS, PARSING, TREE TRAVERSALS. Regrades 10/6/15. Prelim 1. Prelim 1. Expression trees. Pointers to material
1 Prelim 1 2 Max: 99 Mean: 71.2 Median: 73 Std Dev: 1.6 ADS, GRAMMARS, PARSING, R RAVRSALS Lecture 12 CS2110 Spring 2015 3 Prelim 1 Score Grade % 9099 A 8289 A/A 26% 7082 B/B 6269 B/B 50% 5059 C/C
More informationCSE 401 Midterm Exam Sample Solution 2/11/15
Question 1. (10 points) Regular expression warmup. For regular expression questions, you must restrict yourself to the basic regular expression operations covered in class and on homework assignments:
More informationDerivations vs Parses. Example. Parse Tree. Ambiguity. Different Parse Trees. Context Free Grammars 9/18/2012
Derivations vs Parses Grammar is used to derive string or construct parser Context ree Grammars A derivation is a sequence of applications of rules Starting from the start symbol S......... (sentence)
More informationIf you are going to form a group for A2, please do it before tomorrow (Friday) noon GRAMMARS & PARSING. Lecture 8 CS2110 Spring 2014
1 If you are going to form a group for A2, please do it before tomorrow (Friday) noon GRAMMARS & PARSING Lecture 8 CS2110 Spring 2014 Pointers. DO visit the java spec website 2 Parse trees: Text page 592
More informationLR Parsing LALR Parser Generators
Outline LR Parsing LALR Parser Generators Review of bottomup parsing Computing the parsing DFA Using parser generators 2 Bottomup Parsing (Review) A bottomup parser rewrites the input string to the
More informationSometimes an ambiguous grammar can be rewritten to eliminate the ambiguity.
Eliminating Ambiguity Sometimes an ambiguous grammar can be rewritten to eliminate the ambiguity. Example: consider the following grammar stat if expr then stat if expr then stat else stat other One can
More information1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.
Code No: R05320502 Set No. 1 1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail. 2. Construct predictive parsing
More informationGrammars & Parsing. Lecture 12 CS 2112 Fall 2018
Grammars & Parsing Lecture 12 CS 2112 Fall 2018 Motivation The cat ate the rat. The cat ate the rat slowly. The small cat ate the big rat slowly. The small cat ate the big rat on the mat slowly. The small
More informationLR Parsing  The Items
LR Parsing  The Items Lecture 10 Sections 4.5, 4.7 Robb T. Koether HampdenSydney College Fri, Feb 13, 2015 Robb T. Koether (HampdenSydney College) LR Parsing  The Items Fri, Feb 13, 2015 1 / 31 1 LR
More informationLECTURE 3. Compiler Phases
LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent
More informationCS 44 Exam #2 February 14, 2001
CS 44 Exam #2 February 14, 2001 Name Time Started: Time Finished: Each question is equally weighted. You may omit two questions, but you must answer #8, and you can only omit one of #6 or #7. Circle the
More informationLL(k) Parsing. Predictive Parsers. LL(k) Parser Structure. Sample Parse Table. LL(1) Parsing Algorithm. Push RHS in Reverse Order 10/17/2012
Predictive Parsers LL(k) Parsing Can we avoid backtracking? es, if for a given input symbol and given nonterminal, we can choose the alternative appropriately. his is possible if the first terminal of
More informationCompilers  Chapter 2: An introduction to syntax analysis (and a complete toy compiler)
Compilers  Chapter 2: An introduction to syntax analysis (and a complete toy compiler) Lecturers: Paul Kelly (phjk@doc.ic.ac.uk) Office: room 304, William Penney Building Naranker Dulay (nd@doc.ic.ac.uk)
More informationCOMP421 Compiler Design. Presented by Dr Ioanna Dionysiou
COMP421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]
More informationPart 5 Program Analysis Principles and Techniques
1 Part 5 Program Analysis Principles and Techniques Front end 2 source code scanner tokens parser il errors Responsibilities: Recognize legal programs Report errors Produce il Preliminary storage map Shape
More informationOutline. The strategy: shiftreduce parsing. Introduction to BottomUp Parsing. A key concept: handles
Outline Introduction to BottomUp Parsing Lecture Notes by Profs. Alex Aiken and George Necula (UCB) he strategy: reduce parsing A key concept: handles Ambiguity and precedence declarations CS780(Prasad)
More informationReview main idea syntaxdirected evaluation and translation. Recall syntaxdirected interpretation in recursive descent parsers
Plan for Today Review main idea syntaxdirected evaluation and translation Recall syntaxdirected interpretation in recursive descent parsers Syntaxdirected evaluation and translation in shiftreduce
More informationPrinciples of Programming Languages COMP251: Syntax and Grammars
Principles of Programming Languages COMP251: Syntax and Grammars Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong, China Fall 2007
More informationCS 406/534 Compiler Construction Parsing Part I
CS 406/534 Compiler Construction Parsing Part I Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof. Ken Kennedy and Dr.
More informationCMSC 330: Organization of Programming Languages. ContextFree Grammars Ambiguity
CMSC 330: Organization of Programming Languages ContextFree Grammars Ambiguity Review Why should we study CFGs? What are the four parts of a CFG? How do we tell if a string is accepted by a CFG? What
More informationChapter 4: Syntax Analyzer
Chapter 4: Syntax Analyzer Chapter 4: Syntax Analysis 1 The role of the Parser The parser obtains a string of tokens from the lexical analyzer, and verifies that the string can be generated by the grammar
More informationCSE P 501 Compilers. Parsing & ContextFree Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C1
CSE P 501 Compilers Parsing & ContextFree Grammars Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 C1 Administrivia Project partner signup: please find a partner and fill out the signup form by noon
More informationEDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:
EDAN65: Compilers, Lecture 06 A LR parsing Görel Hedin Revised: 20170911 This lecture Regular expressions Contextfree grammar Attribute grammar Lexical analyzer (scanner) Syntactic analyzer (parser)
More informationParsing. Roadmap. > Contextfree grammars > Derivations and precedence > Topdown parsing > Leftrecursion > Lookahead > Tabledriven parsing
Roadmap > Contextfree grammars > Derivations and precedence > Topdown parsing > Leftrecursion > Lookahead > Tabledriven parsing The role of the parser > performs contextfree syntax analysis > guides
More informationDr. D.M. Akbar Hussain
Syntax Analysis Parsing Syntax Or Structure Given By Determines Grammar Rules Context Free Grammar 1 Context Free Grammars (CFG) Provides the syntactic structure: A grammar is quadruple (V T, V N, S, R)
More informationParsing. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.
Parsing Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice. Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students
More information3. Parsing. Oscar Nierstrasz
3. Parsing Oscar Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes. http://www.cs.ucla.edu/~palsberg/ http://www.cs.purdue.edu/homes/hosking/
More information