# DVA337 HT17 - LECTURE 4. Languages and regular expressions

Size: px
Start display at page:

Transcription

1 DVA337 HT17 - LECTURE 4 Languages and regular expressions 1

2 SO FAR 2

3 TODAY Formal definition of languages in terms of strings Operations on strings and languages Definition of regular expressions Meaning of regular expressions in terms of languages Outlook: practical use of regular expressions 3

4 LANGUAGES alphabets, strings, and languages 4

5 LANGUAGE How can we define what a (formal) language is? 5

6 LANGUAGE We define a language to be a set of strings over an alphabet Σ An alphabet is a set of symbols, e.g., { a, b, c,..., z } A string over an alphabet Σ is a sequence of symbols from the alphabet What is the alphabet for the language L = { apple, pear, 1911 } L = { x : x is a binary string } 6

7 EXERCISE, LANGUAGE How can we define the alphabet and language for 1) the programming language C? 2) written English? 7

8 STRINGS 8

9 STRINGS For a 1, a 2,..., a n Σ the sequence a 1 a 2... a n is a string over Σ The empty string is written λ What are the strings over Σ = { a, b }? Let u, v, w denote strings 9

10 CONCATENATION For u = a 1 a 2... a n and v = b 1 b 2... b n what is the concatenation of u and v, written uv? 10

11 PREFIX AND SUFFIX For a string w = u v u is a prefix v is a suffix All prefixes and suffixes for abbab? 11

12 SUBSTRING For a string w = u 1 v u 2 v is a substring prefix and suffix special cases of substring Substrings of abbab? 12

13 LENGTH For string w = a 1 a 2... a n, the length is n, w = n λ = 0 abbab = 5 How can we define length recursively? 13

14 PROOF BY INDUCTION Induction over natural numbers To show that a property P holds for all natural numbers, n N. P(n), show A base case, e.g., P(0) An inductive step, n N. P(n) P(n+1) Why can we conclude n N. P(n) from this? 14

15 EXERCISE, LENGTH OF CONCATENATION What is u v? Can we prove it? 15

16 LENGTH OF CONCATENATION Theorem: u v = u + v Proof: By induction on the length of v. 16

17 REVERSE For a string w = a 1 a 2... a n what is the reverse w R of w? What is a palindrome? 17

18 REPETITION Let w n be w repeated n times, w w... w Can you write a recursive definition of w n? 18

19 Σ N, STRINGS OF LENGTH N Let Σ n be the set of strings of length n over Σ For Σ = {a, b} Σ 0 = { λ } Σ 1 = { a, b } Σ 2 = { aa, ab, ba, bb } How can we define Σ n? 19

20 Σ*, KLEENE CLOSURE Σ* is the set of all strings over Σ {a,b}* = { λ, a, b, aa, bb, ab, ba, aaa, bbb,... } How can we define Σ*? 20

21 Σ*, KLEENE CLOSURE We have that Σ* = Σ 0 Σ 1..., where Σ 0 = { λ } Σ n+1 = { x y : x Σ, y Σ n } Can we use this to define Σ*? as a fixpoint to F(S) S for some F? 21

22 Σ +, POSITIVE CLOSURE Let Σ + = Σ 1 Σ 2... How can we define the positive closure? 22

23 EXERCISE For Σ = {a, b} what is the cardinality of Σ 3? In general, what is the cardinality of Σ n? For Σ as below, give Σ* and Σ + Σ = { 0, 1 } Σ = { a } Σ = { } 23

24 EXERCISE Prove that Σ n = Σ n 24

25 LANGUAGES 25

26 LANGUAGE A language L is a set of strings over an alphabet Σ A language L is a subset of Σ* For Σ = { a, b } Σ* = { λ, a, b, aa, ab, ba, bb, aaa, aab,... } Examples of languages over Σ? 26

27 EXERCISE What is P(Σ*)? 27

28 SET OPERATIONS ON LANGUAGES Since language are sets, the standard set operations apply. For L 1 = {a, b, aaa} and L 2 = {bb, ab}, what is L 1 L 2 L 1 L 2 L 1 L 2 What is the complement of a language, L 28

29 REVERSAL AND CONCATENATION Reversal and concatenation carry over from strings in the natural way Reversal, L R = { w R : w L } { ab, aab, baba } R {a n b n : n 0 } Concatenation, L 1 L 2 = { u v : u L 1, v L 2 } { ab, aab, baba }{b,aa} 29

30 REPETITION With concatenation of languages defined, we can define repetition L 0 = { λ } L n+1 = { u v : u L, v L n } For L = { a n b n : n 0} what is L 2? what is L 0? 30

31 CLOSURES With repetition we can define Kleene closure and positive closure for languages L* = L 0 L 1... L + = L 1 L 2... What is L* in words? If L* = L we say that L is Kleene closed Is C Kleene closed? 31

32 SUMMARY An alphabet, Σ, is a set of symbols A string is a sequence of symbols concatenation, reverse, length, substring, prefix, suffix, repetition Kleene closure Σ*, and positive closure Σ + A language over Σ is a set of strings; a subset of Σ * union, intersection, difference, complement reverse, concatenation, repetition Kleene closure L *, and positive closure L + (c.f., Σ * and Σ + ) 32

33 WHY IS THIS USEFUL? Broad definition: any set of strings on an alphabet is a language Methods of defining language grammars Methods of deciding membership in languages How to answer the questions if a given string is in a given language Can membership always be decided? 33

34 REGULAR EXPRESSIONS 34

35 REGULAR EXPRESSIONS, λ, and any α Σ are primitive regular expressions If r 1 and r 2 are regular expressions, then so are r 1 + r 2, r 1 r 2, r*, and (r) 35

36 EXERCISE Is (a + bc)*(c+λ) a regular expression? Is (a + b +) a regular expression? 36

37 INTUITIVE MEANING Each regular expression over Σ defines a language over Σ think in terms of matching, λ, and any α Σ are primitive regular expressions If r 1 and r 2 are regular expressions, then so are r 1 + r 2, r 1 r 2, r*, and (r) 37

38 EXAMPLE What is the language defined by a + b? What is the language defined by (ab)*? Exercise, what is the language defined by (a + bc)*(c+λ)? 38

39 LANGUAGE DEFINED BY REGULAR EXPRESSIONS How can we define the language of a regular expression more formally? Can we build a recursive function, L(r) that defines the language of a regular expression r? Remember a language is a set of strings we have defined operations on languages: union, concatenation, Kleene star 39

40 EXAMPLE What is L((a + b)a*)? 40

41 EXERCISE What is the language defined by (a+b)*(a+bb) 41

42 ON PRECEDENCE What is the language defined by (a + b)a What is the language defined by a + (ba) Which one is a + ba? 42

43 EXERCISE What is the language defined by (aa)*(bb)*b? 43

44 EXAMPLE Create a regular expression over Σ = { 0, 1 } that defines the language where all strings have at least two consecutive 0s 001 L 010 L 44

45 EXERCISE Construct the regular expression over { 0, 1 } where no string has two consecutive 0s. 010 L 001 L 45

46 EQUIVALENCE OF REGULAR EXPRESSIONS Two regular expressions are equivalent if they define the same language L = { all strings over {0, 1} without consecutive 0 } r 1 = (1+01)*(0+λ) r 2 = (1+011*)*(0+λ)+1*(0+λ) Since L = L(r 1 ) = L(r 2 ) we have that r 1 and r 2 are equivalent. Can we prove that L(r 1 ) = L(r 2 ) in some way? 46

47 REGULAR EXPRESSIONS IN REALITY Slightly richer alphabet and language than what we saw here, e.g., quantifiers: *, +,?, {m}, {m,}, {m,n}, atoms: char, [chars],., ^, \$, \char Example uses Lexical analysis - tokenization preceding parsing Text search grep/egrep (unix) Search for gr(a e)y ^[-+]?[0-9]*\.?[0-9]+\$ 47

48 REGULAR EXPRESSIONS IN COMPILERS The programmer creates a program The lexer splits the program text into a stream of tokens and removes white space Literals: 1, 1.32, Hello World! Keywords: if, while, Variables: c, y, counter, The token stream is passed to the parser that creates a parse tree, which is used by the next step of the compiler this simplifies the parse as it can work on tokens rather than on characters. Text Tokens Binary Lexer Parser 48

49 PARTS OF EXAMPLE PASCAL LEXER white_space [ \t]* digit [0-9] alpha alpha_num hex_digit identifier unsigned_integer hex_integer exponent i real string [A-Za-z_] ({alpha} {digit}) [0-9A-F] {alpha}{alpha_num}* {digit}+ \${hex_digit}{hex_digit}* e[+-]?{digit}+ {unsigned_integer} ({i}\.{i}? {i}?\.{i}){exponent}? \'([^'\n] \'\')+\ and array begin return(and); return(array); return(_begin); 49

50 EXAMPLE TOKENIZATION Consider the following PASCAL program Program Lesson1_Program1; Begin Write('Hello World'); Readln; End. Which would produce the following token stream PROGRAM IDENTIFIER BEGIN IDENTIFIER ( STRING ) ; IDENTIFIER ; END. Note that the tokens are represented by integers and tokens like IDENTIFIER and STRING carry the actual string representing the token. 50

51 REGULAR LANGUAGES Topic for the next few lectures Ways of defining regular language Regular Expressions (RE) Regular grammars Ways of deciding membership in regular languages DFA and NFA Equivalence of the approaches DFA NFA RE 51

52 REGULAR LANGUAGES Regular Expression DFA Regular Language NFA Regular Grammar 52

53 DO THE EXERCISES! Exercise material on the homepage exercises similar to what will be on exam If you get stuck ask a friend ask me If several of you have issues with one we ll add it to a lecture. 53

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

COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! [ALSU03] Chapter 3 - Lexical Analysis Sections 3.1-3.4, 3.6-3.7! Reading for next time [ALSU03] Chapter 3 Copyright (c) 2010 Ioanna

### Languages and Strings. Chapter 2

Languages and Strings Chapter 2 Let's Look at Some Problems int alpha, beta; alpha = 3; beta = (2 + 5) / 10; (1) Lexical analysis: Scan the program and break it up into variable names, numbers, etc. (2)

### CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 2: Lexical Analysis 23 Jan 08

CS412/413 Introduction to Compilers Tim Teitelbaum Lecture 2: Lexical Analysis 23 Jan 08 Outline Review compiler structure What is lexical analysis? Writing a lexer Specifying tokens: regular expressions

### Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

Proof Techniques Alphabets, Strings, and Languages Foundations of Computer Science Theory Proof By Case Enumeration Sometimes the most straightforward way to prove that a property holds for all elements

### Formal Languages and Automata

Mobile Computing and Software Engineering p. 1/3 Formal Languages and Automata Chapter 3 Regular languages and Regular Grammars Chuan-Ming Liu cmliu@csie.ntut.edu.tw Department of Computer Science and

### 1.3 Functions and Equivalence Relations 1.4 Languages

CSC4510 AUTOMATA 1.3 Functions and Equivalence Relations 1.4 Languages Functions and Equivalence Relations f : A B means that f is a function from A to B To each element of A, one element of B is assigned

### Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

Regular Expressions Lecture 10 Sections 3.1-3.2 Robb T. Koether Hampden-Sydney College Wed, Sep 14, 2016 Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 1 / 23 Outline 1

### 2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

2010: Compilers Lexical Analysis: Finite State Automata Dr. Licia Capra UCL/CS REVIEW: REGULAR EXPRESSIONS a Character in A Empty string R S Alternation (either R or S) RS Concatenation (R followed by

### Dr. D.M. Akbar Hussain

1 2 Compiler Construction F6S Lecture - 2 1 3 4 Compiler Construction F6S Lecture - 2 2 5 #include.. #include main() { char in; in = getch ( ); if ( isalpha (in) ) in = getch ( ); else error (); while

### Chapter Seven: Regular Expressions

Chapter Seven: Regular Expressions Regular Expressions We have seen that DFAs and NFAs have equal definitional power. It turns out that regular expressions also have exactly that same definitional power:

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

### CMPSCI 250: Introduction to Computation. Lecture #28: Regular Expressions and Languages David Mix Barrington 2 April 2014

CMPSCI 250: Introduction to Computation Lecture #28: Regular Expressions and Languages David Mix Barrington 2 April 2014 Regular Expressions and Languages Regular Expressions The Formal Inductive Definition

### 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 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION Spring 2017 http://cseweb.ucsd.edu/classes/sp17/cse105-ab/ Today's learning goals Sipser Ch 1.2, 1.3 Design NFA recognizing a given language Convert an NFA (with or without

### Compiler Construction

Compiler Construction Exercises 1 Review of some Topics in Formal Languages 1. (a) Prove that two words x, y commute (i.e., satisfy xy = yx) if and only if there exists a word w such that x = w m, y =

### Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Last lecture CMSC330 Finite Automata Languages Sets of strings Operations on languages Regular expressions Constants Operators Precedence 1 2 Finite automata States Transitions Examples Types This lecture

### Finite Automata Part Three

Finite Automata Part Three Friday Four Square! Today at 4:15PM, Outside Gates. Announcements Problem Set 4 due right now. Problem Set 5 out, due next Friday, November 2. Play around with finite automata

### Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Chapter 1: Introduction Introduction Purpose of the Theory of Computation: Develop formal mathematical models of computation that reflect real-world computers. Nowadays, the Theory of Computation can be

### CS321 Languages and Compiler Design I. Winter 2012 Lecture 4

CS321 Languages and Compiler Design I Winter 2012 Lecture 4 1 LEXICAL ANALYSIS Convert source file characters into token stream. Remove content-free characters (comments, whitespace,...) Detect lexical

### Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens

Concepts Introduced in Chapter 3 Lexical Analysis Regular Expressions (REs) Nondeterministic Finite Automata (NFA) Converting an RE to an NFA Deterministic Finite Automatic (DFA) Lexical Analysis Why separate

### CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

Solved Subjective From Midterm Papers Dec 07,2012 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 MIDTERM SPRING 2012 Q. Point of Kleen Theory. Answer:- (Page 25) 1. If a language can be accepted

### ECS 120 Lesson 7 Regular Expressions, Pt. 1

ECS 120 Lesson 7 Regular Expressions, Pt. 1 Oliver Kreylos Friday, April 13th, 2001 1 Outline Thus far, we have been discussing one way to specify a (regular) language: Giving a machine that reads a word

### Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Finite Automata Dr. Nadeem Akhtar Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur PhD Laboratory IRISA-UBS University of South Brittany European University

### Lexical Analysis. Sukree Sinthupinyo July Chulalongkorn University

Sukree Sinthupinyo 1 1 Department of Computer Engineering Chulalongkorn University 14 July 2012 Outline Introduction 1 Introduction 2 3 4 Transition Diagrams Learning Objectives Understand definition of

### Outline. 1 Scanning Tokens. 2 Regular Expresssions. 3 Finite State Automata

Outline 1 2 Regular Expresssions Lexical Analysis 3 Finite State Automata 4 Non-deterministic (NFA) Versus Deterministic Finite State Automata (DFA) 5 Regular Expresssions to NFA 6 NFA to DFA 7 8 JavaCC:

### Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

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

### Regular Expressions. Regular Expressions. Regular Languages. Specifying Languages. Regular Expressions. Kleene Star Operation

Another means to describe languages accepted by Finite Automata. In some books, regular languages, by definition, are described using regular. Specifying Languages Recall: how do we specify languages?

### Lexical Analysis 1 / 52

Lexical Analysis 1 / 52 Outline 1 Scanning Tokens 2 Regular Expresssions 3 Finite State Automata 4 Non-deterministic (NFA) Versus Deterministic Finite State Automata (DFA) 5 Regular Expresssions to NFA

### Lexical Analysis (ASU Ch 3, Fig 3.1)

Lexical Analysis (ASU Ch 3, Fig 3.1) Implementation by hand automatically ((F)Lex) Lex generates a finite automaton recogniser uses regular expressions Tasks remove white space (ws) display source program

### Glynda, the good witch of the North

Strings and Languages It is always best to start at the beginning -- Glynda, the good witch of the North What is a Language? A language is a set of strings made of of symbols from a given alphabet. An

### Lecture 4: Syntax Specification

The University of North Carolina at Chapel Hill Spring 2002 Lecture 4: Syntax Specification Jan 16 1 Phases of Compilation 2 1 Syntax Analysis Syntax: Webster s definition: 1 a : the way in which linguistic

### Multiple Choice Questions

Techno India Batanagar Computer Science and Engineering Model Questions Subject Name: Formal Language and Automata Theory Subject Code: CS 402 Multiple Choice Questions 1. The basic limitation of an FSM

### Lexical Analysis - 1. A. Overview A.a) Role of Lexical Analyzer

CMPSC 470 Lecture 02 Topics: Regular Expression Transition Diagram Lexical Analyzer Implementation A. Overview A.a) Role of Lexical Analyzer Lexical Analysis - 1 Lexical analyzer does: read input character

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

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

### CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION Spring 2017 http://cseweb.ucsd.edu/classes/sp17/cse105-ab/ Today's learning goals Sipser Ch 1.2, 1.3 Decide whether or not a string is described by a given regular expression

### Chapter 4. Lexical analysis. Concepts. Lexical scanning Regular expressions DFAs and FSAs Lex. Lexical analysis in perspective

Chapter 4 Lexical analysis Lexical scanning Regular expressions DFAs and FSAs Lex Concepts CMSC 331, Some material 1998 by Addison Wesley Longman, Inc. 1 CMSC 331, Some material 1998 by Addison Wesley

### Lexical Analyzer Scanner

Lexical Analyzer Scanner ASU Textbook Chapter 3.1, 3.3, 3.4, 3.6, 3.7, 3.5 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Main tasks Read the input characters and produce

### HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

HKN CS 374 Midterm 1 Review Tim Klem Noah Mathes Mahir Morshed Midterm topics It s all about recognizing sets of strings! 1. String Induction 2. Regular languages a. DFA b. NFA c. Regular expressions 3.

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

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81% 1. (2 pts) See text. You can t be sloppy defining terms like this. You must show a bijection between the natural numbers

### Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016 Lecture 15 Ana Bove May 23rd 2016 More on Turing machines; Summary of the course. Overview of today s lecture: Recap: PDA, TM Push-down

### CHAPTER TWO LANGUAGES. Dr Zalmiyah Zakaria

CHAPTER TWO LANGUAGES By Dr Zalmiyah Zakaria Languages Contents: 1. Strings and Languages 2. Finite Specification of Languages 3. Regular Sets and Expressions Sept2011 Theory of Computer Science 2 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

### Ambiguous Grammars and Compactification

Ambiguous Grammars and Compactification Mridul Aanjaneya Stanford University July 17, 2012 Mridul Aanjaneya Automata Theory 1/ 44 Midterm Review Mathematical Induction and Pigeonhole Principle Finite Automata

### Concepts. Lexical scanning Regular expressions DFAs and FSAs Lex. Lexical analysis in perspective

Concepts Lexical scanning Regular expressions DFAs and FSAs Lex CMSC 331, Some material 1998 by Addison Wesley Longman, Inc. 1 CMSC 331, Some material 1998 by Addison Wesley Longman, Inc. 2 Lexical analysis

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

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

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

### Lexical Analyzer Scanner

Lexical Analyzer Scanner ASU Textbook Chapter 3.1, 3.3, 3.4, 3.6, 3.7, 3.5 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Main tasks Read the input characters and produce

### Zhizheng Zhang. Southeast University

Zhizheng Zhang Southeast University 2016/10/5 Lexical Analysis 1 1. The Role of Lexical Analyzer 2016/10/5 Lexical Analysis 2 2016/10/5 Lexical Analysis 3 Example. position = initial + rate * 60 2016/10/5

### 2. λ is a regular expression and denotes the set {λ} 4. If r and s are regular expressions denoting the languages R and S, respectively

Regular expressions: a regular expression is built up out of simpler regular expressions using a set of defining rules. Regular expressions allows us to define tokens of programming languages such as identifiers.

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

### Notes for Comp 454 Week 2

Notes for Comp 454 Week 2 This week we look at the material in chapters 3 and 4. Homework on Chapters 2, 3 and 4 is assigned (see end of notes). Answers to the homework problems are due by September 10th.

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

### Languages and Finite Automata

Languages and Finite Automata or how to talk to machines... Costas Busch - RPI 1 Languages A language is a set of strings String: A sequence of letters (a word) Examples: cat, dog, house, Defined over

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

### Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

Regular Languages MACM 3 Formal Languages and Automata Anoop Sarkar http://www.cs.sfu.ca/~anoop The set of regular languages: each element is a regular language Each regular language is an example of a

### JNTUWORLD. Code No: R

Code No: R09220504 R09 SET-1 B.Tech II Year - II Semester Examinations, April-May, 2012 FORMAL LANGUAGES AND AUTOMATA THEORY (Computer Science and Engineering) Time: 3 hours Max. Marks: 75 Answer any five

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

### Finite Automata Part Three

Finite Automata Part Three Recap from Last Time A language L is called a regular language if there exists a DFA D such that L( D) = L. NFAs An NFA is a Nondeterministic Finite Automaton Can have missing

### Compiler Construction

Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Conceptual Structure of a Compiler Source code x1 := y2

### Regular Languages and Regular Expressions

Regular Languages and Regular Expressions According to our definition, a language is regular if there exists a finite state automaton that accepts it. Therefore every regular language can be described

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

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

### The Front End. The purpose of the front end is to deal with the input language. Perform a membership test: code source language?

The Front End Source code Front End IR Back End Machine code Errors The purpose of the front end is to deal with the input language Perform a membership test: code source language? Is the program well-formed

### MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Massachusetts Institute of Technology Language Definition Problem How to precisely define language Layered structure

### MIT Specifying Languages with Regular Expressions and Context-Free Grammars

MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Language Definition Problem How to precisely

### Non-deterministic Finite Automata (NFA)

Non-deterministic Finite Automata (NFA) CAN have transitions on the same input to different states Can include a ε or λ transition (i.e. move to new state without reading input) Often easier to design

### MA/CSSE 474. Today's Agenda

MA/CSSE 474 Theory of Computation Course Intro Today's Agenda Student questions Overview of yesterday's proof I placed online a "straight-line" writeup of the proof in detail, without the "here is how

### Compilers CS S-01 Compiler Basics & Lexical Analysis

Compilers CS414-2017S-01 Compiler Basics & Lexical Analysis David Galles Department of Computer Science University of San Francisco 01-0: Syllabus Office Hours Course Text Prerequisites Test Dates & Testing

### Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

Code No: XXXXX JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY, HYDERABAD B.Tech II Year I Semester Examinations (Common to CSE and IT) Note: This question paper contains two parts A and B. Part A is compulsory

### Recursively Defined Functions

Section 5.3 Recursively Defined Functions Definition: A recursive or inductive definition of a function consists of two steps. BASIS STEP: Specify the value of the function at zero. RECURSIVE STEP: Give

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

### Finite Automata Part Three

Finite Automata Part Three Recap from Last Time A language L is called a regular language if there exists a DFA D such that L( D) = L. NFAs An NFA is a Nondeterministic Finite Automaton Can have missing

### 8 ε. Figure 1: An NFA-ǫ

0 1 2 3 4 a 6 5 7 8 9 10 LECTURE 27 Figure 1: An FA-ǫ 12.1 ǫ Transitions In all automata that we have seen so far, every time that it has to change from one state to another, it must use one input symol.

### Homework. Context Free Languages. Before We Start. Announcements. Plan for today. Languages. Any questions? Recall. 1st half. 2nd half.

Homework Context Free Languages Homework #2 returned Homework #3 due today Homework #4 Pg 133 -- Exercise 1 (use structural induction) Pg 133 -- Exercise 3 Pg 134 -- Exercise 8b,c,d Pg 135 -- Exercise

### Languages and Compilers

Principles of Software Engineering and Operational Systems Languages and Compilers SDAGE: Level I 2012-13 3. Formal Languages, Grammars and Automata Dr Valery Adzhiev vadzhiev@bournemouth.ac.uk Office:

### Compilers CS S-01 Compiler Basics & Lexical Analysis

Compilers CS414-2005S-01 Compiler Basics & Lexical Analysis David Galles Department of Computer Science University of San Francisco 01-0: Syllabus Office Hours Course Text Prerequisites Test Dates & Testing

### UNIT I PART A PART B

OXFORD ENGINEERING COLLEGE (NAAC ACCREDITED WITH B GRADE) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS YEAR/SEM: III/V STAFF NAME: Dr. Sangeetha Senthilkumar SUB.CODE: CS6503 SUB.NAME:

### Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

Chapter Seven: Regular Expressions Formal Language, chapter 7, slide The first time a young student sees the mathematical constant π, it looks like just one more school artifact: one more arbitrary symbol

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

### Structure of Programming Languages Lecture 3

Structure of Programming Languages Lecture 3 CSCI 6636 4536 Spring 2017 CSCI 6636 4536 Lecture 3... 1/25 Spring 2017 1 / 25 Outline 1 Finite Languages Deterministic Finite State Machines Lexical Analysis

### AUBER (Models of Computation, Languages and Automata) EXERCISES

AUBER (Models of Computation, Languages and Automata) EXERCISES Xavier Vera, 2002 Languages and alphabets 1.1 Let be an alphabet, and λ the empty string over. (i) Is λ in? (ii) Is it true that λλλ=λ? Is

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

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

### CS402 - Theory of Automata FAQs By

CS402 - Theory of Automata FAQs By Define the main formula of Regular expressions? Define the back ground of regular expression? Regular expressions are a notation that you can think of similar to a programming

### CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2] 1 What is Lexical Analysis? First step of a compiler. Reads/scans/identify the characters in the program and groups

### Compiler Construction

Compiler Construction Lecture 2: Lexical Analysis I (Introduction) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ss-14/cc14/

### 2. Lexical Analysis! Prof. O. Nierstrasz!

2. Lexical Analysis! Prof. O. 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/!

### Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 11 Ana Bove April 26th 2018 Recap: Regular Languages Decision properties of RL: Is it empty? Does it contain this word? Contains

### Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont.

Announcements CS43: Discrete Structures Strong Induction and Recursively Defined Structures Işıl Dillig Homework 4 is due today Homework 5 is out today Covers induction (last lecture, this lecture, and

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

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

### Learn Smart and Grow with world

Learn Smart and Grow with world All Department Smart Study Materials Available Smartkalvi.com TABLE OF CONTENTS S.No DATE TOPIC PAGE NO. UNIT-I FINITE AUTOMATA 1 Introduction 1 2 Basic Mathematical Notation

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

### Caveat lector: This is the first edition of this lecture note. Please send bug reports and suggestions to

Caveat lector: This is the first edition of this lecture note. Please send bug reports and suggestions to jeffe@illinois.edu. But the Lord came down to see the city and the tower the people were building.

### Today. Assignments. Lecture Notes CPSC 326 (Spring 2019) Quiz 2. Lexer design. Syntax Analysis: Context-Free Grammars. HW2 (out, due Tues)

Today Quiz 2 Lexer design Syntax Analysis: Context-Free Grammars Assignments HW2 (out, due Tues) S. Bowers 1 of 15 Implementing a Lexer for MyPL (HW 2) Similar in spirit to HW 1 We ll create three classes:

Oxford University Press 2013 Slides for Faculty Assistance Preliminaries Author: Vivek Kulkarni vivek_kulkarni@yahoo.com Outline Following topics are covered in the slides: Basic concepts, namely, symbols,