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#
  4. Grammars and Parsers

Grammars and Parsers

Scheduled Pinned Locked Moved C#
questioncsharpc++jsonhelp
5 Posts 3 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.
  • T Offline
    T Offline
    Tomerland
    wrote on last edited by
    #1

    Dear experts, may be I have a stupid question for the experts. During my complete sw-career, if I had to parse some information from a text-file, I wrote some hand-crafted functions/classes which were full of (stringcompare, if-then-else-constructs, nested "for"-loops, ....). Finally this code was always totally unmaintainable and unreusable. An example: Getting the include-structure of a c++ - based program can easily get complicated, because the active include-files get constrained on nested defines. Now I read something on grammars and parsers which are used for compiler-construction. This seems to be very interesting to a lot of practical problems (not only to my include-structure-parsing-problem). Due to my beginners level of knowhow I have some questions: 1. Which links/books are available for beginners? 2. Is there a way to automatically create a parser solely from a grammar? 3. Is there any C# - Example available anywhere (e.b. at Codeproject) Kind Regards

    S C 2 Replies Last reply
    0
    • T Tomerland

      Dear experts, may be I have a stupid question for the experts. During my complete sw-career, if I had to parse some information from a text-file, I wrote some hand-crafted functions/classes which were full of (stringcompare, if-then-else-constructs, nested "for"-loops, ....). Finally this code was always totally unmaintainable and unreusable. An example: Getting the include-structure of a c++ - based program can easily get complicated, because the active include-files get constrained on nested defines. Now I read something on grammars and parsers which are used for compiler-construction. This seems to be very interesting to a lot of practical problems (not only to my include-structure-parsing-problem). Due to my beginners level of knowhow I have some questions: 1. Which links/books are available for beginners? 2. Is there a way to automatically create a parser solely from a grammar? 3. Is there any C# - Example available anywhere (e.b. at Codeproject) Kind Regards

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      Tomerland wrote:

      1. Which links/books are available for beginners?

      I did a module on compilers at uni, and the text book[^] was quite useful. It's the only book I've ever read on the subject though, so I don't know how it compares. It has several chapters on grammars, parsers and syntax trees.

      Tomerland wrote:

      2. Is there a way to automatically create a parser solely from a grammar?

      The classic tool is Yacc[^]. It generates parsers (in C) from grammars. I'm sure if you look around there will be ports for whatever languages you use. Check out here for some other compiler related tools. http://dinosaur.compilertools.net/[^] http://catalog.compilertools.net/lexparse.html[^] There's Irony[^] for .net. It generates compilers for domain specific languages, when given a grammar. (There's also a CP article on it's use here[^]). I haven't tried this out yet, but it's been on my list of interesting things to look at for at least 6 months :laugh: There's also an article on a tiny parser generator[^] app posted only a few days ago.

      Simon

      T 1 Reply Last reply
      0
      • S Simon P Stevens

        Tomerland wrote:

        1. Which links/books are available for beginners?

        I did a module on compilers at uni, and the text book[^] was quite useful. It's the only book I've ever read on the subject though, so I don't know how it compares. It has several chapters on grammars, parsers and syntax trees.

        Tomerland wrote:

        2. Is there a way to automatically create a parser solely from a grammar?

        The classic tool is Yacc[^]. It generates parsers (in C) from grammars. I'm sure if you look around there will be ports for whatever languages you use. Check out here for some other compiler related tools. http://dinosaur.compilertools.net/[^] http://catalog.compilertools.net/lexparse.html[^] There's Irony[^] for .net. It generates compilers for domain specific languages, when given a grammar. (There's also a CP article on it's use here[^]). I haven't tried this out yet, but it's been on my list of interesting things to look at for at least 6 months :laugh: There's also an article on a tiny parser generator[^] app posted only a few days ago.

        Simon

        T Offline
        T Offline
        Tomerland
        wrote on last edited by
        #3

        Thank you very much for your help, a very nice overview With very kind Regards ;)

        1 Reply Last reply
        0
        • T Tomerland

          Dear experts, may be I have a stupid question for the experts. During my complete sw-career, if I had to parse some information from a text-file, I wrote some hand-crafted functions/classes which were full of (stringcompare, if-then-else-constructs, nested "for"-loops, ....). Finally this code was always totally unmaintainable and unreusable. An example: Getting the include-structure of a c++ - based program can easily get complicated, because the active include-files get constrained on nested defines. Now I read something on grammars and parsers which are used for compiler-construction. This seems to be very interesting to a lot of practical problems (not only to my include-structure-parsing-problem). Due to my beginners level of knowhow I have some questions: 1. Which links/books are available for beginners? 2. Is there a way to automatically create a parser solely from a grammar? 3. Is there any C# - Example available anywhere (e.b. at Codeproject) Kind Regards

          C Offline
          C Offline
          c2423
          wrote on last edited by
          #4

          You might like to look at COCO/R (type into Google and will be the first hit) for generating from grammars. Its my tool of choice because the syntax is easy to learn and its ported to lots of languages (i.e. it can generate C#, Java......) Chris

          T 1 Reply Last reply
          0
          • C c2423

            You might like to look at COCO/R (type into Google and will be the first hit) for generating from grammars. Its my tool of choice because the syntax is easy to learn and its ported to lots of languages (i.e. it can generate C#, Java......) Chris

            T Offline
            T Offline
            Tomerland
            wrote on last edited by
            #5

            Thank you !

            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