Thread: parser problem.

  1. #1
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117

    parser problem.

    I tried to change this parser which was using cin to use stringstream..
    when was using cin, everything was going perfectly..
    but now if I enter any expression like : 4+5 it'll get stuck on the first char (4 in this exemple..)

    But I changed really few things..
    added stringstream ist(temp_string);
    and then I changed all cin for ist..

    Do you guys see anything wrong there?

    Code:
    Token_value get_token()
    {
          stringstream ist(temp_string);
          char ch = 0;
          do {			// skip whitespace except '\n'
    	 if(!ist.get(ch)) return curr_tok = END;
          }while (ch != '\n' && isspace(ch));
          switch (ch)
          {
    	  case 0 : case  'E':
    	        return curr_tok=END;
    	  case ';' :	return curr_tok = PRINT;
    	  case '\n' :	line_count.new_line();
    	  case '*' :
    	  case '/' :
    	  case '+' :
    	  case '-' :
    	  case '(' :
    	  case ')' :
    	  case '=' : return curr_tok = Token_value(ch);
    	  
    	  case '0' :	case '1' :	case '2' :	case '3' : 	case '4' :
    	  case '5' :	case '6' :	case '7' :	case '8' :	case '9' :
    	  case '.' :
    	        ist.putback(ch);
    	        ist >> number_value;
    	        return curr_tok = NUMBER;
    	  default:				// NAME, NAME =, or error
    	        if (isalpha(ch))
    	        {
    		    string_value = ch;
    		    while (ist.get(ch) && isalnum(ch)) string_value.push_back(ch);
    		    ist.putback(ch);
    		    return curr_tok = NAME;
    	        }
    	        error("Bad Token");
    	        return curr_tok = PRINT;
          }
    }
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  2. #2
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    well Ive used my debugger and my problem seemsto be here:

    Code:
      do {			// skip whitespace except '\n'
    	 if(!ist.get(ch)) return curr_tok = END;
          }while (ch != '\n' && isspace(ch));
    when I was using cin.get it was going trough the string but now using ist (stringstream) it keeps pointing at the first char?

    any suggestion on either why is that so or a way to keep track where it should be pointing at and to go to next char...
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. Replies: 4
    Last Post: 03-12-2006, 02:17 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. problem with parser code
    By ssharish2005 in forum C Programming
    Replies: 2
    Last Post: 12-02-2005, 07:38 AM