1 / 13

COP 3402 System Software

COP 3402 System Software. Recitation Notes 21 st September 2007. Limits Of Regular Expressions. Regular expressions are very useful for recognizing patterns However, there are some patterns they cannot handle. An Example is strings of the form a n b n. Context Free Languages.

mizell
Download Presentation

COP 3402 System Software

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP 3402 System Software Recitation Notes 21st September 2007

  2. Limits Of Regular Expressions • Regular expressions are very useful for recognizing patterns • However, there are some patterns they cannot handle. • An Example is strings of the form anbn

  3. Context Free Languages • Since regular expressions cannot handle some important patterns, we need a more powerful method of describing patterns. • Context Free Languages are one such mechanism • Proposed by Noam Chomsky in the 1950s.

  4. BNF • BNF is a way to express Context free languages. • First used in ALGOL 58. • BNF stands for Backus-Naur Form • Named after two members of the ALGOL design team.

  5. BNF Example for PL/0 • Next slide contains a BNF description that can verify the correctness of any PL/0 program. • Conventions: • Variables/Tokens are written between “<“ and ”>”. • The “→” symbol can be read as “is defined as”. • “ε “ is the empty string.

  6. BNF Grammer for PL/0

  7. Sample PL/0 Programme • const m = 7, n = 85; • var i,x,y,z,q,r; • procedure mult; • var a, b; • begin • a := x; b := y; z := 0; • while b > 0 do • begin • if odd x then z := z+a; • a := 2*a; • b := b/2; • end • end; • begin • x := m; • y := n; • call mult; • end.

  8. Syntax Graphs Visual Way to represent BNF Grammars

  9. Syntax Graphs Cont’d

  10. Extended BNF • Conventions • Optional Constructions are enclosed in square braces ‘[‘ and ‘]’. • Constructs enclosed in curly braces ‘{‘ and ‘}’ are repeated zero or more times. • Example on next slide

  11. EBNF Example for PL/0

  12. Another Example • Try to write a BNF Grammar that validates strings of the type anbn. • Hint: anbn can be rewritten as aan-1bn-1b.

  13. Solution • <string> → a<string>b | ε • Will ensure that • string always has the same number of a’s and b’s • The a’s always come before the b’s in the string. • As to keeping track of the ‘n’, we don’t care in this example because the number of a’s and b’s will always be matched.s

More Related