Need to evaluate simple arithmetic expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mstorkamp@yahoo.com

    #1

    Need to evaluate simple arithmetic expression

    I need to evaluate simple arithmetic expressions.

    I wrote a quick and dirty program that allows me to enter dimensions
    off of a drawing, and based on global or local tolerances calculate an
    upper and lower limit to put in an inspection worksheet.

    When it asks for a dimension I would like to be able to type in
    something like: '(12.5+10)/2' or '150-3.45'

    What I'm looking for is a function along the lines of 'double
    evaluate_expres sion(char *)' that would solve simple 4-function
    arithmetic with parenthesis.

    (and I don't want to have to write it myself)

    I've had no luck googling for such a function. Does anybody have one
    or have a link to download one? Thanks.
  • jameskuyper@verizon.net

    #2
    Re: Need to evaluate simple arithmetic expression



    mstork...@yahoo .com wrote:
    I need to evaluate simple arithmetic expressions.
    >
    I wrote a quick and dirty program that allows me to enter dimensions
    off of a drawing, and based on global or local tolerances calculate an
    upper and lower limit to put in an inspection worksheet.
    >
    When it asks for a dimension I would like to be able to type in
    something like: '(12.5+10)/2' or '150-3.45'
    >
    What I'm looking for is a function along the lines of 'double
    evaluate_expres sion(char *)' that would solve simple 4-function
    arithmetic with parenthesis.
    >
    (and I don't want to have to write it myself)
    >
    I've had no luck googling for such a function. Does anybody have one
    or have a link to download one? Thanks.
    Do you really need a function? Would a stand-alone program be
    acceptable? I would ordinarily use a spreadsheet program for that kind
    of stuff. If you're using a Unix-like system, there's also a program
    called bc that makes it easy to evaluate simple expressions - but
    definitely read the man page before trying to use it, it's not very
    user-friendly.

    Comment

    • Richard Heathfield

      #3
      Re: Need to evaluate simple arithmetic expression

      mstorkamp@yahoo .com said:
      I need to evaluate simple arithmetic expressions.
      This might do the trick:


      I've had no luck googling for such a function. Does anybody have one
      or have a link to download one? Thanks.
      I got the above hit with the search terms

      eval simple c

      (It was the third hit.)

      It probably originates from http://www.snippets.org/ which has got a ton of
      useful stuff. Well worth a look.

      --
      Richard Heathfield <http://www.cpax.org.uk >
      Email: -http://www. +rjh@
      Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
      "Usenet is a strange place" - dmr 29 July 1999

      Comment

      • mstorkamp@yahoo.com

        #4
        Re: Need to evaluate simple arithmetic expression

        On Nov 20, 10:19 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
        mstork...@yahoo .com said:
        >
        I need to evaluate simple arithmetic expressions.
        >
        This might do the trick:
        >

        >
        I've had no luck googling for such a function. Does anybody have one
        or have a link to download one? Thanks.
        >
        I got the above hit with the search terms
        >
        eval simple c
        >
        (It was the third hit.)
        >
        It probably originates fromhttp://www.snippets.or g/which has got a ton of
        useful stuff. Well worth a look.
        >
        Thanks for the links, that's just what I was looking for. (and I tried
        every permutation of arithmetic, function, evaluation, etc I could
        think of, honestly :-)

        Comment

        • Ben Pfaff

          #5
          Re: Need to evaluate simple arithmetic expression

          mstorkamp@yahoo .com writes:
          I need to evaluate simple arithmetic expressions.
          libmatheval

          --
          "...what folly I commit, I dedicate to you."
          --William Shakespeare, _Troilus and Cressida_

          Comment

          • hsmit.home@gmail.com

            #6
            Re: Need to evaluate simple arithmetic expression

            On Nov 20, 4:49 pm, mstork...@yahoo .com wrote:
            I need to evaluate simple arithmetic expressions.
            >
            I wrote a quick and dirty program that allows me to enter dimensions
            off of a drawing, and based on global or local tolerances calculate an
            upper and lower limit to put in an inspection worksheet.
            >
            When it asks for a dimension I would like to be able to type in
            something like: '(12.5+10)/2' or '150-3.45'
            >
            What I'm looking for is a function along the lines of 'double
            evaluate_expres sion(char *)' that would solve simple 4-function
            arithmetic with parenthesis.
            >
            (and I don't want to have to write it myself)
            >
            I've had no luck googling for such a function. Does anybody have one
            or have a link to download one? Thanks.
            Another piece of code that does what you want, and is more C++
            oriented is provided in the following link:



            It's very clean and concise code. Hat's off to the developer.

            Hans Smit

            Comment

            • user923005

              #7
              Re: Need to evaluate simple arithmetic expression

              On Nov 20, 7:49 am, mstork...@yahoo .com wrote:
              I need to evaluate simple arithmetic expressions.
              >
              I wrote a quick and dirty program that allows me to enter dimensions
              off of a drawing, and based on global or local tolerances calculate an
              upper and lower limit to put in an inspection worksheet.
              >
              When it asks for a dimension I would like to be able to type in
              something like: '(12.5+10)/2' or '150-3.45'
              >
              What I'm looking for is a function along the lines of 'double
              evaluate_expres sion(char *)' that would solve simple 4-function
              arithmetic with parenthesis.
              >
              (and I don't want to have to write it myself)
              >
              I've had no luck googling for such a function. Does anybody have one
              or have a link to download one? Thanks.
              It's a FAQ:

              18.14: I need code to parse and evaluate expressions.

              A: Two available packages are "defunc," posted to
              comp.sources.mi sc
              in December, 1993 (V41 i32,33), to alt.sources in January,
              1994,
              and available from sunsite.unc.edu in
              pub/packages/development/libraries/defunc-1.3.tar.Z, and
              "parse," at lamont.ldgo.col umbia.edu. Other options include
              the
              S-Lang interpreter, available via anonymous ftp from
              amy.tch.harvard .edu in pub/slang, and the shareware Cmm ("C-
              minus-minus" or "C minus the hard stuff"). See also questions
              18.16 and 20.6.

              There is also some parsing/evaluation code in _Software
              Solutions in C_ (chapter 12, pp. 235-55).

              Those solutions may no longer be available so the other suggestions
              elsethread may be helpful.

              You could always use yacc or bison or the gold parser to make your own
              grammar. Might be a fun exercise.

              Comment

              Working...