Writting a C++ Parser

Discussion in 'Mac Programming' started by Soulstorm, Aug 3, 2007.

  1. macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #1
    Well, that may sound too vague, but I am trying to improve my skills in writing parsers. So far for C++ I haven't tried to look at any other type of parser other than recursive descent.

    All I would like is to have some resources to get started with writing recursive descent parsers. Examples, tutorials, etc.

    PS. If the resources are for Cocoa, I still want them :)
     
  2. macrumors 6502

    Joined:
    Jul 25, 2006
  3. macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #3
    Theoretical question: Can you write a recursive descent parser for C++?
    I don't know I forgot if C++ is context sensitive or not

    I would only do a recurcive decent parser for a simple language. The
    last two I wrote I simply used LEX/YACC. It is so much easier and
    you can be done in an hour.

    But RD is easy, just write some functions that return "true" on a match.
    Google found this. Looks good
    http://teaching.idallen.com/cst8152/98w/recursive_decent_parsing.html
     
  4. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    C or Objective-C would likely be a better choice. C++ is horrifyingly complex to parse correctly.
     
  5. macrumors newbie

    Joined:
    Aug 12, 2007
    #5
    Flex/Bison are alternatives to Lex/Yacc, that I've personally used.

    Probably the best resource that you can have for writing a compiler is the Dragon book. There's quite a lot of theory to wade through before you get to the juicy bits. For example, you're going to need to have a good understanding of BNF.

    If I recall correctly, there are a lot of ambiguities in the C++ grammar that make writing a compiler for it difficult. That contrasts with C, which has only one ambiguity, the 'dangling else'.
     
  6. macrumors 65816

    devman

    Joined:
    Apr 19, 2004
    Location:
    AU

Share This Page