How code becomes an app on your phone

Software13 seconds

The code a developer writes is just text. See how compilers and interpreters turn it into instructions your phone's processor can actually run.

Key takeaways

  1. A lexer splits source code into tokens: names, numbers and symbols.

  2. A parser arranges tokens into a syntax tree and catches grammar errors.

  3. Compilers optimize an intermediate form, then emit machine code for one chip.

  4. Interpreters and JIT compilers translate code while the program runs.

The code a developer writes is plain text in a file, and a processor cannot read it. Between the keyboard and the app on your phone sits a chain of tools that translates human-friendly language into the raw instructions a chip understands. Here is that chain, one stage at a time.

Step 1: Text becomes tokens

The first stage, the lexer, reads the source code character by character and groups it into tokens: keywords, names, numbers and symbols. A line like total = price * 2 becomes five tokens: a name, an equals sign, another name, a multiplication sign and a number. Spaces and comments are usually discarded here.

Step 2: Tokens become a syntax tree

Next, the parser checks the tokens against the grammar of the language and arranges them into an abstract syntax tree. For our example, the tree says: assign to total the result of multiplying price by 2. This is where a missing bracket becomes a syntax error.

The compiler then checks meaning, not just grammar. Does price exist? Is it a type of value you can multiply? Many bugs are caught at this point, before the program ever runs.

Step 3: An intermediate form gets optimized

The tree is lowered into an intermediate representation, or IR: a simple, uniform language that sits between the source code and any particular chip. Compiler toolkits such as LLVM do much of their heavy lifting here, running optimization passes that, for example:

  • remove code that can never run,
  • work out constant values ahead of time instead of at every launch,
  • copy small functions directly into the code that calls them.

Because the IR is independent of the processor, the same optimizations help whether the app ends up on a phone, a laptop or a server.

Step 4: Machine code, or translation on the fly

A back end translates the IR into machine code for one processor family, such as ARM in most phones or x86 in many PCs. A linker then combines it with libraries into a package the operating system can load. This is ahead-of-time compilation, used by languages like C, Rust and Swift.

Not every language works that way. An interpreter reads a program and carries it out step by step, which is flexible but slower. Many modern runtimes use a just-in-time (JIT) compiler: they start by interpreting, notice which parts run most often, and compile those hot paths into machine code while the program runs. Browser JavaScript engines work like this. Android apps are a mix: they ship as bytecode, and the phone compiles it to machine code, partly ahead of time on the device and partly while the app runs.

Why it matters

This pipeline is why one program can run on very different hardware, why a compiled game starts instantly while a script is easy to tweak, and why a single typo can stop an entire build. Every app you open went through some version of this chain before it reached your screen.

All explainers

Loading related explainers