ทำไมคุณไม่ทำให้ความต้องการของคุณเล็กน้อยง่ายขึ้น?
อย่าใช้เครื่องมือแยกวิเคราะห์เต็มรูปแบบซับซ้อนเกินไปและไม่จำเป็นสำหรับกรณีของคุณ
ทำให้วนเขียนข้อความที่แสดงถึง yout "prompt" สามารถเป็นเส้นทางปัจจุบันที่คุณอยู่
รอให้สตริง "แยกวิเคราะห์" สตริงและทำบางสิ่งบางอย่างขึ้นอยู่กับเนื้อหาของสตริง
สตริงสามารถ "แยกวิเคราะห์" เช่นเดียวกับที่คาดว่าจะมีบรรทัดซึ่งช่องว่างเป็นตัวคั่น ("tokenizer") และอักขระส่วนที่เหลือจะถูกจัดกลุ่ม
ตัวอย่าง.
โปรแกรมแสดงผล (และอยู่ในบรรทัดเดียวกัน): / user / files / ผู้ใช้เขียนรายการ (ในบรรทัดเดียวกัน) ทั้งหมด;
โปรแกรมของคุณจะสร้างรายการคอลเลกชันหรืออาร์เรย์เช่น
list
all;
หรือถ้า ";" ถือเป็นตัวคั่นเช่นช่องว่าง
/user/files/
list
all
โปรแกรมของคุณสามารถเริ่มต้นได้ด้วยการคาดหวังคำสั่งเดียวโดยไม่ต้องใช้ "ไพพ์" แบบ unix และไม่มีการเปลี่ยนทิศทางสไตล์หน้าต่าง
โปรแกรมของคุณสามารถสร้างพจนานุกรมคำแนะนำแต่ละคำสั่งอาจมีรายการพารามิเตอร์
รูปแบบการออกแบบคำสั่งใช้กับกรณีของคุณ:
http://en.wikipedia.org/wiki/Command_pattern
pseudocode "c ธรรมดา" นี้ไม่ได้ทดสอบหรือเสร็จสิ้นเป็นเพียงความคิดว่าสามารถทำได้อย่างไร
คุณสามารถทำให้มันเป็นวัตถุเชิงวัตถุมากขึ้นและในภาษาการเขียนโปรแกรมคุณชอบ
ตัวอย่าง:
// "global function" pointer type declaration
typedef
  void (*ActionProc) ();
struct Command
{
  char[512] Identifier;
  ActionProc Action; 
};
// global var declarations
list<char*> CommandList = new list<char*>();
list<char*> Tokens = new list<char*>();
void Action_ListDirectory()
{
  // code to list directory
} // Action_ListDirectory()
void Action_ChangeDirectory()
{
  // code to change directory
} // Action_ChangeDirectory()
void Action_CreateDirectory()
{
  // code to create new directory
} // Action_CreateDirectory()
void PrepareCommandList()
{
  CommandList->Add("ls", &Action_ListDirectory);
  CommandList->Add("cd", &Action_ChangeDirectory);
  CommandList->Add("mkdir", &Action_CreateDirectory);
  // register more commands
} // void PrepareCommandList()
void interpret(char* args, int *ArgIndex)
{
  char* Separator = " ";
  Tokens = YourSeparateInTokensFunction(args, Separator);
  // "LocateCommand" may be case sensitive
  int AIndex = LocateCommand(CommandList, args[ArgIndex]);
  if (AIndex >= 0)
  {
    // the command
    move to the next parameter
    *ArgIndex = (*ArgIndex + 1);
    // obtain already registered command
    Command = CommandList[AIndex];
    // execute action
    Command.Action();
  }
  else
  {
    puts("some kind of command not found error, or, error syntax");
  }  
} // void interpret()
void main(...)
{
  bool CanContinue = false;
  char* Prompt = "c\:>";
  char Buffer[512];
  // which command line parameter string is been processed
  int ArgsIndex = 0;
  PrepareCommandList();
  do
  {
    // display "prompt"
    puts(Prompt);
    // wait for user input
      fgets(Buffer, sizeof(Buffer), stdin);
    interpret(buffer, &ArgsIndex);
  } while (CanContinue);
} // void main()
คุณไม่ได้พูดถึงภาษาการเขียนโปรแกรมของคุณ คุณยังสามารถพูดถึงภาษาการเขียนโปรแกรมใด ๆ แต่ควร "XYZ"