Question

I am having issues with a Backus Naur assignment I want to define rules that allow...

I am having issues with a Backus Naur assignment

I want to define rules that allow for an integer named x to have one of the following:

0-F followed by “h” to define a hex value,

0-1 to define a binary value, or

0-9 followed by a “d” to define a decimal value.

For example, int x = 3d would be a legal statement

On the other hand, int x= 4b would not be legal (binary numbers can only be 0 r 1

I would like to know how to go about doing that.

Homework Answers

Answer #1

Check out the algorithm for solving the problem.

  1. Convert the given integer to a string.
  2. Check for the last character in the string.
    1. If last character is 'h', iterate the string and check for all characters whether they are from 0-F or not. If not, return invalid, else valid.
    2. If last character is 'd', iterate the string and check for all characters whether they are from 0-9 or not. If not, return invalid, else valid.
    3. If last character is neither 'h' nor 'd', iterate the string and check whether all the characters are either '0' or '1'. If not, return invalid, else valid.
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA a. An integer is a "Lucky Number" if it is divisible by 7 or is...
JAVA a. An integer is a "Lucky Number" if it is divisible by 7 or is divisible by 11 and it is in the range 1000 through 4000. Write a Boolean expression that is true if and only if myNum (an int variable) contains a Lucky Number. b. Let a and b represent the length and the width of a rectangle. The length of the diagonal of the rectangle can be calculated by the following mathematical expression. diagonalLength = squareRoot(a...
I am having some trouble visualizing this present value question and have already put it on...
I am having some trouble visualizing this present value question and have already put it on a timeline, but it's still not clear. I think I may be making it more complex than it really is, but here is the question and then I will explain why I am having problems. At an annual interest rate of 6%, which would you prefer - three annual year-end cash flows of $250 each with the first cash flow one year from today...
can you please work on this assignment because I am having some issues with it. I...
can you please work on this assignment because I am having some issues with it. I have it completed I would just like to know if everything is correct.   DISCRETE PROBABILITY DISTRIBUTIONS (3 points) The number of hits on a certain website follows a Poisson distribution with a mean rate of 4 per minute. What is the probability that 5 messages are received in a given minute? 0.1563 What is the probability that 9 messages are received in 1.5 minutes?...
I am working on an accounting assignment and am having problems. Firstly, 1.I need to journalize...
I am working on an accounting assignment and am having problems. Firstly, 1.I need to journalize these entries and post the closing entries 2. i need to prepare Dalhanis multi-step income statement and statement of owners equity for August 2010 3. i need to prepare the blance sheet at august 31,2010 4. i need to prepare a post-closing trial balance at august 31,2010 DALHANI makes all credit sales on terms 2/10 n/30 and uses the Perpetual Inventory System Aug 1...
I am having trouble deciding what is true for these questions. I thought I had the...
I am having trouble deciding what is true for these questions. I thought I had the right answers but they keep getting marked wrong. For Question 1, I chose option 2, as I though all the others to be false. For Question 4 I chose option 4, as I learned that the z-scores of the mean and standard deviation were always 0 and 1, respectively. For question 5 I chose option 4 as well. Which one of the following statements...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
I am making a game like Rock Paper Scissors called fire water stick where the rules...
I am making a game like Rock Paper Scissors called fire water stick where the rules are Stick beats Water by floating on top of it Water beats Fire by putting it out Fire beats Stick by burning it The TODOS are as follows: TODO 1: Declare the instance variables of the class. Instance variables are private variables that keep the state of the game. The recommended instance variables are: 1. 2. 3. 4. 5. 6. A variable, “rand” that...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list code and can't figure out how to complete it: Below is the code Complete the three empty methods (remove(), find(), and contains()) in the ShoppingListArrayList.java file. These methods are already implemented in the ShoppingListArray class. /////////////////////////////////////////////////////////////////////////////////////////////////////////// Grocery Class (If this helps) package Shopping; public class Grocery implements Comparable<Grocery> { private String name; private String category; private int aisle; private float price; private int quantity;...
The decimal values of the Roman numerals are: M D C L X V I 1000...
The decimal values of the Roman numerals are: M D C L X V I 1000 500 100 50 10 5 1 Remember, a larger numeral preceding a smaller numeral means addition, so LX is 60. A smaller numeral preceding a larger numeral means subtraction, so XL is 40. Assignment: Begin by creating a new project in the IDE of your choice. Your project should contain the following: Write a class romanType. An object of romanType should have the following...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing associated with the assignment it is failing one part of testing.   Below is the test that fails: Failed test 4: differences in output arguments: -c input data: a b c -c expected stdout: b observed stdout: a b expected stderr: observed stderr: ./test: invalid option -- 'c' Unsure where I have gone wrong. MUST BE WRITTEN IN C++ Task Level 1: Basic operation Complete...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT