PDA

View Full Version : What is the meaning of a naked type?



jeffpk
04-10-2011, 08:42 PM
The BNF allows for the following statement:

int;

What is its meaning??

jeffpk
04-11-2011, 09:38 AM
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??

Xmas
04-12-2011, 07:46 AM
The grammar is not a full description of valid shader code. There are semantic rules as well.

jeffpk
04-14-2011, 07:27 PM
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.

SteveBaker
04-14-2011, 08:44 PM
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