This is how a compiler works -
Lexing - break up the text of the program into "tokens"
Parsing - convert the sequence of tokens into a parse tree, which is a data structure representing various language constructs: type declarations, variable declarations, function definitions, loops, conditionals, expressions, etc.
Optimization - evaluate constant expressions, optimize away unused variables or unreachable code, unroll loops if possible, etc.
Translate the parse tree into machine instructions (or JVM byte code)