in reply to Re: nested #if directive matching matching
in thread nested #if directive matching matching

choroba:

Actually, you *do* need a stack if you're going to properly handle the #else clauses. Otherwise, you won't remember the previous value(s) of the print vs. don't print states.

#if 0 this shouldn't print #if 1 nor should this #else nor this #end #else but this should #if 1 as should this #else but not this #end This should print, but where are you storing the information to know it without a stack? #else If you got that one right, howzabout this one? #end

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^3: nested #if directive matching matching
by choroba (Cardinal) on Jun 26, 2012 at 12:53 UTC
    That was not part of the spec :-)

      Using the counter, bitshift left and increment if true. Else is an XOR 1. Endif is a bitshift right.

      Initialize with a sentinel value so you know when you're done.

        That is a stack. Not an overly deep one, but probably sufficient for the purpose.

        True laziness is hard work