Compiler's source code

Hi,

I have a question where I could check how the Elixir / Erlang compiler works? Is there any public source code or is it top secret? :wink:

1 Like

Ok so you have to be level over 9000 to see the source code of either
 nope :wink:

All is on Github. Elixir’s public repo is here:

and Erlang’s:

Both repositories contain compiler as well as some core tools + standard libraries.

2 Likes

Hehe I saw the repos :slight_smile: I just expected something more than I found :smiley: Anyway, thanks :slight_smile:

1 Like

oh well. In Erlang peek into lib/compiler. Elixir hasn’t got dedicated directory I think but you can follow the “mix compile” task execution from https://github.com/elixir-lang/elixir/blob/master/lib/mix/lib/mix/compilers/elixir.ex to locate relevant code. Most of the compiler compiler thing is in written in Erlang I believe: https://github.com/elixir-lang/elixir/tree/master/lib/elixir/src

2 Likes

You are correct. Elixir is parsed using the Leex Lexical Analizer Generator and the Yecc Parser Generator.

The grammar file that Yecc will use to parse Elixir code is elixir/lib/elixir/src/elixir_parser.yrl at main · elixir-lang/elixir · GitHub. This is the place where things like operator precedence are stated, and is probably what you were looking for. :slight_smile:

It’s interesting to note that Elixir’s grammar is quite small, as nearly everything that seems a ‘keyword’ in Elixir is actually just a macro or a function. The only things that are bootstrapped in Erlang to allow the Kernel elixir module to compile are found in the elixir_bootstrap.erl module: elixir/lib/elixir/src/elixir_bootstrap.erl at main · elixir-lang/elixir · GitHub

It’s quite interesting to see how e.g. defmodule is implemented in the Kernel module itself.

1 Like