Function Help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//The program will return true or false depending on
//whether input is a valid LISP command, a command-line interpreter
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
//The Lispinterpreter class will take input and return a boolean value
//depending on whether the command is valid or not
class Lispinterpreter{
      private:
              char ch;//variable to keep track of the last input from the user
      public:
             bool read();
             bool S();
             bool R();
             bool atom();
             bool atom1();
             bool text();          
};
const string digits = "0123456789";
const string letters = "ABCDEDFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

int main()
{
    Lispinterpreter interpreter;
    
    while(cin){
               cout << "Enter LISP expression: (or ^Z to stop) >> ";
               bool result = interpreter.read();
               if(result == true) cout << "True\n"; else cout << "FALSE\n";
               }
               
    system("pause");
    return 0;
}
//All functions belong to the class Lispinterpreter
//Pre: The user has inputted something
bool Lispinterpreter::read()
{
     cin >> ch;
     return S();
}
//Post:  read() is called
//Pre:  read() function is satisfied
bool Lispinterpreter::S()
{
     if(ch == '(')
     {
           cin >> ch;
           return R();
     }
     if(ch == '"')
     {
           cin >> ch;
           return text();
     }
     return atom(); 
}
//Post: R(), text(), or atom() is called
//Pre: A right paren was the user's input
bool Lispinterpreter::R()
{
     if(ch == ')')
     {
           cin >> ch;
           return true;
     }
     if(ch == '"')
     {
           cin >> ch;
           return text() && R();
     }
     if(ch == '(')
     {
           cin >> ch;
           return R() && R();
     }
     return atom() && R();
}
//Post: true, text(), or R() is returned/called
//Pre: User's input was not a ')', ""', or '('
bool Lispinterpreter::atom()
{
     if(digits.find(ch) < digits.length())
     {
                        cin.get(ch);
                        return atom1();
     }
     if(letters.find(ch) < letters.length())
     {
                        cin.get(ch);
                        return atom1();
     }
}
//Post:If user's input included a letter or whole non-negative number, atom() is called.
//Pre: User's input was a letter or whole non-negative number
bool Lispinterpreter::atom1()
{
     if(digits.find(ch) < digits.length())
     {
                        cin.get(ch);
                        return atom1();
     }
     if(letters.find(ch) < letters.length())
     {
                        cin.get(ch);
                        return atom1();
     }
     return true;
}
//Post: recursive loop untill the end of the line of text is reached
//Pre: a '"' was the user's input
bool Lispinterpreter::text()
{
     if(ch == '"')
     {
           cin >> ch;
           return true;
     }
     if(ch != '"')
     {
           cin >> ch;
           return text();
     }
}
//Post: Untill '"' is found the function will call upon itself, if '"' is not
//found the function will return false. 

It seems when I input more than three characters I get my message, but other inputs don't work. Examples:
(goodbye cruel world)
"goodbye cruel world"
)goodbye(
Topic archived. No new replies allowed.