|
|
Warp <war### [at] tagpovrayorg> wrote:
> Is there any good reason why reserved keywords should not be
> allowed as identifier names?
With a few exceptions, most programming languages does not allow that.
The exceptions are dynamic languages. I only can think of Lisp, but I'm sure
there's a lot of them. In these cases, the parser represents "keywords" as
function names which can be redefined. That way, you lose in optimization
of code.
> 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)?
Yes:
#declare fresnel = 0;
#declare MyFinish = finish { reflection { 0.5 metallic fresnel } };
The parser wont know if it's supposed to be:
#declare MyFinish = finish { reflection { 0.5 metallic 0 } };
or
#declare MyFinish = finish { reflection { 0.5 metallic on fresnel on } };
because the boolean value could be omitted.
Of course this can be changed. But it's always complicated to guarantee that
the parser (or the programmer) wont be confused.
> The parser will have to look ahead (...)
If I'm not mistaken, the current parser of POVRay SDL does not allow
lookaheads.
This would imply the total re-writing of the grammar to migrate to a parser
that supports lookahead.
> 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.
The doc's are out there to be read :P
I think a good keyword name never conflicts with good variable names.
For instance, a variable named "if" doesn't mean anything.
Of course, in POV-Ray some keywords do mean something (like the sphere
keyword). This is really a problem from the users point of view.
Maybe an alternative solution is to use some operator to refer to variables,
as $ in PHP.
Post a reply to this message
|
|