POV-Ray : Newsgroups : povray.beta-test : Bug List : Re: Bug List Server Time
28 Jul 2024 18:11:54 EDT (-0400)
  Re: Bug List  
From: Tim Attwood
Date: 5 Feb 2008 21:49:12
Message: <47a92028$1@news.povray.org>
>> Malformed Nested #declare Doesn't Raise Error
>> ---------------------------------------------
>> A declare of the form...
>> #declare Weird = #declare Aval = 1;
>> parses without an error. This is probably should raise an error,
>> or at least a warning, since it can terminate inside nested
>> #if and #while statements. Existed in 3.6 as well.
>
>  This is not a bug nor an error, just a side-effect of how the parser 
> works.
>
>  When the parser finds "#declare Weird = " it will then recursively parse
> for "anything that evaluates to something which can be declared". This
> "anything" is parsed like any other SDL. This includes, among other 
> things,
> the possibility if putting #-commands in there.
>
>  Thus the next thing it finds is "#declare", which is just fine, and
> will parse that (creating the identifier 'Aval' and assigning "1" to it).
> When this is done, parsing will continue as normal, and whatever comes
> after that in-between #declare will be assigned to 'Weird'.
>
>  It's exactly this kind of parsing which allows doing things like:
>
> #declare Weird = some_macro(1, 2, 3);
>
> where the macro may have anything inside it (including #declares and 
> such).
>
>  Your example line does, in fact, give an error, because there's nothing
> to assign to 'Weird' because nothing comes after the second #declare.
> This, however, would be perfectly ok:
>
> #declare Weird = #declare Aval = 1; 2;
>
>  It may look a bit weird, but it's well defined: While parsing the 
> parameter
> to #declare, a second #declare is found, which is parsed recursively. 
> After
> it has been parsed, parsing continues normally, so it finds the '2' and
> assigns it to 'Weird'.
>
>  I'm not sure if changing this behavior is desirable. It would make a lot
> of other things a lot harder to parse.
>
It's not really a high priority to fix, but it probably should at least
raise a warning, since the Weird #declare can terminate inside #if and
#while loops, and without a semicolon.

Here's a more complete test scene that shows some of this weirdness...

camera {
   location  <0.0, 0.5, -4.0>
   direction 1.5*z
   right     x*image_width/image_height
   look_at   <0.0, 0.0,  0.0>
}

light_source {
  <0,1,-10>
  color rgb <1,1,1>
}

background {rgb <1,1,1>}

#declare pass_text = text {
   ttf "timrom.ttf","PASS",0.1,0
   pigment {rgb <0,1,0>}
   translate <-1,0,0>
};

#declare fail_text = text {
   ttf "timrom.ttf","FAIL",0.1,0
   pigment {rgb <1,0,0>}
   translate <-1,0,0>
};

// misformed #declare
#declare Weird = #declare Aval = 1;

// other properly formed statements
#declare PigVal = pigment {rgb <0,0,0>};
#declare ObjVal = sphere {<0,0,0>,1};

#if (true=true)
#local c=0;
#while (c=0)

// this object ends the misformed #declare and doesn't render
object {pass_text}

// this object renders normally
object {fail_text}

#local c=1;
#end
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.