The Parse Tree (AST)

Dhruv Makwana edited this page Feb 7, 2017 · 1 revision

This section gives an overview of the files in the parsing directory of the OCaml repo.

As explained in the Source code section, an .mly file is used to generate a parser for a specified grammar.

parsing/parser.mly has the full specification of the grammar.

The source code is transformed into an Abstract Syntax Tree, specifically, this one in parsing/parsetree.mli.

The file is well commented (if not, contribute, or edit this page!) but this is a quick rundown of the main features of the AST.

  • constant: integer, character, string and float literals.
  • attribute: attributes are “decorations” of the syntax tree which are mostly ignored by the type-checker but can be used by external tools and are made of an identifier and a payload (any unrecognised ones are ignored)
  • extension: extensions are generic placeholders in the syntax tree - rejected by the type-checker and are intended to be “expanded” by external tools such as -ppx rewriters.
  • payload: contents of an attribute or an extension - a structure, signature, type or a pattern.

Now we get into the core language expressions [incomplete].

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.