You probably should read a good book on compiler construction.
The "Dragon Book"
] is a good (theoretical) one.
On the other hand, for an informal, practical approach, I suggest the Crenshaw's Let's buld a compiler
There are also some 'compiler generator tools' available (ANTLR
] being probably the most famous).