-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.java
More file actions
executable file
·65 lines (49 loc) · 1.62 KB
/
Parser.java
File metadata and controls
executable file
·65 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.StringTokenizer;
/**
* classe traitant les entrees de texte
*/
public class Parser
{
private CommandWords aCommandWords; // holds all valid command words
/**
* Create a new Parser.
*/
public Parser()
{
this.aCommandWords = new CommandWords();
} // Parser()
/**
* Get a new command from the user. The command is read by
* parsing the 'inputLine'.
* @param pInputLine la String entree
* @return une Commande
*/
public Command
getCommand( final String pInputLine )
{
String vWord1;
String vWord2;
StringTokenizer tokenizer = new StringTokenizer( pInputLine );
if ( tokenizer.hasMoreTokens() )
vWord1 = tokenizer.nextToken(); // get first word
else
vWord1 = null;
if ( tokenizer.hasMoreTokens() )
vWord2 = tokenizer.nextToken(); // get second word
else
vWord2 = null;
// note: we just ignore the rest of the input line.
// Now check whether this word is known. If so, create a command
// with it. If not, create a "null" command (for unknown command).
return new Command( this.aCommandWords.getCommand(vWord1), vWord2 );
} // getCommand(.)
/**
* Demande la construction d'une String listant les commandes valides et la retourne.
* @return Une string listant les commandes autorisees.
*/
public String
getCommandList()
{
return this.aCommandWords.makeCommandList();
} //getCommandList()
} // Parser