Question

In: Computer Science

Now that you know a bit about BNF's, try writing a grammar (productions) for the "language"...

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.

Solutions

Expert Solution

Grammar for the language of a phone number:

S -> (N)N-M

N -> DZZ

M -> ZZZZ

Z -> 0|D

D -> 1|2|3|4|5|6|7|8|9

where S, N, M, D, Z are non-terminals. and (,),-,0,1,2,3,4,5,6,7,8,9 are terminals and S is the start symbol.

S is the phone number, N is the 3 digit number not begin with 0, M is 4 digit number and Z corresponds digits including 0 and D corresponds digits excluding 0.

The derivation of correct phone number using parse tree method:

(757)530-4601

using sequence substitution method (top down method):

S

=> (N)N-M    // rule 1

=> (DZZ)DZZ-ZZZZ // rule 2 and 3

=> (7DD)5D0-DD0D // rule 3 and 4

=> (757)530-4601 // rule 4

Now test for an incorrect phone number:

(019)555-5555

In case of incorrect phone number the derivation can't go further because while expanding N the first non-terminal is D which corresponds to digit but not zero. where in phone number left N begins with 0(zero). Here there is no rule we can apply.

Hence derivation should be terminated with error.


Related Solutions

Now that we know a bit more about epidemiologic curves and the important steps in an...
Now that we know a bit more about epidemiologic curves and the important steps in an outbreak investigation, let's see how this is playing out with COVID-19. 1. You've probably heard public health officials say that we need to "flatten the curve". What does this statement mean and why is it so important? 2. Discuss one method public health officials have implemented to flatten the COVID-19 curve. Do you think this method is effective? Explain. 3. Will the nation-wide Black...
Now that you know the personality of your brand a bit better, in one paragraph, describe...
Now that you know the personality of your brand a bit better, in one paragraph, describe your fast causal restaurant brand and how it is different than other brands of fast casual restaurant brands in Burnaby, B.C. The idea here is to show how you have differentiated your brand from existing brands.
Activity 2. Now that you know the essential terms in climate and biodiversity, let us try...
Activity 2. Now that you know the essential terms in climate and biodiversity, let us try to check your understanding of these terms. In the space provided, differentiate the following: 1.   Deciduous forest from evergreen forest. 2.   Woodland from shrubland 3. Tropical rainforest from tropical seasonal forest 4. Savanna from thornwood 5. Weather and climate
Think about Psychology and what you know about the field/study to date. Try to think of...
Think about Psychology and what you know about the field/study to date. Try to think of two or more ways that Psychology might be used to investigate a problem (whether it is something an individual is facing or something in a larger group/society). Describe the problem and at least two ways that Psychology might be used to investigate it.
What you know about writing for different audiences? How does your audience affect your writing? What...
What you know about writing for different audiences? How does your audience affect your writing? What should you consider when putting your text together? Write a 300 words essay.
Try to locate an online article about marketing and writing a short synopsis of the article,...
Try to locate an online article about marketing and writing a short synopsis of the article, why it pertains to our studies, and how you think it impacts business. Be sure to cite your source.
A question about exceptions, the language is JAVA. The purpose is writing a program that reads...
A question about exceptions, the language is JAVA. The purpose is writing a program that reads a string from the keyboard and tests whether it contains a valid time. Display the time as described below if it is valid, otherwise display a message as described below. The input date should have the format hh:mm:ss (where hh = hour, mm = minutes and ss = seconds in a 24 hour clock , for example 23:47:55). Here are the input errors (Exceptions)...
Is my writing for this email correct? I mean academy and grammar. (you can edit and...
Is my writing for this email correct? I mean academy and grammar. (you can edit and add any sentence) Dear sir/madam, UK Visas and Immigration I hope you are doing well. I am working hard to provide evidence from The University of Sydney confirming my new admission dates commencing within 3 months according to your e-mail request on October 2, 2020. Noting that my Visa Application( GWF0565848 ) was to get an alternate visa with new entry dates because I...
Is my writing for this email correct? I mean academy and grammar. (you can edit and...
Is my writing for this email correct? I mean academy and grammar. (you can edit and add any sentence) Dear Prof. Joseph, I hope you are doing well. As you know that the circumstances of the Corona pandemic caused the borders to close and the suspension of international flights, which led to my delay in coming to my mission headquarters in Britain, in addition to that the University of Manchester has been largely closed to students since March 2020. I...
Is my writing for this email correct? I mean academy and grammar. (you can edit and...
Is my writing for this email correct? I mean academy and grammar. (you can edit and add any sentence) I hope you will help me in drafting this e-mail Dear Prof. Joseph. I hope you are doing well. As you know, I received an email from the decision-making center stating that it is necessary to update the Academic Technology Approval Scheme (ATAS) certificate which ended on July 15,2020. Consequently, I have applied for the ATAS online to UKVI on October...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT