169k views
1 vote
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; }

User Segalaj
by
5.0k points

1 Answer

3 votes

Answer:

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);

}

}

Step-by-step explanation:

User Kodiak
by
5.9k points