Syntax Analysis: Checks out if the code follows the given CFG or not, i.e., it just checks the given code for typing errors based on the programming language's rules. For eg., if we miss a terminator/semicolon at the end of a C program's statement then it will be a syntax error because C requires its each statement/line to end with a terminator symbol. And for this purpose, a parse tree is generated on the basis of the given CFG.
Semantic analysis: Checks the meaning & usefulness of the program, i.e., type checking. It is better understood by examples:
1. x=a+b*c;
Now "x" can't be a constant or an array.
2. int a[3]={1,2,3};
int b[3]=a[3];
This is invalid because an array can not be directly assigned to some other array. This is semantically wrong but its syntax is alright.
While semantic analysis certainly can not check all possible meanings of all codes so it has its own limitations. But in reality, all these phases have vague lines to differentiate them. Compilers are implemented just as frontend(analysis phase) and backend(synthesis phase). That's why all operations of lexical, syntax & semantic analysis are merged and it is hard to say what happened in which phase unless we know how the compiler itself was implemented at the first phase. One could try checking out output after each phase(there are specific terminal commands for them) but then this could vary when checked on a different machine.
NOW, coming to your questions:
1. Parse tree will be generated for it but it won't be semantically verified because it is meaningless. It is like those examples I gave above in semantic analysis. Thus, this error is only found out in semantic analysis phase.
2. I am hearing this for the first time that a parse tree is not generated for simple declarative sentences. I think int a; will also generate a parse tree. Please provide a link of where you read it, I could be wrong.
3. If an undefined symbol is used without creating a syntax error then it is found out in semantic analysis because syntax analysis just checks the rules of a programming language but not its meaning. But it is vague(maybe wrong) to say so because syntax and semantic phase, as said previously, are implemented together.
4. It is detected in lexical analysis phase. Errors detected by lexical analysis phase:
- Numeric literals too long. Eg. int a=12345678; (exceeding integer range)
- Long identifiers
- Badly formed numeric literals. Eg. int a=$123; ($ not allowed)
- Input characters that are not in the same language. Eg., On a english fixed (only) compiler, one entered/copied a Hindi letter.