Question

In: Computer Science

Write EBNF descriptions for the following: • a Java For each statement Assume that EBNF descriptions...

Write EBNF descriptions for the following:

• a Java For each statement

Assume that EBNF descriptions for statement(s), type, array, white space are given. (statmnts, type, array, and whitespace respectively)

You have to create EBNF descriptions for For each statement and also variable.

Use the following Java variable naming rules to create EBNF description for variable.

o All variable names must begin with a letter of the alphabet, an underscore ( _ ) , or a dollar sign ( $ ).

o After the first initial letter, variable names may also contain letters and the digits 0 to 9. No spaces or special characters are allowed.

Assume that EBNF description for alphabet (including both upper and lower cases) and digits (0 – 9) are given. (alphabet and digit respectively)

Solutions

Expert Solution

EBNF:-

<statements> -> statmnts; | <for> | statmnts;<statements>

<for> -> for '(' <type> <variable> ':' <array> ')' '{' <statements> '}'

<variable> -> ('_' | '$' | <alpha>)<var>

<var> -> ('' | '$' | <alpha> | <num>)<var> | '' | '$' | <alpha> | <num>|epsilon

<type> -> type

<array> -> array

<alpha> -> alphabet

<num> -> digit

let example:-

for(type alphabet : array){

statmnts;

}

<statements> -> <for>

-> for '(' <type> <variable> ':' <array> ')' '{' <statements> '}'

-> for '(' type <variable> ':' <array> ')' '{' <statements> '}'

->for '(' type <alpha><var> ':' <array> ')' '{' <statements> '}'

->for '(' type alphabet<var> ':' <array> ')' '{' <statements> '}'

->for '(' type alphabet ':' <array> ')' '{' <statements> '}'

->for '(' type alphabet ':' array ')' '{' <statements> '}'

->for '(' type alphabet ':' array ')' '{' statmnts; '}'

one more example:-

for(type alphabet : array){

for(type _alphabet : array){

statmnts;

statmnts;

}

}

<statements> -> <for>

-> for '(' <type> <variable> ':' <array> ')' '{' <statements> '}'

-> for '(' type <variable> ':' <array> ')' '{' <statements> '}'

->for '(' type <alpha><var> ':' <array> ')' '{' <statements> '}'

->for '(' type alphabet<var> ':' <array> ')' '{' <statements> '}'

->for '(' type alphabet ':' <array> ')' '{' <statements> '}'

->for '(' type alphabet ':' array ')' '{' <statements> '}'

->for '(' type alphabet ':' array ')' '{' <for> '}'

->for '(' type alphabet ':' array ')' '{' for '(' <type> <variable> ':' <array> ')' '{' <statements> '}' '}'

->for '(' type alphabet ':' array ')' '{' for '(' type <variable> ':' <array> ')' '{' <statements> '}' '}'

->for '(' type alphabet ':' array ')' '{' for '(' type _<alpha> ':' <array> ')' '{' <statements> '}' '}'

->for '(' type alphabet ':' array ')' '{' for '(' type _alphabet ':' <array> ')' '{' <statements> '}' '}'

->for '(' type alphabet ':' array ')' '{' for '(' type _alphabet ':' array ')' '{' <statements> '}' '}'

->for '(' type alphabet ':' array ')' '{' for '(' type _alphabet ':' array ')' '{' statmnts;<statements> '}' '}'

->for '(' type alphabet ':' array ')' '{' for '(' type _alphabet ':' array ')' '{' statmnts; statmnts; '}' '}'


Related Solutions

Very easy: Write an EBNF rule that describes the following for statement in Java for (...
Very easy: Write an EBNF rule that describes the following for statement in Java for ( counter = 1; counter <= 10; counter ++) { sum=sum+1; } Then test your EBNF rule in Java as a recursive-descent subprogram
5-Write an EBNF rules that describes the following while statement of Java. Then, write the recursive-descent...
5-Write an EBNF rules that describes the following while statement of Java. Then, write the recursive-descent subprogram in Java or C/C++ for the EBNF rule. Please summit your source code and a screen shot of the parsing of the following examples. do { if ( number % 2 == 0 ) even ++; number=number+1; } while (number <= 10)
Write the EBNF for mini Java language based of the following information: Data Types Integer Int...
Write the EBNF for mini Java language based of the following information: Data Types Integer Int Long Double Boolean Char References Complex Data Structures Arrays int v[30]; Classes member variables class Name { int a; char b; char name[25]; } Methods Return data type Primitive data type Void Method Name Parameter list Could be empty Statement Block { Variable declarations Executable Statements } Program Variable Declarations Class Definitions Methods Only one method named "main" but must have one method named...
Write down descriptions for each of the following sets:
Write down descriptions for each of the following sets:● Three different countably infinite subsets of the real numbers.● Three different uncountably infinite subsets of the real numbers.● One uncountably infinite proper super set of the real numbers.
you are to write a program in Java, that reads in a set of descriptions of...
you are to write a program in Java, that reads in a set of descriptions of various geometric shapes, calculates the areas and circumferences of the shapes, and then prints out the list of shapes and their areas in sorted order from smallest to largest area. There are four possible shapes: Circle, Square, Rectangle, and Triangle. The last is always an equilateral triangle. The program should read from standard input and write to standard output. The program should read until...
Write a program in java processing. Write a program that does the following: · Assume the...
Write a program in java processing. Write a program that does the following: · Assume the canvas size of 500X500. · The program asks the user to enter a 3 digit number. · The program then checks the value of the first and last digit of the number. · If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer. · If the two digits are odd, it...
Write the chemical formula for each substance mentioned in the following word descriptions (use the front...
Write the chemical formula for each substance mentioned in the following word descriptions (use the front inside cover to find the symbols for the elements you do not know). (a) Zinc carbonate can be heated to form zinc oxide and carbon diox- ide. (b) On treatment with hydrofluoric acid, silicon dioxide forms silicon tetrafluoride and water. (c) Sulfur dioxide reacts with water to form sulfurous acid. (d) The substance phos- phorus trihydride, commonly called phosphine, is a toxic gas. (e)...
Java please! Write the code in Exercise.java to meet the following problem statement: Write a program...
Java please! Write the code in Exercise.java to meet the following problem statement: Write a program that will print the number of words, characters, and letters read as input. It is guaranteed that each input will consist of at least one line, and the program should stop reading input when either the end of the file is reached or a blank line of input is provided. Words are assumed to be any non-empty blocks of text separated by spaces, and...
Select the correct term for each of the following descriptions. Descriptions Terms This theory argues that...
Select the correct term for each of the following descriptions. Descriptions Terms This theory argues that there is no optimal dividend policy because a firm’s dividend policy does not affect the value of the firm. Stock dividend    According to this theory, an announced dividend payment that exceeds investors’ expectations is interpreted to be “good” news and should be expected to increase the price of the firm’s common stock, whereas an announced dividend that is less than investors’ expectations is...
Select the appropriate term associated with a bank reconciliation for each of the following descriptions. Descriptions...
Select the appropriate term associated with a bank reconciliation for each of the following descriptions. Descriptions Terms a. Cash receipts received by the company but not yet recorded by the bank. b. Fees imposed by the bank to the company for providing routine services. c. Checks written to the company that are returned by the bank as not having adequate funds. d. Checks written by the company but not yet recorded by the bank. e. Money earned on the average...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT