Math Parser thingy.....it's kinda cool

This is a discussion on Math Parser thingy.....it's kinda cool within the A Brief History of Cprogramming.com forums, part of the Community Boards category; So I was bored, and now I'm a bit less bored, but basically I've gone and set up an apache ...

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904

    Math Parser thingy.....it's kinda cool

    So I was bored, and now I'm a bit less bored, but basically I've gone and set up an apache server on my computer and had no real use for it...so I made something!

    Anyways, what it is is just a really simple script, you can type in a math expression and then I have a program that's polling a folder where the expressions are placed, and once it finds one, it parses it and returns some html code showing how it was parsed and such....kinda fun to play with if you like parsers.

    Here we go, have fun:
    http://thejefffiles.cjb.net/mathparser.php

    And if you're bored you can look at the stats of my computer....
    http://thejefffiles.cjb.net/

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    Bonus points to anyone who can figure out how to crash the parser, haha.

  3. #3
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    Here is your statement's results:
    There was an error in your math string...
    Hmm

  4. #4
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    What?! I put 3/0 and the result was 0.

    Something's wrong here.

  5. #5
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    I put in testing for divide by zero statements.....because I was afraid it would crash the parser.

  6. #6
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    Quote Originally Posted by B0bDole
    Here is your statement's results:
    There was an error in your math string...
    There was an error in your string evidently.

  7. #7
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    why not put a meta refresh code in your html to refresh after 30 seconds. letting the client manually press it is kinda ....
    nice idea though.

  8. #8
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    Got the meta refresh and it polls every 10 seconds now instead of 30.

  9. #9
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    I put up a diagram thingy if anyone's interested in how my parser works. It's only a really simple expression so it doesn't show order of operations, recursion with parenthesis, functions or variables though....but it's all I've gotten done so far.

    http://thejefffiles.cjb.net/mathparser.php

  10. #10
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    nice... more then the actual parser i liek the way the system works..

  11. #11
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    It doesn't handle trig functions.

  12. #12
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Here is your statement's results:
    Original expression: (3/2)+((14+5)/(6-1.5))

    Infix expression:
    LPAR
    3.000000
    DIV
    2.000000
    RPAR
    ADD
    LPAR
    LPAR
    14.000000
    ADD
    5.000000
    RPAR
    DIV
    LPAR
    6.000000
    SUB
    1.500000
    RPAR
    RPAR

    Postfix expression:
    3.000000
    2.000000
    DIV
    14.000000
    5.000000
    ADD
    6.000000
    1.500000
    SUB
    DIV
    ADD

    The result is: 5.72222



    7Smurfs approves this parser
    To code is divine

  13. #13
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Does it handle exponents yet?

    I want to see what it'll do if I try to raise a negative exponent to the 1/2 power or something :P

  14. #14
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    It handles trig functions and exponents, it always has.

    The following functions are implemented:

    sqrt
    sin
    cos
    tan
    atan
    asin
    acos
    log
    abs

    and exponents just use the ^ operator. There is a flag you can set when you compile the math parser to change ^ to the XOR operator, but since I'm using this as a math expression evaluator, it's just a power operator right now.

    http://thejefffiles.cjb.net/mathpars...?op=view&id=83
    (-1)^(-1/2)
    Last edited by jverkoey; 06-16-2005 at 12:37 PM.

  15. #15
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Oh, okay. I didn't know that.

    Sounds good.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cool math homework assignment
    By BobMcGee123 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-23-2007, 08:21 PM
  2. Math parser
    By grepawksed in forum C++ Programming
    Replies: 1
    Last Post: 10-14-2005, 08:13 PM
  3. Problem with a file parser.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 03-17-2005, 09:54 AM
  4. I dunno, kinda cool
    By Silvercord in forum Game Programming
    Replies: 12
    Last Post: 07-03-2003, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21