Command Line Interpreter

by Alex Peterson
Takes input from a player and breaks it down into commands. Useful for text based games.
ID:1708880
 
How it works

This shows you one way you can take apart a user's sentence into it's component parts and turn that into a series of commands that can be executed.

Part 1: Takes the user's input as text
Part 2: Removes anything unnecessary
Part 3: Makes a list called parts which contains Commands Objects and Numbers.
Part 4: Makes a list called format which contains corresponding values of "c","o" or "n" to each command, object and number.

Finally it executes each command right to left, giving it whatever information it finds to the right of the command. That command is then replaced in the parts list by whatever value it returned.

Example: "Pick up the candles from the table" becomes:

parts = ("/Command/pick_up", "candles"," /Command/from", "table"
format= ("c", "o", "c", "o")

Executes "/Command/from" becoming:

parts = (/Command/pick_up", "candles", "table")
format = ("c", "o", "o")

Executes "/Command/pick_up"
This command then takes the first object off of the second object. In this case it will take the candles off of the table.

I believe this is all considered Lexical analysis, in case anyone wanted to do further research

en.wikipedia.org/wiki/Lexical_analysis