Compiler is a program that reads a program written in one language (the source language) and translates it into an another equivalent program in another language (the target language), mostly machine language.
There are different phases of compiler through which your source language code is scanned line by line. There is a symbol table which keeps the track of all Keywords which are scanned for in source language code.
Phase 1 : Lexical Analyzer - reads all the character in source program and forms the
logical separation of tokens (int, char, float, if-else,for,while etc.)
Phase 2 : Syntax Analyzer - analyze the structure of stream of tokens. Hierarchical
parsing of expressions which includes postfix/prefix etc.
(a=b+c*d)
Phase 3 : Semantic Analyzer - Type checking of tokens (integer to real, float etc.) and
many things like operator precedence etc..
Phase 4 : Intermediate Code Generator -
a=b+c*d-e(temp1=c*d, temp2=temp1+b, temp3=temp2-e)
Phase 5 : Code Optimization - Various Analysis (control flow, data flow, transformations)
which eleminates : Redundancy code, Constants propogation, Partial dead code,
common subexpression, Loop invariant code
Phase 6 : Code Generation - Generation of target code (Mostly Assembly Language) putting
values in Registers
All these phases are nothing but well written programs and there could be N number of flaws in that..