# CSE 582 Autumn 2002 Exam 11/26/02

Size: px
Start display at page:

Transcription

1 Name There are 8 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following reference materials: Course lecture slides & notes Your primary compiler textbook (presumably Cooper & Torczon, Appel, or the dragon book) No other books or other materials. Please wait to turn the page until you are told to begin. Page 1 of 10

2 Score (Remainder of this page intentionally left blank. Questions start on the next page.) Page 2 of 10

3 Question 1. (10 points) Regular expressions. Describe the set of strings that are generated by the each of the following regular expressions. a) (a (bc)* d)+ b) ((0 1)* (2 3)+) 0011 Question 2. (10 points) Draw a deterministic finite automata (DFA) that recognizes strings generated by (a (bc)* d)+. You do not need to use the formal algorithms for converting regular expressions to a NFA then a DFA (although those algorithms might provide some insight into what s needed). Just draw a suitable diagram. Page 3 of 10

4 Question 3. (10 points) A new programming language is being designed that includes decimal numbers with no exponent. A decimal number has a period to separate the integer and fractional parts of the number and must have at least one digit both before and after the decimal point. Furthermore, a decimal number must not have any superfluous leading or trailing 0 s. Some examples of legal decimal numbers are 3.14, 0.01, 17.0, 0.0, Some examples of illegal decimal numbers are 00.0,.5, 17, 17., , (this last example is illegal because of the trailing 0 s; the 0 before the decimal point is required). Write a regular expression (or collection of regular expressions) to generate legal decimal numbers. Question 4. (10 points) Suppose we have the following fragment of a Java program (including some language operators that are not included in JFlat) while (xyzzy >= thing) // repeat until thing is big enough { x += y; thing++; } List in order the tokens that would be produced by a scanner when reading this input. (Use any reasonable set of token names; just be sure they are clear and descriptive.) Page 4 of 10

5 Question 5. (12 points) The standard programming language grammar for statements is ambiguous because of the dangling else problem. stmt ::= if ( expr ) stmt if ( expr ) stmt else stmt while ( expr ) stmt S Give an unambiguous grammar that defines all of the above statements and correctly handles the dangling else problem in the grammar. (Hint: introduce multiple productions for statements and divide the productions into two categories: those that might end in an if statement with no else clause a short if and those that definitely do not.) Page 5 of 10

6 Question 6. (20 points) Grammars and LR parsing. Consider the following grammar s ::= expr \$ expr ::= a a subs subs ::= [ expr ] [ expr ] subs (In the first production, \$ represents the end of file) a) (3 points) What are the terminals and non-terminals of this grammar? Terminals: Non-terminals: b) (3 points) Describe in English the set of strings generated by this grammar (continued next page) Page 6 of 10

7 Question 6. (Cont) LR parsing. CSE 582 Autumn 2002 Exam 11/26/02 (Grammar repeated for reference) s ::= expr \$ expr ::= a a subs subs ::= [ expr ] [ expr ] subs d) (12 points) Construct (draw) the LR(0) state machine for this grammar. You do not need to write out the parser GOTO and ACTION tables, or compute FIRST and FOLLOW sets. Just draw the state machine. Be sure to show the sets of items in each state. e) (2 points) Is this grammar LR(0)? Why or why not? Page 7 of 10

8 Question 7. (18 points) x86 hacking. Consider the following C main program and function definition: int avg(int a, int b) { int ans; if (a == b) { return a/2; } else { ans = (a + b) / 2; return ans; } } void main() { int x; x = avg(17,42); } (a) (5 points) Draw a picture showing the layouts of the stack frames for methods avg and main. This should show the stack layout immediately after the prologue code of each function is executed, just before execution of the first statement of the function body (i.e., after the stack frame has been allocated). Be sure to show where registers ebp and esp point, and the location and offsets from ebp of each parameter and local variable. Page 8 of 10

9 Question 7. (cont) CSE 582 Autumn 2002 Exam 11/26/02 (b) (13 points) Translate both functions avg and main into x86 assembly language. You do not need to slavishly imitate the code shapes described in class straightforward x86 code is fine as long as it is correct, uses the registers properly, and obeys the x86 C language conventions for stack frame layout, function calls, and so on. It will help us grade your answer if you include the source code as comments near the corresponding x86 instructions. The C code is repeated here to save some page flipping. int avg(int a, int b) { void main() { int ans; int x; if (a == b) { x = avg(17,42); return a/2; } } else { ans = (a + b) / 2; return ans; } } Page 9 of 10

10 Question 8. (10 points) Code Shape Several languages in the ALGOL family had a loop statement designed strictly for counting loops. The syntax for a specific example is: for var := expr1 to expr2 by expr3 do statement The semantics of the for statement are to repeatedly execute the statement that is the loop body with var taking on values starting at expr1, continuing while the value in var is less than or equal to expr2, and incrementing var by expr3 after each execution of the loop body. All three expressions (expr1, expr2, and expr3) are evaluated only once before the first iteration of the loop. If expr1 is initially greater than expr2 then the loop body is not executed. The final by expr3 clause is optional; if it is omitted, by 1 is assumed instead. Describe the code shape that could be used to implement this statement on the x86 processor, in the same style that we ve used to show code shapes for other programming language constructs. Include the instructions and labels needed to implement the loop and be sure it is clear where the compiled code for the various expressions and the loop body would appear. If you introduce any temporary variables, be sure it is clear where they are stored (where in registers and/or memory). Page 10 of 10

### CSE 582 Autumn 2002 Exam Sample Solution

Question 1. (10 points) Regular expressions. Describe the set of strings that are generated by the each of the following regular expressions. a) (a (bc)* d)+ One or more of the string a or the string d

### CSE P 501 Exam 8/5/04

Name There are 7 questions worth a total of 65 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following references: Course

### CSE P 501 Exam 11/17/05 Sample Solution

1. (8 points) Write a regular expression or set of regular expressions that generate the following sets of strings. You can use abbreviations (i.e., name = regular expression) if it helps to make your

### CSE P 501 Exam 12/1/11

Name There are 7 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following references:

### CSE 401 Final Exam. December 16, 2010

CSE 401 Final Exam December 16, 2010 Name You may have one sheet of handwritten notes plus the handwritten notes from the midterm. You may also use information about MiniJava, the compiler, and so forth

### CSE P 501 Exam 8/5/04 Sample Solution. 1. (10 points) Write a regular expression or regular expressions that generate the following sets of strings.

1. (10 points) Write a regular ression or regular ressions that generate the following sets of strings. (a) (5 points) All strings containing a s, b s, and c s with at least one a and at least one b. [abc]*a[abc]*b[abc]*

### CSE 401 Midterm Exam 11/5/10

Name There are 5 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed books, closed notes, closed

### CS 164 Handout 11. Midterm Examination. There are seven questions on the exam, each worth between 10 and 20 points.

Midterm Examination Please read all instructions (including these) carefully. Please print your name at the bottom of each page on the exam. There are seven questions on the exam, each worth between 10

### CSE P 501 Exam Sample Solution 12/1/11

Question 1. (10 points, 5 each) Regular expressions. Give regular expressions that generate the following sets of strings. You may only use the basic operations of concatenation, choice ( ), and repetition

### CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

Name ID # There are 7 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed books, closed notes,

### CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Winter /15/ Hal Perkins & UW CSE C-1

CSE P 501 Compilers Parsing & Context-Free Grammars Hal Perkins Winter 2008 1/15/2008 2002-08 Hal Perkins & UW CSE C-1 Agenda for Today Parsing overview Context free grammars Ambiguous grammars Reading:

### RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name

### CSE 413 Winter 2001 Final Exam Sample Solution

Question 1. (12 points, 4 each) Regular expressions. (a) Describe the set of strings generated by the regular expression ((xy*x) (yx*y))* In any order, 0 or more pairs of x s with 0 or more y s between

### CSE 413 Final Exam. June 7, 2011

CSE 413 Final Exam June 7, 2011 Name The exam is closed book, except that you may have a single page of hand-written notes for reference plus the page of notes you had for the midterm (although you are

### Parsing. source code. while (k<=n) {sum = sum+k; k=k+1;}

Compiler Construction Grammars Parsing source code scanner tokens regular expressions lexical analysis Lennart Andersson parser context free grammar Revision 2012 01 23 2012 parse tree AST builder (implicit)

### CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1

CSE P 501 Compilers Parsing & Context-Free Grammars Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 C-1 Administrivia Project partner signup: please find a partner and fill out the signup form by noon

### ECE468 Fall 2003, Final Exam

Name ECE468 Fall 2003, Final Exam This test has 9 pages and 9 questions. When told to begin please check to make sure you have all 9 pages. Let us know immediately if it doesn t. This test is open book

### Midterm I - Solution CS164, Spring 2014

164sp14 Midterm 1 - Solution Midterm I - Solution CS164, Spring 2014 March 3, 2014 Please read all instructions (including these) carefully. This is a closed-book exam. You are allowed a one-page handwritten

### LL(1) predictive parsing

LL(1) predictive parsing Informatics 2A: Lecture 11 Mary Cryan School of Informatics University of Edinburgh mcryan@staffmail.ed.ac.uk 10 October 2018 1 / 15 Recap of Lecture 10 A pushdown automaton (PDA)

### CSE 401 Midterm Exam Sample Solution 11/4/11

Question 1. (12 points, 2 each) The front end of a compiler consists of three parts: scanner, parser, and (static) semantics. Collectively these need to analyze the input program and decide if it is correctly

### CS 406/534 Compiler Construction Putting It All Together

CS 406/534 Compiler Construction Putting It All Together 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

### CSCE 531 Spring 2009 Final Exam

CSCE 531 Spring 2009 Final Exam Do all problems. Write your solutions on the paper provided. This test is open book, open notes, but no electronic devices. For your own sake, please read all problems before

### CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1

CSEP 501 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter 2008 1/8/2008 2002-08 Hal Perkins & UW CSE B-1 Agenda Basic concepts of formal grammars (review) Regular expressions

### CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

CS 1622 Lecture 2 Lexical Analysis CS 1622 Lecture 2 1 Lecture 2 Review of last lecture and finish up overview The first compiler phase: lexical analysis Reading: Chapter 2 in text (by 1/18) CS 1622 Lecture

### Optimizing Finite Automata

Optimizing Finite Automata We can improve the DFA created by MakeDeterministic. Sometimes a DFA will have more states than necessary. For every DFA there is a unique smallest equivalent DFA (fewest states

### Lexical Analysis. Introduction

Lexical Analysis Introduction Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission to make copies

### CSE 413 Programming Languages & Implementation. Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions

CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions 1 Agenda Overview of language recognizers Basic concepts of formal grammars Scanner Theory

### Midterm 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

### CS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers Overview of the Course These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Critical Facts Welcome to CS415 Compilers Topics in the

### CSE 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:

### Syntax. A. Bellaachia Page: 1

Syntax 1. Objectives & Definitions... 2 2. Definitions... 3 3. Lexical Rules... 4 4. BNF: Formal Syntactic rules... 6 5. Syntax Diagrams... 9 6. EBNF: Extended BNF... 10 7. Example:... 11 8. BNF Statement

### CS 415 Midterm Exam Spring SOLUTION

CS 415 Midterm Exam Spring 2005 - SOLUTION Name Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you

### RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 97 INSTRUCTIONS

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 97 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name

### Lecture 8: Deterministic Bottom-Up Parsing

Lecture 8: Deterministic Bottom-Up 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

### CSE 401 Final Exam. March 14, 2017 Happy π Day! (3/14) This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,...

CSE 401 Final Exam March 14, 2017 Happy π Day! (3/14) Name This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,.... Please wait to turn the page until everyone has their

### COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 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]

### Formal Languages and Grammars. Chapter 2: Sections 2.1 and 2.2

Formal Languages and Grammars Chapter 2: Sections 2.1 and 2.2 Formal Languages Basis for the design and implementation of programming languages Alphabet: finite set Σ of symbols String: finite sequence

### WARNING for Autumn 2004:

CSE 413 Programming Languages Autumn 2003 Max Points 50 Closed book, closed notes, no electronics. Do your own work! WARNING for Autumn 2004 Last year s exam did not cover Scheme and Java, but this year

### CSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1

CSE P 501 Compilers LR Parsing Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 D-1 Agenda LR Parsing Table-driven Parsers Parser States Shift-Reduce and Reduce-Reduce conflicts UW CSE P 501 Spring 2018

### Regular Expressions. Agenda for Today. Grammar for a Tiny Language. Programming Language Specifications

Agenda for Today Regular Expressions CSE 413, Autumn 2005 Programming Languages Basic concepts of formal grammars Regular expressions Lexical specification of programming languages Using finite automata

### Lecture 7: Deterministic Bottom-Up Parsing

Lecture 7: Deterministic Bottom-Up 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

### Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Lexical Analysis COMP 524, Spring 2014 Bryan Ward Based in part on slides and notes by J. Erickson, S. Krishnan, B. Brandenburg, S. Olivier, A. Block and others The Big Picture Character Stream Scanner

### CSE 401 Compilers. LR Parsing Hal Perkins Autumn /10/ Hal Perkins & UW CSE D-1

CSE 401 Compilers LR Parsing Hal Perkins Autumn 2011 10/10/2011 2002-11 Hal Perkins & UW CSE D-1 Agenda LR Parsing Table-driven Parsers Parser States Shift-Reduce and Reduce-Reduce conflicts 10/10/2011

### Compilers Crash Course

Compilers Crash Course Prof. Michael Clarkson CSci 6907.85 Spring 2014 Slides Acknowledgment: Prof. Andrew Myers (Cornell) What are Compilers? Translators from one representation of program code to another

### Formal Languages and Compilers Lecture VI: Lexical Analysis

Formal Languages and Compilers Lecture VI: Lexical Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/ artale/ Formal

### CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions

CSE 413 Programming Languages & Implementation Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions 1 Agenda Overview of language recognizers Basic concepts of formal grammars Scanner Theory

### Examination in Compilers, EDAN65

Examination in Compilers, EDAN65 Department of Computer Science, Lund University 2016 10 28, 08.00-13.00 Note! Your exam will be marked only if you have completed all six programming lab assignments in

### 2068 (I) Attempt all questions.

2068 (I) 1. What do you mean by compiler? How source program analyzed? Explain in brief. 2. Discuss the role of symbol table in compiler design. 3. Convert the regular expression 0 + (1 + 0)* 00 first

### CSCI Compiler Design

CSCI 565 - Compiler Design Spring 2015 Midterm Exam March 04, 2015 at 8:00 AM in class (RTH 217) Duration: 2h 30 min. Please label all pages you turn in with your name and student number. Name: Number:

### Part 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

### Introduction to Parsing. Lecture 8

Introduction to Parsing Lecture 8 Adapted from slides by G. Necula Outline Limitations of regular languages Parser overview Context-free grammars (CFG s) Derivations Languages and Automata Formal languages

### CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages Lecture 2: Syntax Analysis Zheng (Eddy) Zhang Rutgers University January 22, 2018 Announcement First recitation starts this Wednesday Homework 1 will be release

### Properties of Regular Expressions and Finite Automata

Properties of Regular Expressions and Finite Automata Some token patterns can t be defined as regular expressions or finite automata. Consider the set of balanced brackets of the form [[[ ]]]. This set

### Compiling Regular Expressions COMP360

Compiling Regular Expressions COMP360 Logic is the beginning of wisdom, not the end. Leonard Nimoy Compiler s Purpose The compiler converts the program source code into a form that can be executed by the

### CS415 Compilers. Lexical Analysis

CS415 Compilers Lexical Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Lecture 7 1 Announcements First project and second homework

### CS 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

### CSE 413 Final Exam Spring 2011 Sample Solution. Strings of alternating 0 s and 1 s that begin and end with the same character, either 0 or 1.

Question 1. (10 points) Regular expressions I. Describe the set of strings generated by each of the following regular expressions. For full credit, give a description of the sets like all sets of strings

### COP4020 Programming Languages. Syntax Prof. Robert van Engelen

COP4020 Programming Languages Syntax Prof. Robert van Engelen Overview n Tokens and regular expressions n Syntax and context-free grammars n Grammar derivations n More about parse trees n Top-down and

### UNIVERSITY OF CALIFORNIA

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS164 Fall 1997 P. N. Hilfinger CS 164: Midterm Name: Please do not discuss the contents of

### Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov 2014 Compiler Design (170701) Question Bank / Assignment Unit 1: INTRODUCTION TO COMPILING

### EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

EDAN65: Compilers, Lecture 06 A LR parsing Görel Hedin Revised: 2017-09-11 This lecture Regular expressions Context-free grammar Attribute grammar Lexical analyzer (scanner) Syntactic analyzer (parser)

### Principle of Compilers Lecture IV Part 4: Syntactic Analysis. Alessandro Artale

Free University of Bolzano Principles of Compilers Lecture IV Part 4, 2003/2004 AArtale (1) Principle of Compilers Lecture IV Part 4: Syntactic Analysis Alessandro Artale Faculty of Computer Science Free

### List of Figures. About the Authors. Acknowledgments

List of Figures Preface About the Authors Acknowledgments xiii xvii xxiii xxv 1 Compilation 1 1.1 Compilers..................................... 1 1.1.1 Programming Languages......................... 1

### Action Table for CSX-Lite. LALR Parser Driver. Example of LALR(1) Parsing. GoTo Table for CSX-Lite

LALR r Driver Action Table for CSX-Lite Given the GoTo and parser action tables, a Shift/Reduce (LALR) parser is fairly simple: { S 5 9 5 9 void LALRDriver(){ Push(S ); } R S R R R R5 if S S R S R5 while(true){

### Parsing II Top-down parsing. Comp 412

COMP 412 FALL 2018 Parsing II Top-down 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

### Compiler Optimisation

Compiler Optimisation 1 Introductory Lecture Hugh Leather IF 1.18a hleather@inf.ed.ac.uk Institute for Computing Systems Architecture School of Informatics University of Edinburgh 2018 Textbooks Engineering

### CSE302: Compiler Design

CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University March 20, 2007 Outline Recap LR(0)

### Problem Score Max Score 1 Syntax directed translation & type

CMSC430 Spring 2014 Midterm 2 Name Instructions You have 75 minutes for to take this exam. This exam has a total of 100 points. An average of 45 seconds per point. This is a closed book exam. No notes

### Syntax Analysis, VI Examples from LR Parsing. Comp 412

Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, VI Examples from LR Parsing Comp 412 COMP 412 FALL 2018 source code IR IR target Front End Optimizer Back End code Copyright

### CS 415 Midterm Exam Fall 2003

CS 415 Midterm Exam Fall 2003 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you can to

### CSE 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:

### CSE 413 Final Exam. December 13, 2012

CSE 413 Final Exam December 13, 2012 Name The exam is closed book, closed notes, no electronic devices, signal flags, tin-can telephones, or other signaling or communications apparatus. Style and indenting

### ECE251 Midterm practice questions, Fall 2010

ECE251 Midterm practice questions, Fall 2010 Patrick Lam October 20, 2010 Bootstrapping In particular, say you have a compiler from C to Pascal which runs on x86, and you want to write a self-hosting Java

### CSE au Final Exam Sample Solution

CSE 413 12au Final Exam Sample Solution Question 1. (10 points) Regular expressions I. Describe the set of strings generated by each of the following regular expressions. For full credit, give a description

### EECS 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

### CSE-304 Compiler Design

CSE-304 Compiler Design Fall 09 Final Exam December 14, 2009 Duration: 2 hours, 30 minutes. Maximum Score: 30 Name: USB ID Number: INSTRUCTIONS Read the following carefully before answering any question.

### CMSC 350: COMPILER DESIGN

Lecture 11 CMSC 350: COMPILER DESIGN see HW3 LLVMLITE SPECIFICATION Eisenberg CMSC 350: Compilers 2 Discussion: Defining a Language Premise: programming languages are purely formal objects We (as language

### Introduction to Parsing Ambiguity and Syntax Errors

Introduction to Parsing Ambiguity and Syntax rrors Outline Regular languages revisited Parser overview Context-free grammars (CFG s) Derivations Ambiguity Syntax errors Compiler Design 1 (2011) 2 Languages

### COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

COMP 181 Compilers Lecture 2 Overview September 7, 2006 Administrative Book? Hopefully: Compilers by Aho, Lam, Sethi, Ullman Mailing list Handouts? Programming assignments For next time, write a hello,

### Chapter 2 - Programming Language Syntax. September 20, 2017

Chapter 2 - Programming Language Syntax September 20, 2017 Specifying Syntax: Regular expressions and context-free grammars Regular expressions are formed by the use of three mechanisms Concatenation Alternation

### Lecture 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],

### Part I: Multiple Choice Questions (40 points)

Preparatory Course Grammars and Parsing Friday, November 11, 2005 (9:00-12:00 This exam consists of 10 multiple-choice questions (Part I and 3 open questions (Part II. The maximum number of points for

### The Parsing Problem (cont d) Recursive-Descent Parsing. Recursive-Descent Parsing (cont d) ICOM 4036 Programming Languages. The Complexity of Parsing

ICOM 4036 Programming Languages Lexical and Syntax Analysis Lexical Analysis The Parsing Problem Recursive-Descent Parsing Bottom-Up Parsing This lecture covers review questions 14-27 This lecture covers

### Principles 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

### Bottom-Up Parsing. Lecture 11-12

Bottom-Up Parsing Lecture 11-12 (From slides by G. Necula & R. Bodik) 9/22/06 Prof. Hilfinger CS164 Lecture 11 1 Bottom-Up Parsing Bottom-up parsing is more general than topdown parsing And just as efficient

### Bottom-Up Parsing. Lecture 11-12

Bottom-Up Parsing Lecture 11-12 (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

### MIDTERM EXAM (Solutions)

MIDTERM EXAM (Solutions) Total Score: 100, Max. Score: 83, Min. Score: 26, Avg. Score: 57.3 1. (10 pts.) List all major categories of programming languages, outline their definitive characteristics and

### Introduction to Parsing Ambiguity and Syntax Errors

Introduction to Parsing Ambiguity and Syntax rrors Outline Regular languages revisited Parser overview Context-free grammars (CFG s) Derivations Ambiguity Syntax errors 2 Languages and Automata Formal

### Languages, Automata, Regular Expressions & Scanners. Winter /8/ Hal Perkins & UW CSE B-1

CSE 401 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter 2010 1/8/2010 2002-10 Hal Perkins & UW CSE B-1 Agenda Quick review of basic concepts of formal grammars Regular

### Parsing Algorithms. Parsing: continued. Top Down Parsing. Predictive Parser. David Notkin Autumn 2008

Parsing: continued David Notkin Autumn 2008 Parsing Algorithms Earley s algorithm (1970) works for all CFGs O(N 3 ) worst case performance O(N 2 ) for unambiguous grammars Based on dynamic programming,

### CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going

### CS 315 Programming Languages Syntax. Parser. (Alternatively hand-built) (Alternatively hand-built)

Programming languages must be precise Remember instructions This is unlike natural languages CS 315 Programming Languages Syntax Precision is required for syntax think of this as the format of the language

### CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages Context Free Grammars 1 Architecture of Compilers, Interpreters Source Analyzer Optimizer Code Generator Abstract Syntax Tree Front End Back End Compiler

### Introduction to Parsing. Lecture 5

Introduction to Parsing Lecture 5 1 Outline Regular languages revisited Parser overview Context-free grammars (CFG s) Derivations Ambiguity 2 Languages and Automata Formal languages are very important

### Building a Parser Part III

COMP 506 Rice University Spring 2018 Building a Parser Part III With Practical Application To Lab One source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda

### CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

CS 4120 / 4121 CS 5120/5121 Introduction to Compilers Fall 2011 Andrew Myers Lecture 1: Overview Outline About this course Introduction to compilers What are compilers? Why should we learn about them?