97.4k views
4 votes
"Write an EBNF rule that describes the following while statement of Java. Then, write the recursive-descent subprogram in Java for the EBNF rule. Please summit your source code and a screen shot of the parsing of the following examples. while (number <= 10) { number=number+1; } while (number > 10) { number=number-1; }"

1 Answer

6 votes

Answer:

Step-by-step explanation:

import java.util.*;

public class Main

{

public static void main(String args[])

{

StringTokenizer st1 =

new StringTokenizer("do { sum = sum + 1 ; } while ( sum < 10 ) ;", " ");

int count=0;

while (st1.hasMoreTokens())

{

count++;

System.out.println("Token "+count+" "+st1.nextToken());

}

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

}

}

User Veeresh Honnaraddi
by
4.3k points