Docsity

Regular Expressions in Compiler Design: A Comprehensive Guide, Schemes and Mind Maps of Computer science

Partial preview of the text

Download Regular Expressions in Compiler Design: A Comprehensive Guide and more Schemes and Mind Maps Computer science in PDF only on Docsity!

Regular Expression

Course Name: Compiler Design Course Code: CSE Level:3, Term: Department of Computer Science and Engineering Daffodil International University

A Regular expression (sometimes called a rational expression) is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. “find and replace”-like operations.

Regular expression is a notation for defining the set of tokens that

normally occur in programming languages.

Regular Expression

  • Letters or alphabets and digits are the most important elements of language.
  • Let L be the set of alphabets {A, B,…Z, a, b,….z} and D be the set of digits { 0 , 1 , …., 9 }
  • L could be in form of upper case and lower case.
  • Examples: L U D is the set of letters and digits. LD is the set of strings consisting of a letter followed by a digit.
  • LLLL = L 4 is the set of all four-letter strings.

Operations of Language

• L

is the set of all strings of letters, including ε, the empty string

  • L(L U D)
    • is the set of all strings of letters and digits beginning with a letter.
  • D
    • is the set of all strings of one or more digits.

Operations of Language

  • (a|b)
    • or (a * |b * ) *
  • Denotes the set of all strings containing zero or more instances of an a or b, that is, the set of all strings of a’s and b’s.
  • a | a
    • b
  • Denotes the set containing the string a and all strings consisting of zero or more a’s followed by a b

Examples

Examples:

  • “Set of all strings having at least one ab”  (ab)
  • “Set of all strings having even number of aa”  (aa)
  • “Set of all strings having odd number of bb”  b(bb)
  • “Set of all strings having even number of aa and even number of bb”  (aa)
    • (bb) * Language to Regular Expressions

THANK YOU