1. Engineering
  2. Computer Science
  3. now that you know a bit about bnfs try writing...

Question: now that you know a bit about bnfs try writing...

Question details

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

  • three digits enclosed in parentheses - the first digit cannot be "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 following numbers are invalidaccording to this grammar:

  • 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 phone number - give both the sequence of substitutions and the parse tree representation
  • the attempted derivation of one incorrect phone number - list the sequence of substitutions OR draw the parse tree until the derivation "breaks." Write a note explaining why the derivation can go no further.
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution