simple interpreter
-
hi. I am trying to create a simple interpreter wherein it simply adds and subtracts. Sample Input: y = 5 + 8; cout << y; Output: 13 I have already started using stacks however it seems that it cannot pass through other commands after reading the input. Here's the code (Actually, I got this code from the net but it seems not to work): #include #include #include using namespace std; int main(){ stack syntax; string word; while (cin >> input) //after this, it no longer passes to the next syntax { syntax.push(word); } cout << "Number of words: " << syntax.size() << endl; while(!syntax.empty()) { cout << syntax.top() << endl; syntax.pop(); } cout.flush(); return 0; } Do you have any ideas? :confused:
-
hi. I am trying to create a simple interpreter wherein it simply adds and subtracts. Sample Input: y = 5 + 8; cout << y; Output: 13 I have already started using stacks however it seems that it cannot pass through other commands after reading the input. Here's the code (Actually, I got this code from the net but it seems not to work): #include #include #include using namespace std; int main(){ stack syntax; string word; while (cin >> input) //after this, it no longer passes to the next syntax { syntax.push(word); } cout << "Number of words: " << syntax.size() << endl; while(!syntax.empty()) { cout << syntax.top() << endl; syntax.pop(); } cout.flush(); return 0; } Do you have any ideas? :confused:
harcaype wrote:
Do you have any ideas?
Definitely!
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
harcaype wrote:
Do you have any ideas?
Definitely!
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark Salsbery wrote:
Definitely!
I know you're a creative guy. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
hi. I am trying to create a simple interpreter wherein it simply adds and subtracts. Sample Input: y = 5 + 8; cout << y; Output: 13 I have already started using stacks however it seems that it cannot pass through other commands after reading the input. Here's the code (Actually, I got this code from the net but it seems not to work): #include #include #include using namespace std; int main(){ stack syntax; string word; while (cin >> input) //after this, it no longer passes to the next syntax { syntax.push(word); } cout << "Number of words: " << syntax.size() << endl; while(!syntax.empty()) { cout << syntax.top() << endl; syntax.pop(); } cout.flush(); return 0; } Do you have any ideas? :confused:
harcaype wrote:
Do you have any ideas?
Personally not, however I know a creative guy [^]. BTW: properly format you code snippet using the code block button. BTW2: are you using this code without properly understanding the underlying idea? At a first glance it looks rather buggy. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
hi. I am trying to create a simple interpreter wherein it simply adds and subtracts. Sample Input: y = 5 + 8; cout << y; Output: 13 I have already started using stacks however it seems that it cannot pass through other commands after reading the input. Here's the code (Actually, I got this code from the net but it seems not to work): #include #include #include using namespace std; int main(){ stack syntax; string word; while (cin >> input) //after this, it no longer passes to the next syntax { syntax.push(word); } cout << "Number of words: " << syntax.size() << endl; while(!syntax.empty()) { cout << syntax.top() << endl; syntax.pop(); } cout.flush(); return 0; } Do you have any ideas? :confused:
harcaype wrote:
while (cin >> input) //after this, it no longer passes to the next syntax ... Do you have any ideas?
Yes. Fix the syntax error.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
harcaype wrote:
while (cin >> input) //after this, it no longer passes to the next syntax ... Do you have any ideas?
Yes. Fix the syntax error.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
well... that's my point. I can't seem to find any way to fix it. It runs but I don't know what logical error I'm doing. It does store the input in the stack but it no longer goes to the next line of codes after the while loop. Please help.. (T_T)
harcaype wrote:
I can't seem to find any way to fix it.
The code snippet you've shown does not compile.
harcaype wrote:
...but it no longer goes to the next line of codes after the while loop.
Have you tried pressing F6 followed by the Enter key (twice).
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
harcaype wrote:
I can't seem to find any way to fix it.
The code snippet you've shown does not compile.
harcaype wrote:
...but it no longer goes to the next line of codes after the while loop.
Have you tried pressing F6 followed by the Enter key (twice).
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
wait. im sorry about that. this is the right code. #include #include #include using namespace std; int main(){ stack syntax; string word; while (cin >> word) { syntax.push(word); } cout << "Number of words: " << syntax.size() << endl; while(!syntax.empty()) { cout << syntax.top() << endl; syntax.pop(); } cout.flush(); return 0; }