POV-Ray : Newsgroups : povray.general : Array and Macro problem (again) Server Time
6 Nov 2024 06:21:48 EST (-0500)
  Array and Macro problem (again) (Message 1 to 6 of 6)  
From: Tor Olav Kristensen
Subject: Array and Macro problem (again)
Date: 18 Aug 2004 21:38:16
Message: <41240488$1@news.povray.org>
Can you people try this code and see if you get the same
error message as me ?


#version 3.6;

// Does not work
#macro Test()
   #local AA = array[1] { 1 }
   AA
#end // macro Test

// Works
#macro Tust()
   #local AA = array[1]
   #local AA[0] = 1;
   AA
#end // macro Tust

// Works
#macro Tist()
   array[1] { 1 }
#end // macro Test

#declare BB = Test()


I get this error message:

File: E:\Raytracinger\Untitled.pov  Line: 6
File Context (5 lines):
   #local AA = array[1] { 1 }
   AA
Parse Error: Cannot assign uninitialized identifier.


POV-Ray for Windows Version 3.6.1.icl8.win32
Athlon XP2400 PC with 512MB RAM
Windows 2000 Professional v5.0.2195 Service Pack 2 Build 2195

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


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Array and Macro problem (again)
Date: 18 Aug 2004 22:10:21
Message: <41240c0d$1@news.povray.org>
Tor Olav Kristensen wrote:

> 
> Can you people try this code and see if you get the same
> error message as me ?
> 
> 
> #version 3.6;
> 
> // Does not work
> #macro Test()
>   #local AA = array[1] { 1 }
>   AA
> #end // macro Test
> 
> // Works
> #macro Tust()
>   #local AA = array[1]
>   #local AA[0] = 1;
>   AA
> #end // macro Tust
> 
> // Works
> #macro Tist()
>   array[1] { 1 }
> #end // macro Test
> 
> #declare BB = Test()
> 
> 
> I get this error message:
> 
> File: E:\Raytracinger\Untitled.pov  Line: 6
> File Context (5 lines):
>   #local AA = array[1] { 1 }
>   AA
> Parse Error: Cannot assign uninitialized identifier.
> 
> 
> POV-Ray for Windows Version 3.6.1.icl8.win32
> Athlon XP2400 PC with 512MB RAM
> Windows 2000 Professional v5.0.2195 Service Pack 2 Build 2195

I just tried the same on my Linux PC and got the same result.

Official POV-Ray for Linux Version 3.6.0 (g++ 3.4.0 @ i686-pc-linux-gnu)
Athlon XP1800 PC with 512MB RAM
Red-Hat v9.0

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


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Array and Macro problem (again)
Date: 19 Aug 2004 01:57:20
Message: <41244140@news.povray.org>
In article <41240488$1@news.povray.org> , Tor Olav Kristensen 
<tor### [at] TOBEREMOVEDhotmailcom>  wrote:

>    #local AA = array[1] { 1 }

You are missing a semicolon...

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Array and Macro problem (again)
Date: 19 Aug 2004 06:53:48
Message: <412486bc$1@news.povray.org>
Thorsten Froehlich wrote:
> In article <41240488$1@news.povray.org> , Tor Olav Kristensen 
> <tor### [at] TOBEREMOVEDhotmailcom>  wrote:
> 
> 
>>   #local AA = array[1] { 1 }
> 
> 
> You are missing a semicolon...

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.

Here's what the manual says:

http://www.povray.org/documentation/view/3.6.1/237/

   Note: that there should be a semi-colon after the
   expression in all float, vector and color identifier
   declarations. This semi-colon is introduced in POV-
   Ray version 3.1. If omitted, it generates a warning
   and some macros may not work properly. Semicolons
   after other declarations are optional.

 From this I understand that a semicolon after an array
declaration is optional.

Or is it so that if the array declaration contains
floats, vectors or colors, then one has to use semi-
colons ?

If so then I suggest that this is written more expli-
citly in the manual.

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


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Array and Macro problem (again)
Date: 19 Aug 2004 07:20:14
Message: <41248cee@news.povray.org>
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.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Array and Macro problem (again)
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.