|
|
In article <47a87d61@news.povray.org>, war### [at] tagpovrayorg says...
> Tim Attwood <tim### [at] comcastnet> wrote:
> > 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 wo
rks.
>
> When the parser finds "#declare Weird = " it will then recursively pa
rse
> for "anything that evaluates to something which can be declared". This
> "anything" is parsed like any other SDL. This includes, among other thing
s,
> 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 param
eter
> to #declare, a second #declare is found, which is parsed recursively. Aft
er
> it has been parsed, parsing continues normally, so it finds the '2' and
> assigns it to 'Weird'.
>
Well, its also open to interpretation. Logically, it would *also* be
possible to consider the original statement to mean:
#declare Aval = 1;
#declare Weird = Aval;
Since it *is* recursing. The parser though is treating things like a
function call, apparently, so sees:
declare global:Weird {
declare global:Aval {
return 1
}
'Error! This language "requires" a returned value.
}
Its a wacky way to handle variable declarations, and probably the reason
why "most" languages separate variables and functions/macros, which much
clearer syntax.
--
void main () {
if version = "Vista" {
call slow_by_half();
call DRM_everything();
}
call functional_code();
}
else
call crash_windows();
}
<A HREF='http://www.daz3d.com/index.php?refid=16130551'>Get 3D Models,
3D Content, and 3D Software at DAZ3D!</A>
Post a reply to this message
|
|