kuchuz

PBO-C 6 : Parser()

Nov 26th, 2020 (edited)
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.util.StringTokenizer;
  4. import java.lang.String;
  5.  
  6. public class Parser
  7. {
  8.     private CommandWords commands;
  9.      
  10.     public Parser()
  11.     {
  12.         commands = new CommandWords();
  13.     }
  14.  
  15.     public Command getCommand()
  16.     {
  17.         String inputLine = "";
  18.         String word1;
  19.         String word2;
  20.         System.out.print("> ");
  21.         BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
  22.         try
  23.         {
  24.             inputLine = reader.readLine();
  25.         }
  26.         catch (java.io.IOException exc)
  27.         {
  28.             System.out.println ("There was an error during reading: " + exc.getMessage());
  29.         }
  30.         StringTokenizer tokenizer = new StringTokenizer(inputLine);
  31.         if(tokenizer.hasMoreTokens())
  32.             word1 = tokenizer.nextToken();
  33.         else
  34.             word1=null;
  35.         if(tokenizer.hasMoreTokens())
  36.             word2 = tokenizer.nextToken();
  37.         else
  38.             word2=null;
  39.         if(commands.isCommand(word1))
  40.             return new Command(word1, word2);
  41.         else
  42.             return new Command(null, word2);
  43.     }
  44. }
Add Comment
Please, Sign In to add comment