Question: How do you read multiple commands/variables/modifiers from a single line of user input?
Much like any CLI such as Command Prompt would do, the user enters a single line and variables + modifiers are read and assigned from it.
E.G. A conversion program command:
32 km to cm
Then it reads:
numToConvert = (32)
then
"km to cm"
points to conversionRate1
conversionRate1 = (0.621371192)
multiply 32 by conversion rate (0.621371192)
print Result.
Second Example:
shutdown -h
or
shutdown /?
shutdown is read as a command
-h modifies it or /? modifies it
Anything given on the commandline, after the program name, is split on whitespace, and passed in to the args array.
So, given:
running “c:>program.exe convert foo to bar” will produce the lines
In order to parse out the semantic meaning, you will need to scan the args array and look for the modifiers.
If you’ve got strict syntax, you can simply look in the expected position
If you’re allowing flexible syntax it will be more complex; you will need to develop a series of parsing rules to help you make sense of the input.