prac3-soln-fall09

prac3-soln-fall09 - CMSC 330, Fall 2009, Practice Problem 3...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMSC 330, Fall 2009, Practice Problem 3 Solutions 1. Context Free Grammars a. List the 4 components of a context free grammar. Terminals, non-terminals, productions, start symbol b. Describe the relationship between terminals, non-terminals, and productions. Productions are rules for replacing a single non-terminal with a string of terminals and non-terminals c. Define ambiguity. Multiple left-most (or right-most) derivations for the same string d. Describe the difference between scanning & parsing. Scanning matches input to regular expressions to produce terminals, parsing matches terminals to grammars to create parse trees 2. Describing Grammars a. Describe the language accepted by the following grammar: S & abS | a (ab)*a b. Describe the language accepted by the following grammar: S & aSb | a n b n , n & 0 c. Describe the language accepted by the following grammar: S & bSb | A A & aA | b n a * b n , n & 0 d. Describe the language accepted by the following grammar: S & AS | B A & aAc | Aa | B & bBb | Strings of a & c with same or fewer cs than as and no prefix has more cs than as, followed by an even number of bs e. Describe the language accepted by the following grammar: S & S and S | S or S | (S) | true | false Boolean expressions of true & false separated by and & or, with some expressions enclosed in parentheses f. Which of the previous grammars are left recursive? 2d, 2e g. Which of the previous grammars are right recursive? 2a, 2c, 2d, 2e h. Which of the previous grammars are ambiguous? Provide proof. Examples of multiple left-most derivations for the same string 2d: S => AS => AaS => aS => aB => a S => AS => S => AS => AaS => aS => aB => a 2e: S => S and S => S and S and S => true and S and S => true and true and S => true and true and true S => S and S => true and S => true and S and S => true and true and S => true and true and true 3. Creating Grammars a. Write a grammar for a x b y , where x = y S & aSb | b. Write a grammar for a x b y , where x > y S & aL L & aL | aLb | c. Write a grammar for a x b y , where x = 2y S & aaSb | d. Write a grammar for a x b y a z , where z = x+y S & aSa | L L & bLa | e. Write a grammar for a x b y a z , where z = x-y S & aSa | L L & aLb |...
View Full Document

Page1 / 6

prac3-soln-fall09 - CMSC 330, Fall 2009, Practice Problem 3...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online