3) Write code in a language of your choice that checks a source file (input file in plain text format) that separates lexemes by white space and special characters. This lexical analyzer will only have tokens for special characters and alphanumeric strings. Ie: 2345 6tgbsauhd9sa67*I{OPKDSl;jaklhl Would be 2345 6tgbsauhd9sa67 * I { OPKDSl ; jaklhl

Respuesta :

Answer:

Explanation:

CODE:

import java.io.*;

class Test

{

  public static void main(String[] args) {

      File file = new File("input.txt");

 

      try{

      BufferedReader b = new BufferedReader(new FileReader(file));

     

      String line;

      while ((line = b.readLine()) != null)

      {

          for(int i=0;i<line.length();i++)

          {

              char c=line.charAt(i);

              if((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9'))   //check if char is digit or alphabet

                  System.out.print(c);

              else

                  System.out.println("\n"+c);

          }

      }

      }

      catch(Exception e)

      {

          System.out.println(e);

      }

     

}

 

}