Question

In: Computer Science

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

Solutions

Expert Solution

Java:

import java.util.*;                                // Import package

public class EBNF                             // Class declaration

{

public static void main(String args[]) // Main method with void return type

{

StringTokenizer str1 = new StringTokenizer("for(counter= 1; counter<=10; counter++) {sum=sum+1;}", " ");

int count=0;                             // Value initialization

while (str1.hasMoreTokens())

{

count++;                                 // Count = count + 1

System.out.println("Token "+count+" "+str1.nextToken());       // Print command

}

System.out.println("Total Tokens :: "+count);                           // Print command

}

}

Output:

Hope this helps.


Related Solutions

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 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 ( $...
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...
Q1)   Convert the following set of BNF rules to a single EBNF rule. <E> --> <E>...
Q1)   Convert the following set of BNF rules to a single EBNF rule. <E> --> <E> + <T> | <E> - <T> | <T> Q2)   Briefly explain how the expected type and actual type of <expr>             in the following two BNF rules are determined: <assign> --> <var> = <expr> (Rule 1) <expr> --> <var> + <var> (Rule 2)
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...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner object to read input. int Age;     Write a java statement to read the Age input value 4 . Redo 1 to 3 using JOptionPane
3.Use EBNF to describe the syntax of Java ifstatements, no need to further define other statements...
3.Use EBNF to describe the syntax of Java ifstatements, no need to further define other statements or Boolean expressions. 4.Python uses indention in its program structures. How do you define the syntax of a language construct that uses indention?
The junction rule describes the conservation of which quantity?
The junction rule describes the conservation of which quantity? Note that this rule applies only to circuits that are in a steady-state.is it current, voltage or resistance>Apply the junction rule to the junction labeled with the number 1 (at the bottom of the resistor of resistance R2).Answer in terms of given quantities, together with the meter readings I1 and I2 and the current I3.>Apply the loop rule to loop 2(the smaller loop on the right). Sum the voltage changes across each...
1. Which of the following best describes a success scenario? - A statement that describes how...
1. Which of the following best describes a success scenario? - A statement that describes how certain decisions lead to success -A statement that defines what it means for the system to perform as intended   -A statement of what could go wrong within a system -A statement of who, what, when, where and how a system would fail 2. Which of the following variable types represent measurable properties of a system itself? -Input Variables -Output Variables -Exogenous Variables    -State Variables...
Java Complete Example.java to fulfill the following problem statement: Write a program to accept a list...
Java Complete Example.java to fulfill the following problem statement: Write a program to accept a list of numbers, one per line. Input is provided from a file if one is provided as the first command line argument. If a file is not provided, input should be read from the terminal. The numbers can either be whole numbers or floating point numbers. The program should continue to accept input until a number equal to 00 is input. Of course, if the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT