Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. simple interpreter

simple interpreter

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harcaype
    wrote on last edited by
    #1

    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:

    M CPalliniC D 3 Replies Last reply
    0
    • H harcaype

      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:

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      harcaype wrote:

      Do you have any ideas?

      Definitely!

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      CPalliniC 1 Reply Last reply
      0
      • M Mark Salsbery

        harcaype wrote:

        Do you have any ideas?

        Definitely!

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        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]

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • H harcaype

          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:

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          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]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • H harcaype

            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:

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            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

            H 1 Reply Last reply
            0
            • D David Crow

              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

              H Offline
              H Offline
              harcaype
              wrote on last edited by
              #6

              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)

              D 1 Reply Last reply
              0
              • H harcaype

                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)

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                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

                H 1 Reply Last reply
                0
                • D David Crow

                  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

                  H Offline
                  H Offline
                  harcaype
                  wrote on last edited by
                  #8

                  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; }

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups