# Does checking for correctness belong predominantly to "semantic analysis"?

Does checking for correctness belong predominantly to "semantic analysis"?

Or is it reasonable to be done in earlier phases (in a compiler like construction) as well? Mainly in syntax analysis. Or is syntax analysis often/always "formal", rather than semantical?

http://courses.cs.vt.edu/cs1104/Compilers/Compilers.020.html

• Checking for correctness of what? "Correctness" of a program usually means that it meets whatever specification it was designed to meet. That's not something the compiler is interested in. Dec 30 '15 at 17:23
• @DavidRicherby I believe the semantic analysis phase is to verify that the computations done are "rational". Whereas syntax analysis merely verified that the program contains syntactically valid sentences. Dec 30 '15 at 17:38
• So "correctness" of whatever is deemed correct semantics. Dec 30 '15 at 17:38
• "Correctness" of what? The program being compiled vs some specification? Completely outside the scope of a compiler. Dec 30 '15 at 19:01

2. Correctness of semantics. During the semantical analysis the compiler rejects statements that are syntactically correct, but are nonsensical semantically. E.g. 10 / "blue".
However, it is not that black and white, as compilers will often warn about lexically and semantically perfectly legal constructs that are likely to be misinterpreted, e.g. in C++ an assignment inside a conditional:if (x = 5) ....