Parser program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anandaraman
    New Member
    • Feb 2007
    • 8

    Parser program

    Hi all, i need one help from u.when u give expression like 10+4*2-6/8 the expression should be evaluated in hierarchy order and the result will be displayed. the expression may be any longer or shorter.the operands used are +,-,*,/,mod, pow..please any one help in writing coding on this...
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by anandaraman
    Hi all, i need one help from u.when u give expression like 10+4*2-6/8 the expression should be evaluated in hierarchy order and the result will be displayed. the expression may be any longer or shorter.the operands used are +,-,*,/,mod, pow..please any one help in writing coding on this...
    I'm not sure what you are asking for; please elaborate on your problem, and ask a question.

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      In any computer language, to force the order of precedence of calculations use brackets () as these have the highest order of precedence in computers and mathematics

      Comment

      • steven
        New Member
        • Sep 2006
        • 143

        #4
        As far as I was aware, languages usually take mathematical precedence in such calculations, doing multiplications , divisions, etc, then addition and subtraction.

        You can force precedence with the use of brackets though.

        Comment

        • anandaraman
          New Member
          • Feb 2007
          • 8

          #5
          i know, there ia already predefined function that calculate the expression, but i need the program that perform the calculation

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            i know, there ia already predefined function that calculate the expression, but i need the program that perform the calculation
            If you know, why are you asking us? And what are you asking for? A PHP predefined function or a user defined function? Both seem pointless and inefficient because it can be done using basic mathematics

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              What you are asking is to write an interpreter written in an interpreter language, i.e. PHP. That is not a good idea. If you want to develop such an interpreter you should use a compiled language, like C.
              Or is this just an exercide for a class assignment?

              Ronald :cool:

              Comment

              • datttanand
                New Member
                • Mar 2007
                • 19

                #8
                10+4*2-6/8

                here evaluation order will be

                step1-- 4*2
                step2-- 6/8
                step3-- 10+step1
                step4--step3-step2

                so accordingly arrange your variables...... ...

                Comment

                Working...