What is the meaning of a naked type?

The BNF allows for the following statement:

int;

What is its meaning??

Similarly, this is also legal syntax according to the BNF.

void main(){
      int a=3;
      void bar();
      a+=2;
}

What is the meaning/purpose of a function prototype declared within a function??

The grammar is not a full description of valid shader code. There are semantic rules as well.

Thanks… but this seems very sloppy language definition to me.

Why should syntax be allowed for which there is no valid semantic meaning?

These questions are motivated by the fact that I am writing a glsl compiler right now. Knowing that these constructions are meaningless I will probably tighten up the syntax.

Just because the syntax matches the BNF doesn’t mean that it has meaning.

Almost all language specs are like that. Take C++ for example; It pains me that I’m not allowed to write:


   x ^= y ^= x ^= y ;

It’s syntactically legal according to BNF but semantically it’s totally illegal and gets you a compilation error. (Because the C++ spec says that you aren’t allowed to change the value of a variable more than once in a single expression…a restriction that cannot be expressed in BNF).

I’ll leave it as an “exercise for the reader” to figure out why that particular statement would be so useful (x and y are integers).

– Steve

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.