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.

I would like a visual representation of it.

Like how it would look like in BNF grammer.

Homework Answers

Answer #1

You can write the BNF grammar as:

<int> ::= <bin> | <hex> h | <dec> d

<bin> ::= <bindigit> | <bin> <bindigit>

<bindigit> ::= 0 | 1

<hex> ::= <hexdigit> | <hex> <hexdigit>

<dec> ::= <decdigit> | <dec> <decdigit>

<hexdigit> ::= 0|1|2|3|4|5|6|7|8|9|A| B|C|D|E|F

<decdigit> ::= 0|1|2|3|4|5|6|7|8|9

Here, the integer can be a binary number or a hexadecimal followed by h or a decimal value followed by d.

Now a binary number can be a single binary digit or multiple digits (bin followed by bindigit) where a binary digit can be either a 0 or a 1.

Same for hexadecimal and decimal numbers.

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
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...
I am creating a towers of hanoi game board using c#, and am having trouble understanding...
I am creating a towers of hanoi game board using c#, and am having trouble understanding my instructors instructions. So far I have an outline setup as follows: using System; namespace Towers { public class Towers { int numberOfDiscs; //Number of discs to be place on the leftmost pole (between 1 and 9) int numberOfMoves; //Number of moves executed thus far bool isComplete; //True if all discs have been succesfully moved to the righmost pole int minimumPossibleMoves; public Towers(int numberOfDiscs)...
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...
I am to create three different versions of the following C program code below that implements...
I am to create three different versions of the following C program code below that implements the conversion of unsigned binary numbers into decimal (Base 2 to Base 10 conversion). Version 1: Complete the C program ”bin2dec ver1.c” that implements binary to decimal conversion. The maximum number of binary bits is 32. The program is made of the functions ”unsigned binary to decimal(const char *str)”and ”main”. The parameter ”str” passed to this function points to a C string comprising only...
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?...
Currently stuck on this part of a project. I am struggling with creating the String for...
Currently stuck on this part of a project. I am struggling with creating the String for creating the dice values in the boxes for the "showDice" string. I have already completed the first part which was creating the class for the Die. This is Javascript. For this part, we will create the class that allows you to roll and score the dice used in a game of Yahtzee. This will be the longest part of the project, so I suggest...
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...
For this assignment you will implement a simple calculator or interpreter that reads arithmetic expressions from...
For this assignment you will implement a simple calculator or interpreter that reads arithmetic expressions from a file. Specifically, you will implement the following function: /* * Reads one arithmetic "expression" at a time from a file stream, computes, then * returns the result. If there are additional expressions in the file, they are * read and computed by successive calls to “calculator”. * * “Expressions” are groups of operations (add, subtract, multiply, divide). Your * calculator will read and...
import java.util.ArrayList; /* Rules:         1. Allow Tester to iterate through all nodes using the...
import java.util.ArrayList; /* Rules:         1. Allow Tester to iterate through all nodes using the in-order traversal as the default.             This means, in Tester the following code should work for an instance of this class             called bst that is storing Student objects for the data:                 BinarySearchTree_Lab08<String> bst = new BinarySearchTree_Lab08<String>();                 bst.add("Man");       bst.add("Soda");   bst.add("Flag");                 bst.add("Home");   bst.add("Today");   bst.add("Jack");                ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT