Homework - PowerPoint PPT Presentation

About This Presentation
Title:

Homework

Description:

... number of 0's and 1's Also b) construct a parse tree and c) leftmost derivation of 0011. ... { e, x, z, xz, xx, zz, zx, xzz, xzx. zzx, xzzx }, a finite language ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 9
Provided by: Kal127
Learn more at: http://web.cs.wpi.edu
Category:

less

Transcript and Presenter's Notes

Title: Homework


1
Homework 5 Solutions
2
1. True or False
  • a) Regular Languages are always Context-Free
    Languages

  • True
    False
  • b) Context Free Languages are always Regular
    Languages

  • True
    False
  • c) The grammar S? 0S 0S1S e is ambiguous
  • d) The language anbncn is regular
  • e) The language anbncn is context-free

True False
True False
True False
3
2. Minimize the following dfa
(1) Dividing into Final and Non-Final States
Partition I ? Partition 2 ?
4
2 cont.
  • (2) In Partition 1, all states do the same
    thing on an a. But on a b, states 1 and 6 both
    go to Partition II. Well move them to their own
    partition

(3) We cannot partition further
L(M) (ababa)
5
3. a) Create a grammar that generates the set of
all strings over 0,1 with an equal number of
0s and 1s Also b) construct a parse tree and
c) leftmost derivation of 0011. d) Is your
grammar ambiguous? Why or why not?
  • S-gt 0 S 1, S ? 1 S 0, S ? S S, S? e
  • b)
  • c) Yes. There is more than 1 parse tree for e as
    well as for other strings.

S?0 S 1 ? 0 0 S 1 1 ? 0 0 1 1
6
4. Find the Start symbol for the Java grammar
shown at http//www.cse.psu.edu/saraswat/cg428/
lecture_notes/LJava2.html
  • The start symbol is CompilationUnit.
  • It doesnt appear on the left-hand-side.
  • It is good technique to write a programming
  • language grammar so that the Start symbol
  • does not occur on the right-hand-side, and
  • all grammars can be changed to an
  • equivalent grammar having this property
  • (how?)

7
5. For the grammar G
S ? X Z Z X X ? x X ? e Z ? z Z ? ea)
What is L(G)?
  • e, x, z, xz, xx, zz, zx, xzz, xzx. zzx, xzzx ,
    a finite language
  • b) Proof Let X e, x, z, xz, xx, zz, zx,
    xzz, xzx. zzx, xzzx .
  • To show X L(G) requires 2 proof parts
  • if w e X, then w e L(G)
  • if w e L(G), then w e X
  • 1. Given w e X
  • Prove w e L(G)

  • To show w e L(G) means we have to show S ? w
  • Since the language is finite, we can show this
    for each string
  • w e
  • S?XZZX?eZZX?eeZX?eeeX?eeee e Similarly for
    the other elements of L.

8
5 cont
  • 2. if w e L(G), then w e X
  • Derivations of strings of length 0 in L(G)
  • S?XZZX?eZZX?eeZX?eeeX?eeee e
  • and e is in X
  • Derivations of strings of length 1 in L(G)
  • S?XZZX?xZZX?xeZX?xeeX?xeeex (can be derived
    another way also)
  • And x is in X
  • S?XZZX?eZZX?ezZX?ezeX?ezeez (can be derived
    another
  • way also
  • And z is in X
  • No other derivations result in strings of length
    1
  • Similarly for derivations of strings of length 3
    and 4
Write a Comment
User Comments (0)
About PowerShow.com