Question: Now that you know a bit about BNF's, try writing a grammar(productions) for the language of a phonenumber , which consists of: three digits enclosed

Now that you know a bit about BNF's, try writing a grammar(productions) for the "language" of a phonenumber, which consists of:

  • three digits enclosed in parentheses - the first digit cannotbe "0" (zero)
  • followed by three digits - the first digit cannot be "0"(zero)
  • followed by a "-" (dash)
  • followed by four digits

So, (757)530-4601 is a valid phone number. All the followingnumbers are invalidaccording to thisgrammar:

  • 757-530-4601 (area code is not in parentheses)
  • (757)530.4601 (missing dash after the exchange)
  • (919)-555-5555 (stray dash after area code)
  • (019)555-5555 (area code cannot start with zero)
  • and so on

Once you have a grammar, write down:

  • the derivation of one correct phonenumber - give both the sequence of substitutions and the parse treerepresentation
  • the attempted derivationof one incorrect phone number - list thesequence of substitutions OR draw the parse tree until thederivation "breaks." Write a note explaining why the derivation cango no further.

Step by Step Solution

3.38 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Grammar for the phonenumber language phonenumber digit digit digit digit digit digit digit di... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!