A compiler is a program that takes instructions written in a programming language, like C++, and converts them into instructions that a computer can understand, like "01100100 01011001".
It's like a translator - it transforms words (in this case, code words) into something else. A compiler is necessary because a computer only speaks machine language - it needs someone to translate so it can understand what to do.
Compilers are very clever and can take all the instructions written in a programming language, break them down and understand each one. It then takes each instruction and translates it into machine language, making sure it follows the rules of the programming language. This can be quite hard, as machine language is very specific, so the compiler has to be very precise.
Once the compiler has translated the instructions, it combines them all into a single file - a machine code program. This is what the computer can run to do whatever the programmer wanted it to do!