A compiler is a program that translates source code written in one programming language into another language. It performs two main tasks: analysis of the source program and synthesis of a machine-language program. The structure of a compiler typically includes a scanner, parser, semantic routines, code generator, and optimizer. The scanner reads the source code and groups characters into tokens. The parser checks the syntax against a grammar. Semantic routines perform static checking and translation. The code generator produces target code, which may then be optimized. An example compiler output is shown translating a sample program into assembly code.