Help getting started with a Command Line Interpreter:

This is a discussion on Help getting started with a Command Line Interpreter: within the C++ Programming forums, part of the General Programming Boards category; Hi Everyone, I am in desperate need of help here. I would appreciate if anyone can give me some input ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Help getting started with a Command Line Interpreter:

    Hi Everyone,

    I am in desperate need of help here. I would appreciate if anyone can give me some input or some example to get me started with this problem.

    I have been working on creating operator overloading functions to work on Sets. I have created the Class for the Set by using a linked list (Doubly Linked) of integers. The program is functional and works by presenting a menu and predefined operations. Now the assignment is to make it work as a command line interpreter. In few words, instead of having a menu of options, I have to prompt the user for the expression to work on:

    Some Examples:

    Valid commands:
    Invalid Commands
    Command
    Result
    Command
    Result
    A
    A = { 1 2 3 4 5 }
    ! A
    B = A * { 1 3 5 }
    C = A { 2 4 6 } << 7
    { 3 6 9 12 } << 3 << 8
    3 <= A
    A == B
    A != C
    A == 5

    { }
    { 1 2 3 4 5 }
    5
    { 1 3 5 }
    {1 3 5 7 }
    { 3 6 9 12 8 }
    True
    False
    True
    True



    The good thing is that the professor already gave out the code to parse the command line expression and check for any errors or invalid expression, but that is all it does. What I need help with is to integrate one with the other and I am having a hell of time trying to understand the professor's code. I don't know which way to go without running into a corner. I just need to see maybe an example of an operation such as insert an element into a set for example, and then I can continue to work on the others.

    I have attached 2 files:

    1. Program 4 Final.zip which is the Set and Node Class with operator overloading functions and the User Menu in the main.
    2. Program 5.zip, which is the SetInterpreter Class with command line parsing and just checks for valid expressions and number of tokens.

    But I can't attach these 2 files here. If anyone is willing to help I can send them via email maybe?

    Please let me know if anyone can take a look at the code and hopefully give me a kick-start on how to begin because I have absolute no idea.

    Thanks in Advance for your precious help!

    Vince

    {EDIT}

    I managed to upload the files individually with the exception of one and here is the code which is the main function that goes with the SetInterp.h and setinterp.h

    Code:
    #include <cstdlib>
    #include <iostream>
    #include "SetInterp.h"
    
    using namespace std;
    
    int main()
    {
        SetInterpreter si;
        ReadFlag result;
        
        result = si.readLine();
        while (result != ENDF)
        {
    //          cout << result << endl;
              if (result == FAIL) {
    //             cout << "Bad Commandline\n";
                 result = si.readLine();
                 continue;
              }
              cout << "Number of tokens on command line were " << si.length() << endl;
              while (si.more())
              {
    
                    TokenNode * t = si.getNext();
                    switch(t->getToken()) {
                        default:      cout << "? ";
                        case OPERATOR:
                        case SETNAME: cout << t->getName() << " "; break;
                        case ELEMENT:
                        case VALUE:   cout << t->getValue() << " "; break;
                        case SET:     const int * list = t->getElements();
                                      cout << "{ ";
                                      for (int i=0; i<t->getSize(); i++) cout << list[i] << " ";
                                      cout << "} ";
                                      break;
                    }
              }
    
              cout << endl;
              result = si.readLine();
        }
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    Attached Files Attached Files
    Last edited by enzorug; 11-15-2010 at 09:35 AM. Reason: Adding the attachments

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help getting started...
    By Sh4d0ws in forum C Programming
    Replies: 0
    Last Post: 12-05-2009, 03:14 PM
  2. Interpreter Features Question
    By audinue in forum C Programming
    Replies: 0
    Last Post: 10-19-2008, 07:29 AM
  3. Help getting started :(
    By blackocellaris in forum C Programming
    Replies: 4
    Last Post: 11-05-2006, 05:50 PM
  4. Most pointless idea ever: Interpreter
    By Trauts in forum C++ Programming
    Replies: 5
    Last Post: 02-09-2003, 05:06 PM
  5. How to get started?
    By anoopks in forum Linux Programming
    Replies: 0
    Last Post: 01-14-2003, 02:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21