import java.util.Scanner;
/**
* Class Parser here.
*
*/
public class Parser
{
private CommandWords commands;
private Scanner reader;
/**
* Membuat sebuah parser untuk membaca dari terminal window.
*/
public Parser()
{
commands = new CommandWords();
reader = new Scanner(System.in);
}
/**
* @return Perintah selanjutnya dari user.
*/
public Command getCommand()
{
String inputLine;
String word1 = null;
String word2 = null;
System.out.print("-> ");
inputLine = reader.nextLine();
Scanner tokenizer = new Scanner(inputLine);
if(tokenizer.hasNext())
{
word1 = tokenizer.next();
if(tokenizer.hasNext())
{
word2 = tokenizer.next();
}
}
if(commands.isCommand(word1))
{
return new Command(word1, word2);
}
else
{
return new Command(null, word2);
}
}
}