Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No; if "c" is not a type, then there are no grammar rules which will allow you to produce that statement. So, as you parse that text, when you get to "c", you have to ask, "Is 'c' a type?" The answer you get will determine which subsequent grammar rules you apply. That context - having to know something about "c" that was described elsewhere - isn't technically semantics. It's an assertion just that "c" appeared elsewhere in the text, and when we parsed it, it was in a particular location in the grammer (which just so happens to mean it is a type - but the parser doesn't need to know what that means).

An example of syntactically correct, but semantically undefined code is:

  *(static_cast<int*>(NULL)) = 42;
The difference between here and above is that there is nothing in the grammar that can tell you "this is an error". It's only an error because of the semantics that we've given to the operations.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: