POV-Ray : Newsgroups : povray.general : Array and Macro problem (again) : Re: Array and Macro problem (again) Server Time
2 Aug 2024 22:12:03 EDT (-0400)
  Re: Array and Macro problem (again)  
From: Tor Olav Kristensen
Date: 20 Aug 2004 11:46:39
Message: <41261cdf$1@news.povray.org>
Thorsten Froehlich wrote:

> In article <412486bc$1@news.povray.org> , Tor Olav Kristensen 
> <tor### [at] TOBEREMOVEDhotmailcom>  wrote:
> 
> 
>>Hmmm... I see that it works when I add a semicolon,
>>but I can not see any error messages or warnings about
>>a missing semicolon.
> 
> 
> This has nothing to do with the array declaration per se and no warning
> should be expected either.  It has to do with the declaration being returned
> before POV-Ray can know that it is complete.  This applies to all
> declarations.  If you would add another declare or anything else prior to
> returning the just declared value, POV-Ray would also know that your
> declaration was complete.  The semicolon is indeed optional if you do not
> need it to disambiguate your statement, but POV-Ray cannot guess what you
> intended in an ambiguous case.  Consequently, adding the semicolon makes
> clear what you want to do and the macro works properly.
> 
> This is what the manual states as you quoted it.  It is not possible to list
> all possibly ambiguous cases one can create that do require a semicolon.
> Hence the manual only tells you to add it when a macro does not work as
> expected.  The error message actually says this implicitly as it tells you
> "AA" is not initialized, because that is indeed the case.  Together with the
> manual that implies a semicolon finalizes any declaration, adding the
> semicolon is the logical course of action.
> 
> I agree that this concept is not easy to understand, but it is entirely
> logical once you fully understood the concept of declarations and how macros
> return values.

Thank you for your aswer Thorsten.

I have been thinking about this for a while now.
Although I believe that I now understand where
semicolons are needed, I can't understand how that
first declarations can be ambiguous:

   #local AA = array[1] { 1 }

Isn't the closing curly bracket clearly marking the
end of the declaration ?

And if there are other pairs of curly brackets
within the declaration, like this:

#macro Tast()
   #local AA = array[1] { sphere { 0*y, 1 } };
   AA
#end // macro Tast

Isn't it then sufficient for a parser to make sure
that every opening bracket has a corresponding
closing one ? (The last matching closing one would
then indicate the end of the declaration.)

Please explain more. (I dont know much about parsing.)


Btw.:
Yesterday I read a chapter in "Java in a nutshell"
(3rd edition, p.67) and there I stumbled upon this
example:

int[] powersOfTwo = { 1, 2, 4, 8, 16, 32, 64, 128 };

"There is a semicolon following the close curly brace
in this array literal. This is one of the fine points
in Java syntax. When curly braces delimit classes,
methods, and compound statements, they are not
followed by semicolons. However, for this array literal
syntax, the semicolon is required to terminate the
variable declarations statement."

It seems that the requirements are similar to the ones
of Java, but unfortunately the book does not explain
further.

-- 
Tor Olav
http://subcube.net
http://subcube.com


Post a reply to this message

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