title: parser with scopes and conditionals
body: <p>I'm writing a C/C++/... build system (I understand this is madness ;)), and I'm having trouble designing my parser.</p>
  
  <p>My "recipes" look like this:</p>
  
  <pre><code>global
  {
      SOURCE_DIRS src
      HEADER_DIRS include
      SOURCES bitwise.c \
              framing.c
      HEADERS \
              ogg/os_types.h \
              ogg/ogg.h
  }
  lib static ogg_static
  {         
     NAME ogg
  }
  lib shared ogg_shared
  {
      NAME ogg
  }
  </code></pre>
  
  <p>(This being based on the super simple libogg source tree)</p>
  
  <p><code>#</code> are comments, <code>\</code> are "newline escapes", meaning the line continues on the next line (see QMake syntac). <code>{}</code> are scopes, like in C++, and global are settings that apply to every "target". This is all background, and not <em>that</em> relevant... I really don't know how to work with my scopes. I will need to be able to have multiple scopes, and also a form of conditional processing, in the lines of:</p>
  
  <pre><code>win32:DEFINES NO_CRT_SECURE_DEPRECATE
  </code></pre>
  
  <p>The parsing function will need to know on what level of scope it's at, and call itself whenever the scope is increased. There is also the problem with the location of the braces ( <code>global {</code> or <code>global{</code> or as in the example).</p>
  
  <p>How could I go about this, using Standard C++ and STL? I understand this is a whole lot of work, and that's exactly why I need a good starting point. Thanks!</p>
  
  <p>What I have already is the whole ifstream and internal string/stringstream storage, so I can read word per word.</p>