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. Managed C++/CLI
  4. How to perform Expression Evaluation in C++

How to perform Expression Evaluation in C++

Scheduled Pinned Locked Moved Managed C++/CLI
tutorialc++data-structures
4 Posts 4 Posters 3 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.
  • U Offline
    U Offline
    User 12365995
    wrote on last edited by
    #1

    Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4). -Only integers need to be supported -The following operators should be supported: +, -, *. -Expressions within parenthesis should be evaluated first. -Then the resulting expressions should be evaluated from left to right (no operator precedence) -Example: 4+(4-(2*3)+1)+4 = 7 The code should be written in such a way to support additional operators. Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’] and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.

    S L S 3 Replies Last reply
    0
    • U User 12365995

      Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4). -Only integers need to be supported -The following operators should be supported: +, -, *. -Expressions within parenthesis should be evaluated first. -Then the resulting expressions should be evaluated from left to right (no operator precedence) -Example: 4+(4-(2*3)+1)+4 = 7 The code should be written in such a way to support additional operators. Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’] and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.

      S Offline
      S Offline
      Sascha Lefevre
      wrote on last edited by
      #2

      Your homework should serve the purpose that you learn something. And that something isn't supposed to be how to get other people to doing your homework for you. Your assignments will get more difficult over time - so if you don't start doing them yourself now you'll never be able to. So sit down, think about it and try something. If you then encounter a specific problem, feel free to ask - that's the idea of these forums. Also, there are a lot of articles here on CodeProject about expression evaluation. Take a look at those if you struggle to find a starting point.

      If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

      1 Reply Last reply
      0
      • U User 12365995

        Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4). -Only integers need to be supported -The following operators should be supported: +, -, *. -Expressions within parenthesis should be evaluated first. -Then the resulting expressions should be evaluated from left to right (no operator precedence) -Example: 4+(4-(2*3)+1)+4 = 7 The code should be written in such a way to support additional operators. Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’] and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Not sure whether this is C or C++ but you could always start at C/C++ Language and Standard Libraries[^].

        1 Reply Last reply
        0
        • U User 12365995

          Write a simple expression evaluator that takes a string like the following as input: 1+2*(3+4). -Only integers need to be supported -The following operators should be supported: +, -, *. -Expressions within parenthesis should be evaluated first. -Then the resulting expressions should be evaluated from left to right (no operator precedence) -Example: 4+(4-(2*3)+1)+4 = 7 The code should be written in such a way to support additional operators. Assume the existence of a function tokenise, which could take a string and return an array of strings, for instance tokenise(‘1+(2*3)+4’) would return [‘1’,’+’,’(‘,’2’,’*’,’3’,’)’,’+’,’4’] and the functions isNumber and asNumber which would return a Boolean and integer respectively on a single string input.

          S Offline
          S Offline
          Super Lloyd
          wrote on last edited by
          #4

          Big list of resource for you. There is good stuff there! ;) language agnostic - Learning to write a compiler - Stack Overflow[^]

          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

          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