I asked how the compiler works. I looked through several books, and they all agree that the compiler phases roughly correspond to this (correct me if I am wrong): lexical analysis, parsing, semantic analysis, intermediate code, code optimization, code generation. The lexical and syntactic phases look quite clear and understandable as methods (but this, of course, does not mean that it is easy). However, I still cannot find what really is in the semantic phase. Firstly, I know that there must be some sub-phases, such as scope checking, declaration checking, and type checking, but the question that bothered me is this: are there other things that need to be done. Can you tell me what are the necessary steps to take at this stage. I know that this depends heavily on the programming language and implementation of the compiler, but could you give a few examples regarding C / C ++, Java. And could you please point me to a book / page / article where I can read these things in depth. Thanks.
Edit: The books I looked at were Compilers: Principles, Methods, and Tools, Aho and Modern Compiler Design, Grunet, Reywijk. I could not answer this question using them. If you find this question is too broad, you can give an answer by considering the implementation of the compiler of your choice for C, C ++ or Java.
svs source share