lecture19-cfgs.pdf - CSE 311 Foundations of Computing Lecture 19 Regular Expressions Context-Free Grammars[Audience looks around “What is going on

lecture19-cfgs.pdf - CSE 311 Foundations of Computing...

This preview shows page 1 - 9 out of 34 pages.

CSE 311: Foundations of Computing Lecture 19: Regular Expressions & Context-Free Grammars [Audience looks around] “What is going on? There must be some context we’re missing”
Image of page 1

Subscribe to view the full document.

Review: each regular expression is a “pattern” e matches the empty string a matches the one character string a A È B matches all strings that either A matches or B matches (or both) AB matches all strings that have a first part that A matches followed by a second part that B matches A* matches all strings that have any number of strings (even 0) that A matches, one after another
Image of page 2
Examples All binary strings that have an even # of 1’s
Image of page 3

Subscribe to view the full document.

Examples All binary strings that have an even # of 1’s e.g., 0*(10*10*)*
Image of page 4
Examples All binary strings that have an even # of 1’s All binary strings that don’t contain 101 e.g., 0*(10*10*)*
Image of page 5

Subscribe to view the full document.

Examples All binary strings that have an even # of 1’s All binary strings that don’t contain 101 e.g., 0*(10*10*)* e.g., 0*(1 000*)* 0*
Image of page 6
Limitations of Regular Expressions Not all languages can be specified by regular expressions Even some easy things like Palindromes Strings with equal number of 0’s and 1’s But also more complicated structures in programming languages Matched parentheses Properly formed arithmetic expressions etc.
Image of page 7

Subscribe to view the full document.

Context-Free Grammars A Context-Free Grammar (CFG) is given by a finite set of substitution rules involving A finite set V of variables that can be replaced Alphabet S of terminal symbols that can’t be replaced One variable, usually S , is called the start symbol The rules involving a variable A are written as A ® w 1 | w 2 | | w k where each w i is a string of variables and terminals – that is w i ( V È S ) *
Image of page 8
Image of page 9
  • Spring '16

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes