Because of the complexity of the transformation, the compilation process is partitioned into a series of compilation phases . The following figure shows a typical structure of a compiler. Lexical analysis and syntax analysis. The lexical analysis is done by the so-called scanner . During this phase, characters of the source program which logically belong together are grouped into character groups known as tokens .
Tokens are for instance keywords, identfiers, and operators.
The scanner passes on a linear stream of tokens to the next phase. The syntax analysis is done by the so-called parser . The tokens from phase 1 are grouped into syntactic structures using the syntax rules of the language being translated. Either interleaved with syntax checks or implemented as another subphase comes a series of semantic checks where the meanings of the syntactic structures are validated. Lexical analysis of Java programs Lexical analysis can sometimes appear ambigous.