100% found this document useful (1 vote)
548 views3 pages

Lexical Analysis: (Section 3.3)

This document contains exercises on lexical analysis from a compiler design course. It includes regular expressions to describe languages and questions about prefixes, suffixes, substrings, and subsequences. It also provides regular definitions for languages containing vowels in order, letters in ascending order, comments, and strings of a's and b's with certain patterns of the letters.

Uploaded by

Qualtz Andrew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
548 views3 pages

Lexical Analysis: (Section 3.3)

This document contains exercises on lexical analysis from a compiler design course. It includes regular expressions to describe languages and questions about prefixes, suffixes, substrings, and subsequences. It also provides regular definitions for languages containing vowels in order, letters in ascending order, comments, and strings of a's and b's with certain patterns of the letters.

Uploaded by

Qualtz Andrew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Islamic University – Gaza

Engineering Faculty
Department of Computer Engineering
ECOM 5060: Compiler Design Discussion

Chapter 3
Lexical Analysis
(Section 3.3)

Eng. Eman R. Habib

March, 2014
2 Computer Architecture Discussion

Exercises 3.3.2: Describe the language denoted by the following regular


expressions:

a) a(a|b)*a
All strings of a’s and b’s begin and end with a.

b) ((|a)b*)*
All strings of a’s and b’s.

c) (a|b)*a(a|b)(a|b)
All strings of a’s and b’s, with an a in the 3rd letter from the right.

d) a*ba*ba*ba*
All strings of a’s, with just three b’s.

e) (00|11)*((01|10)(00|11)*(01|10)(00|11)*)*
All strings of even number of 0’s and even number of 1’s

Exercises 3.3.3: In a string of length n, how many of the following are there?
a) Prefixes
n+1

b) Suffixes
n+1

c) Proper prefixes
n-1

d) Substrings

e) Subsequences
n
2

Exercises 3.3.4:
(S|s)(E|e)(L|l)(E|e)(C|c)(T|t)
3 Computer Architecture Discussion

Exercises 3.3.5: Write regular definitions for the following languages.

a) All strings of lowercase letters that contain the five vowels (a, e, i, o, or u) in order.
Letter  [b-d f-h j-n p-t v-z]
String  (Letter|a)* (Letter|e)* (Letter|i)* (Letter|o)* (Letter|u)*

b) All strings of lowercase letters in which the letters in are in ascending lexicographic
order.
String  a*b*c*d*…………z*

c) Comments, consisting of a string surrounded by /* and */, without an intervening */,


unless it is inside double-qoutes(“)
Character  [a-zA-Z0-9]
Comment  /* (Character|“*/”|(*|/) Character)* */

h) All strings of a’s and b’s that do not contain the substring abb.
b* (a (|b))*

i) All strings of a’s and b’s that do not contain the subsequence abb.
b* a*(|b) a*

Extra Exercises: Write regular definitions for the following languages.


a) All strings of a’s and b’s with an even number of a’s.
b*(a b* a b*)*

b) All strings of a’s and b’s with and odd number of b’s.
a* b (a* b a* b)* a*

c) All strings of a’s and b’s that contain at least two b's.
(a|b)* b (a|b)* b (a|b)*

d) All strings of a’s and b’s that contain at most two b's.
a* (|b) a* (|b) a*

e) All strings of a’s and b’s that contain just two or three b`s
a* b a* b a* b? a*

 Best Wishes 

You might also like