CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2014
    Location
    RANCHI
    Posts
    1

    Thumbs up Implement an expression parser

    HOW CAN WE IMPLEMENT AN EXPRESSION PARSER IN C++. CAN ANYONE PLSSSSSSSS HELP ME ..... ??? THANX IN ADVANCE.

    NOTE :- ITS A LITTLE BIT URGENT ................

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Implement an expression parser

    There is a lot of discussions about it like
    http://stackoverflow.com/questions/1...ression-in-c-c
    and others
    And if it is "A LITTLE BIT URGENT" then you had to begin working on this problem "a little bit" earlier!
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Implement an expression parser

    A lot of the complexity (or not) of this will be around what is deemed to be an 'expression'. If you haven't already got/done this then the first step is to define the 'language' of the expression - what are its basic elements (eg numbers, arithmetic symbols etc) and how can these elements be correctly combined to produce a valid expression. Once you have the 'language' defined then you can best determine the type of parser required. There are various types of parsers depending upon the 'language' that is required to be parsed. One of the more popular methods is the recursive descent parser See http://www.dreamincode.net/forums/to...ser-oop-style/ for an example

    The method of parsing may also be influenced by the required output of the parser and how the output is to be used. eg do you need an expression tree that can be traversed or if the expression is simple do you just want reverse polish format output?

    Sorry I can't provide more guidance at this stage as your initial query about building an expression parser is rather general.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    Aug 2013
    Posts
    55

    Re: Implement an expression parser

    The most famous parsing algorithm specifically for math expression parsing is the Shunting-yard algorithm by Dijkstra,

    http://en.wikipedia.org/wiki/Shunting-yard_algorithm

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured