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. Using Context Free Grammers

Using Context Free Grammers

Scheduled Pinned Locked Moved C / C++ / MFC
json
4 Posts 4 Posters 0 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.
  • F Offline
    F Offline
    fordge
    wrote on last edited by
    #1

    hi Suppose I want an application which takes a source file and outputs its data members and functions. Supposed to develop into a kind of class view explorer. Regarding parsing the source file .... should i go for using regular expressions rules for this parsing or should i go for a language representation in context free grammer[CFG] and use the CFG rules for parsing or is there any other possible ideas for source file parsing awaiting advice fordge

    R B J 3 Replies Last reply
    0
    • F fordge

      hi Suppose I want an application which takes a source file and outputs its data members and functions. Supposed to develop into a kind of class view explorer. Regarding parsing the source file .... should i go for using regular expressions rules for this parsing or should i go for a language representation in context free grammer[CFG] and use the CFG rules for parsing or is there any other possible ideas for source file parsing awaiting advice fordge

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      For something with fixed syntax rules such as a programming language, I would go for a CFG, since parsing it with pure regex can be relatively complicated. Search Code Project for context free grammar to get more information. Hope this helps. ~RaGE();

      1 Reply Last reply
      0
      • F fordge

        hi Suppose I want an application which takes a source file and outputs its data members and functions. Supposed to develop into a kind of class view explorer. Regarding parsing the source file .... should i go for using regular expressions rules for this parsing or should i go for a language representation in context free grammer[CFG] and use the CFG rules for parsing or is there any other possible ideas for source file parsing awaiting advice fordge

        B Offline
        B Offline
        Bob Stanneveld
        wrote on last edited by
        #3

        I think that you should use a CF Grammer for parsing the file. The advantage of the CFG is, that when you have your grammer and rules, you can easely deduce code from it by yourself or a tool. An other advantage of a CFG over RegEx is that with a CFG, you almost always have a good overview of what you are doing and where you are doing it, RegEx tend to get complicated really fast. A recursive parser (from a CFG) is also easier to debug, than a state based RegEx parser, since you always have stack traces and you exacty know where you are and how you came there. IMHO I think that regular expressions are great for validating strings (like postal codes, phone numbers, etc..), but for the real parsing you shouls stick with grammers and parsers. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

        1 Reply Last reply
        0
        • F fordge

          hi Suppose I want an application which takes a source file and outputs its data members and functions. Supposed to develop into a kind of class view explorer. Regarding parsing the source file .... should i go for using regular expressions rules for this parsing or should i go for a language representation in context free grammer[CFG] and use the CFG rules for parsing or is there any other possible ideas for source file parsing awaiting advice fordge

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          Probably CFG. If you want to try regular expressions, then go download and install Regex++. It has some example programs like taking C++ file and (thru callbacks) outputs an html file. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

          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