Concept:
Compilers analyze programs in multiple stages, moving from raw text to logical meaning.
• Syntax: Checks if the "structure" is correct (like grammar in English).
• Semantics: Checks if the "meaning" is correct (logic, types, declarations).
Step 1: Defining the scope of Syntax Analysis.
The parser (syntax analyzer) only ensures that statements like x = 10; are valid.
It does not care if 'x' was actually defined as an integer earlier.
Step 2: Defining the scope of Semantic Analysis.
The Semantic analyzer uses a "Symbol Table."
It checks if every variable used in an expression has been declared.
It also verifies that the type of the variable matches the operation.
Step 3: Final Identification.
Checking whether a variable is "known" to the program is a task of logic and meaning.
Thus, Semantic Analysis is the correct phase for declaration checking.