Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Mathematical Expression Parser (C++)

Options
  • 29-12-2003 12:35am
    #1
    Closed Accounts Posts: 13


    I'm writing a Mathematical Expression Parser in C++
    It should be able to handle most basic arithmetic operations (+ - / *) for scalar and vectorial arguments.
    It should also be able to evaluate macro functions on the fly, for example #max(vect1,vect2)+vect3/4.9 is an example of a typical expression.

    It needs to be as generic as possible, and recursive.

    I'm currently using the interperator design pattern to construct a syntax tree of classes.

    Together with a topdown tree parsing algorithim, which splits the expression into nodes, and evalutes each node recursivley.

    This is working well, but I'm considering using the visitor design pattern instead.

    If anyone has done ANYTHING similar to this, do you have any ideas for any similar (better) patterns to use, that would make the language syntax easily extensable? and more robust?

    The code is about 3000 lines, so I won't be pasting it in full. I'll give some examples if anyone wants.


Comments

  • Closed Accounts Posts: 66 ✭✭usualsuspect


    In Java I used state pattern visitor and abstract factory were the keys to execution without sucking up all available system resources...all depends how complex your expressions will be also are you dealing with unknowns. There were lots of papers on the web that explained different approaches to this problem. Dunno about interpretator soryr


Advertisement