|
![](/i/fill.gif) |
<wal### [at] informatik uni-halle de> wrote...
> I declared an Array :
>
> #declare A=array[100]
>
> and in the following instruction I want to declare a variable,
> using the "$"-Operator I get an Errormessage ...
>
> $B=1;
Yes, this is known limitation (a bug that is too difficult to fix that I
won't bother).
The following three code snipets will work:
#declare a=array[16]
#declare b=1;
$a=array[16]
$b=1;
$a=array[16]
#declare b=1; //I'm pretty sure this will work
The following one will not:
#declare a=array[16]
$b=1;
The problem occurs when you use of a #declare that does NOT end with a
semicolon, followed by a $.
Here is an explanation of why it acts this way and why I haven't fixed it:
All "#" directives in POV (such as #declare and #local) are handled
specially. When the Get_Token() function (responsible for reading and
interpreting the character input) finds a "#" character, it interrupts what
it is doing and calls the Parse_Directive() function. Regular scene parsing
is suspended until POV is done parsing the directive.
Now, just like the rest of the parser, Parse_Directive() uses Get_Token() to
get its tokens. This means that if POV wasn't careful, it could get a stack
overflow if you have a long string of #declares one right after another.
Why? Well, if Get_Token() finds a "#" (such as in my first code snipet)
while it is parsing a #declare, it calls Parse_Directive().
The trick is to make Parse_Directive() contain a loop, and add a special
case for Get_Token() so it won't allow a re-entry of Parse_Directive(). If
Parse_Directive() is active and Get_Token() hits a "#", it will ignore it
and allow Parse_Directive() to take care of it.
I built this same looping capability into the "$" replacement for
"#declare". However, the two loops are independent from each other.
Because of the way Parse_Directive() works, I'm pretty sure that you can
enter Parse_Directive() from my "$" replacement, but you can't go the other
way.
The best solution would be to force all #declares to end with a semicolon,
so the parser knows exactly when the directive is complete and it can return
from Parse_Directive() without having to have that messy loop and special
re-entry flag. Of course, that would break more scenes, but I think it
would be best. It would also add consistency to the parser, because now you
need a semicolon for #declaring floats and vectors, but you CANNOT have a
semicolon when declaring arrays, textures, pigments, etc. That semicolon
would be useful for avoiding accidental layered textures, too.
-Nathan
Post a reply to this message
|
![](/i/fill.gif) |