Assignment 4. Due 09/18/17

Similar documents
Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

Dr. D.M. Akbar Hussain

Lexical Analysis: Constructing a Scanner from Regular Expressions

Scanner Termination. Multi Character Lookahead

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08

Definition of Regular Expression

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015

CSE 401 Midterm Exam 11/5/10 Sample Solution

Fig.25: the Role of LEX

Lexical analysis, scanners. Construction of a scanner

CS 432 Fall Mike Lam, Professor a (bc)* Regular Expressions and Finite Automata

Theory of Computation CSE 105

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

Topic 2: Lexing and Flexing

Reducing a DFA to a Minimal DFA

Scanning Theory and Practice

Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *

CSCE 531, Spring 2017, Midterm Exam Answer Key

ECE 468/573 Midterm 1 September 28, 2012

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos

Lexical Analysis. Amitabha Sanyal. ( as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

CS 430 Spring Mike Lam, Professor. Parsing

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis

TO REGULAR EXPRESSIONS

Should be done. Do Soon. Structure of a Typical Compiler. Plan for Today. Lab hours and Office hours. Quiz 1 is due tonight, was posted Tuesday night

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

CS 321 Programming Languages and Compilers. Bottom Up Parsing

Fall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University of the Negev

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

Fall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Midterm I Solutions CS164, Spring 2006

2014 Haskell January Test Regular Expressions and Finite Automata

Lexical Analysis and Lexical Analyzer Generators

10/12/17. Motivating Example. Lexical and Syntax Analysis (2) Recursive-Descent Parsing. Recursive-Descent Parsing. Recursive-Descent Parsing

Example: Source Code. Lexical Analysis. The Lexical Structure. Tokens. What do we really care here? A Sample Toy Program:

this grammar generates the following language: Because this symbol will also be used in a later step, it receives the

Lecture T4: Pattern Matching

LEX5: Regexps to NFA. Lexical Analysis. CMPT 379: Compilers Instructor: Anoop Sarkar. anoopsarkar.github.io/compilers-class

Regular Expression Matching with Multi-Strings and Intervals. Philip Bille Mikkel Thorup

CMSC 331 First Midterm Exam

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

acronyms possibly used in this test: CFG :acontext free grammar CFSM :acharacteristic finite state machine DFA :adeterministic finite automata

ASTs, Regex, Parsing, and Pretty Printing

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

Midterm 2 Sample solution

LING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong

Compilation

Lecture T1: Pattern Matching

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID:

Principles of Programming Languages

12 <= rm <digit> 2 <= rm <no> 2 <= rm <no> <digit> <= rm <no> <= rm <number>

INTRODUCTION TO SIMPLICIAL COMPLEXES

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or

Problem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins.

CMPSC 470: Compiler Construction

CS201 Discussion 10 DRAWTREE + TRIES

Alternation. Kleene Closure. Definition of Regular Expressions

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

Stack. A list whose end points are pointed by top and bottom

Compilers Spring 2013 PRACTICE Midterm Exam

P(r)dr = probability of generating a random number in the interval dr near r. For this probability idea to make sense we must have

Compiler Construction D7011E

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

Matrices and Systems of Equations

Java CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications

10.5 Graphing Quadratic Functions

COS 333: Advanced Programming Techniques

Reference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays

Section 3.1: Sequences and Series

Unit 5 Vocabulary. A function is a special relationship where each input has a single output.

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016

COS 333: Advanced Programming Techniques

12-B FRACTIONS AND DECIMALS

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications.

CMPT 379 Compilers. Lexical Analysis

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009

Digital Design. Chapter 6: Optimizations and Tradeoffs

Automata Processor. Tobias Markus Computer Architecture Group, University of Heidelberg

EECS 281: Homework #4 Due: Thursday, October 7, 2004

1.1. Interval Notation and Set Notation Essential Question When is it convenient to use set-builder notation to represent a set of numbers?

Functor (1A) Young Won Lim 10/5/17

Class-XI Mathematics Conic Sections Chapter-11 Chapter Notes Key Concepts

CS2204 DIGITAL LOGIC & STATE MACHINE DESIGN SPRING 2014

Lexical Analysis. Role, Specification & Recognition Tool: LEX Construction: - RE to NFA to DFA to min-state DFA - RE to DFA

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

Eliminating left recursion grammar transformation. The transformed expression grammar

Applied Databases. Sebastian Maneth. Lecture 13 Online Pattern Matching on Strings. University of Edinburgh - February 29th, 2016

Digital Design. Chapter 1: Introduction. Digital Design. Copyright 2006 Frank Vahid

Functor (1A) Young Won Lim 8/2/17

Alignment of Long Sequences. BMI/CS Spring 2012 Colin Dewey

Regular Expressions and Automata using Miranda

CS481: Bioinformatics Algorithms

Transcription:

Assignment 4. ue 09/18/17 1. ). Write regulr expressions tht define the strings recognized by the following finite utomt: b d b b b c c b) Write FA tht recognizes the tokens defined by the following regulr expression: ( (bc)*d)+ c) Write regulr expression tht defines Pscl-like fixed-deciml literl with no superfluous leding or triling zeroes. Tht is, 0.0, 123.01, nd 123005.0 re legl, but 00.0, 001.000, nd 002345.1000 re illegl. d) Let Rev be the opertor tht reverses strings. For exmple, Rev(bc) = cb. Let R be ny regulr expression. Rev(R) is the set of strings denoted by R, with ech string reversed. Is Rev(R) regulr set? Why? 2. Implement Micro Scnner river employing routines considered in clss. Scn 2 progrms from Ass-t 1. Scn two new progrms of your choice written on Micro lnguge employing your old Micro Scnner nd new Scnner river. Compre the outputs.

Scnning Lexicl Anlysis 2 How to specify the precise structure of tokens? Wht bout unprintble chrcters? Is 1..10 the sme s 1..10? How to correct errors? A precise definition of tokens is necessry to ensure tht lexicl rules re properly enforced. It lso llows lnguge designer to nticipte design flws. Scnner Genertor is n exmple of nonprocedurl progrmming. We do not tell it how to scn, but simply wht must be scnned. Regulr expressions nd finite utomt Regulr expressions re defined s follows. Ech regulr expression denotes set of strings ( regulr set). Ø is regulr expression denoting the empty set (the set contining no strings). λ is regulr expression denoting the set tht contins only the empty string. It is not the sme s Ø, becuse it contins one element. A string s of chrcters from the lphbet V is regulr expression denoting set contining only s. If s contins met-chrcters, i.e., (, ),, *, +,, s cn be quoted to void mbiguity. If A nd B re regulr expressions, then A B, AB, nd A* re lso regulr expressions, denoting the ltertion, ctention, nd Kleene closure of the corresponding regulr sets. The following opertions will be used for nottionl convenience. They re not strictly necessry, since their effect cn be obtined using stndrd regulr opertors: P is regulr expression. P+ denotes ll strings consisting of one or more strings in P ctented together: P+ =? P+ = P* λ If A is set of chrcters, Not(A) denotes ll chrcters in V not included in A: Not(A) = (V A); Wht is Not(A)*? Not(A)*= (V A)*

The set Ak represents ll strings formed by ctenting k (not necessrily different) symbols from A: Ak = AAA...A (k copies) 3 P+ = P* λ ; Not(A) = (V A); Not(A)*= (V A)*; Ak =AAA...A; Let us specify tokens. Let = (0... 9), L = (A... Z). A comment tht begins with nd ends with Eol. A fixed rel deciml literl. Comment = Not(Eol)* Eol Lit = +. + An identifier, composed of letters, digits, nd underscores, tht begins with letter, ends with letter or digit, nd contins no consecutive underscores. I = L(L )* (_(L )+)* A comment delimited by ## mrkers, which llows single # s within the comment body: Wht bout Comment2 = ##((# λ) Not(#))* ## It llows mny # mrkers within the comment body. If we need the only #, right expression is s follows: Comment3 = ## Not(#)*(# λ) Not(#)* ## A set of blnced brckets of the form [[[[...]]]] SetBrket = { [i ]i i 1} This is n infinite set. All the finite sets nd mny infinite sets re regulr but SetBrket is not regulr.

Finite Automt nd Scnners 4 A finite utomton (FA) cn be used to recognize the tokens specified by regulr expression. An FA is simple, idelized computer tht recognizes strings belonging to regulr sets. It consists of: A finite set of sttes A set of trnsitions (or moves) from one stte to nother, lbeled with chrcters in V A specil strt stte A set of finl, or ccepting, sttes FA cn be represented s trnsition digrms: b c The vlid tokens for the utomton shown in the digrm re described s (b(c)+)+ As n bbrevition, trnsition my be lbeled with more thn one chrcter, e.g., Not(c). The trnsition my be tken if the current input chrcter mtches ny of the chrcters lbeling the trnsition. c

eterministic Finite Automton (FA) is n FA which lwys hs unique next stte (for given stte nd chrcter). 5 Consider the expression, which defines n Ad comment: Not(Eol)* Eol Eol Not(Eol)

Consider exmples of regulr expressions nd corresponding FA. 6 You cn use the following formuls: P+ = P* λ ; Not(A) = (V A); Not(A)*= (V A)*; Ak; Let us specify tokens. Let = (0... 9), L = (A... Z). A FORTRAN-like rel literl (which requires digits on either or both sides of deciml point, or just string of digits). RelLit = (+( λ.)) (*. +) + λ (+( λ.)).

(+( λ.)) (λ. +) 7.. (+( λ.)) (*. +)..

8 An identifier consisting of letters, digits nd underscores ws defined s: I = L(L )* ( _(L )+)* L L L

You cn use the following formuls: P+ = P* λ ; Not(A) = (V A); Not(A)*= (V A)*; Ak; Let us specify tokens. Let = (0... 9), L = (A... Z). 9 Construct regulr expression nd FA for quoted strings: ( Not( ) )* Not(") " " "