Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Parse tokens in nested parentheses?

Parse tokens in nested parentheses?

Scheduled Pinned Locked Moved C / C++ / MFC
hardwaredata-structurestutorialquestionlearning
3 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matt Weagle
    wrote on last edited by
    #1

    Howdy all, I'm looking for either a library or a snippet as to how to parse tokens embedded in nested parentheses. For instance, I need to convert something like: (A, B, (C, D)) into a tree like: A B (Parent)->C (Parent)->D Of course, other trees would have different formats: ((A, B), C, D) ((A,B), (C,D)) etc.. I think this borders on a grammar topic, but my brain isn't quite what it used to be ;-( Any suggestions would be welcome. Thanks.

    S S 2 Replies Last reply
    0
    • M Matt Weagle

      Howdy all, I'm looking for either a library or a snippet as to how to parse tokens embedded in nested parentheses. For instance, I need to convert something like: (A, B, (C, D)) into a tree like: A B (Parent)->C (Parent)->D Of course, other trees would have different formats: ((A, B), C, D) ((A,B), (C,D)) etc.. I think this borders on a grammar topic, but my brain isn't quite what it used to be ;-( Any suggestions would be welcome. Thanks.

      S Offline
      S Offline
      Stober
      wrote on last edited by
      #2

      Probably need to use Polish Notation logic. I don't remember just how it goes, but you should be able to find a compiler design book that covers it.

      1 Reply Last reply
      0
      • M Matt Weagle

        Howdy all, I'm looking for either a library or a snippet as to how to parse tokens embedded in nested parentheses. For instance, I need to convert something like: (A, B, (C, D)) into a tree like: A B (Parent)->C (Parent)->D Of course, other trees would have different formats: ((A, B), C, D) ((A,B), (C,D)) etc.. I think this borders on a grammar topic, but my brain isn't quite what it used to be ;-( Any suggestions would be welcome. Thanks.

        S Offline
        S Offline
        Sam Hobbs
        wrote on last edited by
        #3

        I think there is an expression parser in the CodeGuru web site but there might be one in this web site too. They might help but might be too much. I think you only need a syntactical parser. You probably do not need a symantics parser. Are you familiar with Lexx? It is a compiler that generates a syntactical parser written in C. Also see: http://www.snippets.org/ and look for "Jari Laaksonen's comment utilities in C++" near the bottom. It might help.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups