POV-Ray : Newsgroups : povray.advanced-users : Allowing reserved keywords to be used as identifier names? : Allowing reserved keywords to be used as identifier names? Server Time
28 Jul 2024 18:24:06 EDT (-0400)
  Allowing reserved keywords to be used as identifier names?  
From: Warp
Date: 30 May 2004 23:03:27
Message: <40baa07f@news.povray.org>
The problem someone was having with some include file choking on
POV-Ray 3.5 because it used an identifier named 'size' which is a
reserved keyword in POV-Ray 3.5 got me thinking about one thing:

  Is there any good reason why reserved keywords should not be
allowed as identifier names?

  The only reason I can think of is that it makes the implementation
of the parser more complicated. Developers may well think this is good
enough to not to support (and I suppose this is justified), but if we
think about it from the user's and the SDL syntax point of view, would
there be any potential problem with that?

  If you think about it, is there any place where there could be
ambiguity whether a name is a keyword or an identifier (specially
when we know that if it's an identifier, what is its type)?

  For instance, suppose we have this:

#declare sphere = 5;

#declare Obj = sphere { 0, 1 };
#declare Val = sphere;

  The parser will have to look ahead and see that in the second #declare
if 'sphere' is taken as a float identifier it will result in a syntax
error, but if it's taken as the keyword for the sphere primitive, it
will work ok. Thus the parser chooses the meaning which does not cause
a syntax error. The same goes for the third #declare: As a keyword it
would produce a syntax error, but as a float identifier it won't, so
the parser would choose the meaning that does not produce the error.

  One could even write this:

#declare Obj = sphere { sphere, sphere };

  The parser would interpret 'sphere' as a primitive keyword where a
keyword is expected and as a float identifier where a float is expected.

  I can't think of any example where the parser could not unambiguously
decide which meaning to choose. And even if there would be, the parser
could simply issue an error in that case (something like "ambiguous use
of 'sphere'" or whatever).

  #macros are a special case in that the name of a macro could be any
reserved keyword except an internal function name (ie. sin, cos, etc).
This is naturally because calling an internal function has the same
syntax as calling a macro. However, there shouldn't be any problem in
having a #macro called 'sphere', for instance, because the syntax of
a macro call can't be confused with the creation of a sphere primitive.

  One could ask what would be the benefit from this. It only sounds as
an additional feature to make more obfuscated code.

  The benefit would be that if someone uses a certain name now, there
will be a bigger chance that his code will not break in future versions
of POV-Ray.

  I know, I know, someone will reply to this "just use identifier names
starting with a capital letter". The problem is that there are tens or
hundreds of thousands of people out there using POV-Ray and only a very
small percentage of them are reading this kind of good advice here.

  I'm not proposing that this should be implemented. I'm just thinking
out loud, sharing my random thoughts.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

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