/* FPAE_Scanner_Tester.java ** Author: R. McCloskey ** Date: February 2020 ** This Java application is for the purpose of testing instances of the ** FPAE_Scanner class. The user is asked to enter an FPAE and, in response, ** the program lists the tokens in that FPAE, as produced by consecutive ** calls to the next() method of an instance of FPAE_Scanner that had ** been constructed using that FPAE. Note that it is not necessary for ** the user to enter a well-formed FPAE; any string containing only ** characters that would be expected to appear in an FPAE (parentheses, ** operator symbols, digits, and spaces) would be fine. ** This behavior repeats until the user enters an empty string. ** */ import java.util.Scanner; public class FPAE_Scanner_Tester { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String expr = "glorp"; while (expr.length() != 0) { System.out.print("\nEnter an FPAE: "); expr = keyboard.nextLine(); FPAE_Scanner fpaeScanner = new FPAE_Scanner(expr); System.out.println("Tokens are as follows:"); int cntr = 0; while (fpaeScanner.hasNext()) { cntr = cntr + 1; String nextToken = fpaeScanner.next(); System.out.printf("Token #%d: |%s|\n", cntr, nextToken); } System.out.printf("%d tokens found.\n", cntr); } System.out.println("\nGoodbye."); } }