# CS164: Midterm I. Fall 2003

Size: px
Start display at page:

Transcription

2 1 Regular Expressions/Finite Automata Part (a) Consider a language over the alphabet {0, 1} consisting of the strings that meet the following conditions: The length of the strings is 6. There must be at least one 1 in an odd position (1, 3, or 5) that is immediately followed by a 1 in an even position (2, 4, or 6). For example, , , and are all in the language; 00000, , and are not. Write a regular expression that defines this language: Part (b) Consider a language over the alphabet {0, 1} consisting of the strings that meet the following conditions: The length of the strings is 6. The last two characters must both be zero. For example, , , and are all in the language; , , and are not. Write a regular expression that defines this language: 2

3 Part (c) Draw two deterministic finite-state machines, one for the language defined in Part (a), and one for the language defined in Part (b). When drawing the state machines, use the appropriate notation for nodes and edges. Organize your node layouts neatly; the layout should reflect the logic of your solution. Part (d) Draw a non-deterministic finite-state machine for the language that is the union of the languages defined in Parts (a) and (b). (A string belongs to a language that is the union of languages A and B if the string belongs to A or B or both A and B.) 3

4 Part (e). Draw a deterministic finite-state machine for the language that is the union of the languages defined in Parts (a) and (b). Also, write a string that is not accepted by your finite-state machine. 4

5 2 First/Follow/LL(1) This question concerns the context-free grammar given below (where capital letters denote nonterminals, small letters denote terminals). S AB BAB A SA yx B x ɛ Part (a) Fill in the following table with First and Follow sets for the grammar. X FIRST(X) F OLLOW (X) S A B A B B A B y x x ɛ Part (b) In the LL(1) parsing table below, fill in the column headings, and the row corresponding to the non-terminal A: A Part (c) Is the grammar LL(1)? Justify your answer. 5

6 3 A Simple Real-World Problem Background: Recall that Java provides the ++ operator, which can be used either as a pre-increment or as a post-increment operator. That is, ++ can be used to increment the value of a variable either before or after the value of the variable is used. For example, if the value of x is initially 1, then the expression x++ evaluates to 1 and the expression ++x evaluates to 2. Also recall that x++ is a legal Java expression, but 3++ is not. That is, you can increment a memory location (e.g., a variable) but you cannot increment a value. Note that the error in 3++ is detected in the semantic phase of the compiler. Part (a) Draw an AST for the expression below. Label each AST node clearly with the meaning of the node (for example, addition, identifier, etc). Invent new types of AST nodes as necessary. x x Part (b) It is interesting to observe that while x x is a legal Java expression, the same expression without white spaces, namely x+++++x is not a legal Java expression. That is, the latter expression will cause a compile-time error. This question asks you to identify the phase of the compiler in which the error occurred. Depending on the compiler, the error can be flagged in different stages, and so there is more than one correct answer. (Continued on the next page.) 6

7 (i) Was the error found in the lexer? If yes, clearly explain the cause of the lexical error, and move on to Part (c) on the next page. If not, write the output of the lexer for this input expression and continue to (ii). (Assume that the lexer uses three kinds of tokens: the + operator, the ++ operator, and an identifier.) (ii) Was the error found in the parser? If yes, clearly explain the cause of the syntactic error, and move on to Part (c) on the next page. If not, write the output of the parser (i.e., an AST) for this input expression and continue to (iii). (iii) Was the error found in the semantic checker? If yes, clearly explain the cause of the semantic error. (Clearly, since you got all the way to this part, the answer must be yes.) To show the error, all you need to do is evaluate the AST from (ii) under the assumption that the initial value of x is 1, and show where and why the evaluation would fail. Evaluate the AST just like you did in your PA1 interpreter. 7

8 Part (c) Let s assume that when the programmer wrote the expression x+++++x, he really meant to compute the expression x x. Unfortunately, the first Java expression is not equivalent to the second expression with the whitespaces (as discussed above, the first expression is not even a legal Java expression). Clearly, in Java, white spaces are sometimes very important. One solution how to make the compiler recognize x+++++x as equivalent to x x without having to insert any whitespaces into the expression is to move part of the functionality of the lexer to the parser. Specifically, let us propose that the ++ operator won t be recognized in the lexer; instead, the lexer would simply turn each + character into a plus token. So, the lexer recognizes only two kinds of tokens: id and plus. As usual, the lexer discards any white space from the input. It would then be up to the parser to group plus tokens into ++ operators. Below is a grammar for such a parser. This grammar describes a tiny subset of the language of arithmetic expressions (this language includes additions, pre-increments and post-increments): E T plus E T T id id plus plus plus plus id (i) Show the parse tree for the input string x+++++x. (ii) Let s now show that the proposed solution unfortunately doesn t work because the grammar is ambiguous. Use the input x+++x to show that the grammar is ambiguous. Why does ambiguity in a grammar for a programming language pose a problem? 8

9 4 Lexer Generator The code below is a fragment of a solution for the second programming assignment (the lexer generator). The code shows a fragment of a visitor object that traverses a Java AST that represents a regular expression and creates an NFA that represents the regular expression. Specifically, the code shows a method that implements the regular expression + operator (i.e., the one-or-more repetition) as well as the * operator (i.e., the zero-or-more repetition). The code for the second operator is not shown. Your task is to fill in this missing code. public boolean visit(postfixexpression s) { // the traversal of the child s fills in the values of start, end // which are instance fields of the visitor object. s.getoperand().accept(this); NFAState childstart = start, childend = end; // Java ++ operator corresponds to regexp + operator if (s.getoperator() == PostfixExpression.Operator.INCREMENT) { start = new NFAState(); end = new NFAState(); start.addtransition(nfastate.epsilon, childstart); childend.addtransition(nfastate.epsilon, end); childend.addtransition(nfastate.epsilon, childstart); } // Java -- operator corresponds to regexp * operator else if (s.getoperator() == PostfixExpression.Operator.DECREMENT) { // ADD YOUR CODE HERE } } else assert false; return false; 9

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

### First Midterm Exam CS164, Fall 2007 Oct 2, 2007

P a g e 1 First Midterm Exam CS164, Fall 2007 Oct 2, 2007 Please read all instructions (including these) carefully. Write your name, login, and SID. No electronic devices are allowed, including cell phones

### CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this

### CS143 Midterm Fall 2008

CS143 Midterm Fall 2008 Please read all instructions (including these) carefully. There are 4 questions on the exam, some with multiple parts. You have 75 minutes to work on the exam. The exam is closed

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

### CS 164 Programming Languages and Compilers Handout 9. Midterm I Solution

Midterm I Solution Please read all instructions (including these) carefully. There are 5 questions on the exam, some with multiple parts. You have 1 hour and 20 minutes to work on the exam. The exam is

### UVa ID: NAME (print): CS 4501 LDI Midterm 1

CS 4501 LDI Midterm 1 Write your name and UVa ID on the exam. Pledge the exam before turning it in. There are nine (9) pages in this exam (including this one) and six (6) questions, each with multiple

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

### CS143 Midterm Spring 2014

CS143 Midterm Spring 2014 Please read all instructions (including these) carefully. There are 5 questions on the exam, most with multiple parts. You have 75 minutes to work on the exam. The exam is open

### Introduction to Lexing and Parsing

Introduction to Lexing and Parsing ECE 351: Compilers Jon Eyolfson University of Waterloo June 18, 2012 1 Riddle Me This, Riddle Me That What is a compiler? 1 Riddle Me This, Riddle Me That What is a compiler?

### CS143 Midterm Sample Solution Fall 2010

CS143 Midterm Sample Solution Fall 2010 Please read all instructions (including these) carefully. There are 4 questions on the exam, all with multiple parts. You have 75 minutes to work on the exam. 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:

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

### CS164 Second Midterm Exam Fall 2014

CS164 Second Midterm Exam Fall 2014 November 24 th, 2014 Please read all instructions (including these) carefully. This is a closed-book exam. You are allowed a one-page, one-sided handwritten cheat sheet.

### Lexical Analysis. Lecture 3. January 10, 2018

Lexical Analysis Lecture 3 January 10, 2018 Announcements PA1c due tonight at 11:50pm! Don t forget about PA1, the Cool implementation! Use Monday s lecture, the video guides and Cool examples if you re

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

### EXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully

EXAM Please read all instructions, including these, carefully There are 7 questions on the exam, with multiple parts. You have 3 hours to work on the exam. The exam is open book, open notes. Please write

### Question Marks 1 /20 2 /16 3 /7 4 /10 5 /16 6 /7 7 /24 Total /100

CSC 460/660, Midterm March 14, 2005 Name: Student ID: Signature: You have 75 minutes to write the 7 questions on this examination. A total of 100 marks is available. Justify all of your answers You may

### Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Lexical Analysis Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Compiler Passes Analysis of input program (front-end) character stream

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

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

### 1 Parsing (25 pts, 5 each)

CSC173 FLAT 2014 ANSWERS AND FFQ 30 September 2014 Please write your name on the bluebook. You may use two sides of handwritten notes. Perfect score is 75 points out of 85 possible. Stay cool and please

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

### CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages Context Free Grammars and Parsing 1 Recall: Architecture of Compilers, Interpreters Source Parser Static Analyzer Intermediate Representation Front End Back

### Compiler phases. Non-tokens

Compiler phases Compiler Construction Scanning Lexical Analysis source code scanner tokens regular expressions lexical analysis Lennart Andersson parser context free grammar Revision 2011 01 21 parse tree

### 1. Consider the following program in a PCAT-like language.

CS4XX INTRODUCTION TO COMPILER THEORY MIDTERM EXAM QUESTIONS (Each question carries 20 Points) Total points: 100 1. Consider the following program in a PCAT-like language. PROCEDURE main; TYPE t = FLOAT;

### Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday 1 Finite-state machines CS 536 Last time! A compiler is a recognizer of language S (Source) a translator from S to T (Target) a program

### CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters

: Organization of Programming Languages Context Free Grammars 1 Architecture of Compilers, Interpreters Source Scanner Parser Static Analyzer Intermediate Representation Front End Back End Compiler / Interpreter

### Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens

Syntactic Analysis CS45H: Programming Languages Lecture : Lexical Analysis Thomas Dillig Main Question: How to give structure to strings Analogy: Understanding an English sentence First, we separate a

### Lexical Analysis. Finite Automata

#1 Lexical Analysis Finite Automata Cool Demo? (Part 1 of 2) #2 Cunning Plan Informal Sketch of Lexical Analysis LA identifies tokens from input string lexer : (char list) (token list) Issues in Lexical

### A simple syntax-directed

Syntax-directed is a grammaroriented compiling technique Programming languages: Syntax: what its programs look like? Semantic: what its programs mean? 1 A simple syntax-directed Lexical Syntax Character

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

### 2.2 Syntax Definition

42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions

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

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

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

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

### Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Name: of 7 Theory of Computation Dr. Weiss Extra Practice Exam Solutions Directions: Answer the questions as well as you can. Partial credit will be given, so show your work where appropriate. Try to be

### Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End

Architecture of Compilers, Interpreters : Organization of Programming Languages ource Analyzer Optimizer Code Generator Context Free Grammars Intermediate Representation Front End Back End Compiler / Interpreter

### Semantic Analysis. Lecture 9. February 7, 2018

Semantic Analysis Lecture 9 February 7, 2018 Midterm 1 Compiler Stages 12 / 14 COOL Programming 10 / 12 Regular Languages 26 / 30 Context-free Languages 17 / 21 Parsing 20 / 23 Extra Credit 4 / 6 Average

### Midterm II CS164, Spring 2006

Midterm II CS164, Spring 2006 April 11, 2006 Please read all instructions (including these) carefully. Write your name, login, SID, and circle the section time. There are 10 pages in this exam and 4 questions,

### Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

More detailed overview of compiler front end Structure of a compiler Today we ll take a quick look at typical parts of a compiler. This is to give a feeling for the overall structure. source program lexical

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

### CMSC 330, Fall 2018 Midterm 2

CMSC 330, Fall 2018 Midterm 2 Name Teaching Assistant Kameron Aaron Danny Chris Michael P. Justin Cameron B. Derek Kyle Hasan Shriraj Cameron M. Alex Michael S. Pei-Jo Instructions Do not start this exam

### CSE 12 Abstract Syntax Trees

CSE 12 Abstract Syntax Trees Compilers and Interpreters Parse Trees and Abstract Syntax Trees (AST's) Creating and Evaluating AST's The Table ADT and Symbol Tables 16 Using Algorithms and Data Structures

### Scanners. Xiaokang Qiu Purdue University. August 24, ECE 468 Adapted from Kulkarni 2012

Scanners Xiaokang Qiu Purdue University ECE 468 Adapted from Kulkarni 2012 August 24, 2016 Scanners Sometimes called lexers Recall: scanners break input stream up into a set of tokens Identifiers, reserved

### Lexical Analysis. Chapter 2

Lexical Analysis Chapter 2 1 Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexers Regular expressions Examples

### Grammars & 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

### Question Marks 1 /16 2 /13 3 /12 4 /15 5 /8 6 /15 7 /8 8 /5 9 /8 Total /100

CSC 460/660, Midterm March 22, 2006 Name: Student ID: Signature: You have 75 minutes to write the 9 questions on this examination. A total of 100 marks is available. Justify all of your answers You may

### Final Exam 2, CS154. April 25, 2010

inal Exam 2, CS154 April 25, 2010 Exam rules. he exam is open book and open notes you can use any printed or handwritten material. However, no electronic devices are allowed. Anything with an on-off switch

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

### COL728 Minor1 Exam Compiler Design Sem II, Answer all 5 questions Max. Marks: 20

COL728 Minor1 Exam Compiler Design Sem II, 2016-17 Answer all 5 questions Max. Marks: 20 1. Short questions a. Show that every regular language is also a context-free language [2] We know that every regular

### CMSC 330: Organization of Programming Languages. Context Free Grammars

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

### CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

CSECE 374 Fall 2016 Homework 1 Due Tuesday, September 6, 2016 at 8pm Starting with this homework, groups of up to three people can submit joint solutions. Each problem should be submitted by exactly one

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

### CMSC 330: Organization of Programming Languages. Context Free Grammars

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

### Lexical Analysis. Lecture 2-4

Lexical Analysis Lecture 2-4 Notes by G. Necula, with additions by P. Hilfinger Prof. Hilfinger CS 164 Lecture 2 1 Administrivia Moving to 60 Evans on Wednesday HW1 available Pyth manual available on line.

### Monday, August 26, 13. Scanners

Scanners Scanners Sometimes called lexers Recall: scanners break input stream up into a set of tokens Identifiers, reserved words, literals, etc. What do we need to know? How do we define tokens? How can

### Implementation of Lexical Analysis. Lecture 4

Implementation of Lexical Analysis Lecture 4 1 Tips on Building Large Systems KISS (Keep It Simple, Stupid!) Don t optimize prematurely Design systems that can be tested It is easier to modify a working

### Lexical Analysis. Finite Automata

#1 Lexical Analysis Finite Automata Cool Demo? (Part 1 of 2) #2 Cunning Plan Informal Sketch of Lexical Analysis LA identifies tokens from input string lexer : (char list) (token list) Issues in Lexical

### CS131 Compilers: Programming Assignment 2 Due Tuesday, April 4, 2017 at 11:59pm

CS131 Compilers: Programming Assignment 2 Due Tuesday, April 4, 2017 at 11:59pm Fu Song 1 Policy on plagiarism These are individual homework. While you may discuss the ideas and algorithms or share the

### Wednesday, September 3, 14. Scanners

Scanners Scanners Sometimes called lexers Recall: scanners break input stream up into a set of tokens Identifiers, reserved words, literals, etc. What do we need to know? How do we define tokens? How can

### CS143 Final Fall 2009

CS143 Final Fall 2009 Please read all instructions (including these) carefully. There are 4 questions on the exam, all with multiple parts. You have 2 hours to work on the exam. The exam is closed book,

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

### Final Exam CS164, Fall 2007 Dec 18, 2007

P a g e 1 Final Exam CS164, Fall 2007 Dec 18, 2007 Please read all instructions (including these) carefully. Write your name, login, and SID. No electronic devices are allowed, including cell phones used

### Week 2: Syntax Specification, Grammars

CS320 Principles of Programming Languages Week 2: Syntax Specification, Grammars Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Week 2: Syntax Specification, Grammars 1/ 62 Words and Sentences

### Lexical Analysis. Lecture 3-4

Lexical Analysis Lecture 3-4 Notes by G. Necula, with additions by P. Hilfinger Prof. Hilfinger CS 164 Lecture 3-4 1 Administrivia I suggest you start looking at Python (see link on class home page). Please

### CS 164 Handout 16. Final Examination. There are nine questions on the exam, some in multiple parts. You have 3 hours to work on the

Final Examination Please read all instructions (including these) carefully. Please print your name at the bottom of each page on the exam. There are nine questions on the exam, some in multiple parts.

### Final Exam 1, CS154. April 21, 2010

Final Exam 1, CS154 April 21, 2010 Exam rules. The exam is open book and open notes you can use any printed or handwritten material. However, no electronic devices are allowed. Anything with an on-off

### CSE 582 Autumn 2002 Exam 11/26/02

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:

### UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2010 P. N. Hilfinger CS 164: Final Examination (revised) Name: Login: You have

### Midterm Exam. CS169 Fall November 17, 2009 LOGIN: NAME: SID: Problem Max Points Points TOTAL 100

Midterm Exam CS169 Fall 2009 November 17, 2009 Please read all instructions (including these) carefully. Write your name, login, and SID. There are 12 pages in this exam and 6 questions, each with multiple

### Introduction to Lexical Analysis

Introduction to Lexical Analysis Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexical analyzers (lexers) Regular

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

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

### University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016 The entire examination is 925 points. The real final will be much shorter. Name: No books, notes, scratch paper, or calculators. Use pen

### Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

1 Semantics via Syntax The specification of a programming language starts with its syntax. As every programmer knows, the syntax of a language comes in the shape of a variant of a BNF (Backus-Naur Form)

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

i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

### CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages!! Chapter 3 Regular Expression and Lexer Xu Liu Recap! Copyright 2006 The McGraw-Hill Companies, Inc. Clite: Lexical Syntax! Input: a stream of characters from

### Implementation of Lexical Analysis

Implementation of Lexical Analysis Outline Specifying lexical structure using regular expressions Finite automata Deterministic Finite Automata (DFAs) Non-deterministic Finite Automata (NFAs) Implementation

### Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

CMPSCI 601: Recall From Last Time Lecture 5 Definition: A context-free grammar (CFG) is a 4- tuple, variables = nonterminals, terminals, rules = productions,,, are all finite. 1 ( ) \$ Pumping Lemma for

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

### Introduction to Lexical Analysis

Introduction to Lexical Analysis Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexers Regular expressions Examples

### Project 1: Scheme Pretty-Printer

Project 1: Scheme Pretty-Printer CSC 4101, Fall 2017 Due: 7 October 2017 For this programming assignment, you will implement a pretty-printer for a subset of Scheme in either C++ or Java. The code should

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

### UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2009 P. N. Hilfinger CS 164: Final Examination (corrected) Name: Login: You have

### Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

Lexical Analysis Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata Phase Ordering of Front-Ends Lexical analysis (lexer) Break input string

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

### 1. [5 points each] True or False. If the question is currently open, write O or Open.

University of Nevada, Las Vegas Computer Science 456/656 Spring 2018 Practice for the Final on May 9, 2018 The entire examination is 775 points. The real final will be much shorter. Name: No books, notes,

### CS Introduction to Data Structures How to Parse Arithmetic Expressions

CS3901 - Introduction to Data Structures How to Parse Arithmetic Expressions Lt Col Joel Young One of the common task required in implementing programming languages, calculators, simulation systems, and

### CMSC330 Spring 2018 Midterm 2 9:30am/ 11:00am/ 3:30pm

CMSC330 Spring 2018 Midterm 2 9:30am/ 11:00am/ 3:30pm Name (PRINT YOUR NAME as it appears on gradescope ): SOLUTION Discussion Time (circle one) 10am 11am 12pm 1pm 2pm 3pm Instructions Do not start this

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

### Course Project 2 Regular Expressions

Course Project 2 Regular Expressions CSE 30151 Spring 2017 Version of February 16, 2017 In this project, you ll write a regular expression matcher similar to grep, called mere (for match and echo using

### Extra Credit Question

Top-Down Parsing #1 Extra Credit Question Given this grammar G: E E+T E T T T * int T int T (E) Is the string int * (int + int) in L(G)? Give a derivation or prove that it is not. #2 Revenge of Theory