Slide 1

Slide 1 text

How To Create Your Own Programming Language @aatrostle @aarontrostle

Slide 2

Slide 2 text

Source Material • How To Create Your Own Freaking Awesome Programming Language • http://createyourproglang.com/ • Written by Marc-André Cournoyer • Created Thin and tinyrb • Great for a weekend project

Slide 3

Slide 3 text

Four Parts of a Language • The Lexer • The Parser • The Interpreter • The Runtime

Slide 4

Slide 4 text

The Lexer • Also known as a “scanner” or “tokenizer” • Converts code you want to run into tokens • Splits code and tags each part with the type of token

Slide 5

Slide 5 text

Example Lexer Output turns into

Slide 6

Slide 6 text

The Parser • Reads tokens and produces a tree of nodes • Most common parser output is an Abstract Syntax Tree (AST) • Parser generators are commonly used • In the book we use Racc, based on Yacc

Slide 7

Slide 7 text

Example Parser Output turns into

Slide 8

Slide 8 text

The Runtime • How we represent objects, methods, types and structures in memory • Defines how a language behaves • Many ways to model a runtime

Slide 9

Slide 9 text

Runtime Models • Procedural - ex. C or PHP (before version 4) • Centered around methods • No objects • Class-based - ex. Java, Python, Ruby • Easier to understand for your users • Prototype-based - ex. Javascript • Easier to implement • Most flexible because everything is a clone of an object • Functional - ex. Lisp • Treats computation as evaluation of mathematical functions

Slide 10

Slide 10 text

The Interpreter • Module that evaluates the code • Reads the AST produced by the parser • Executes each action associated with the nodes and modifies the runtime

Slide 11

Slide 11 text

Questions? @aatrostle @aarontrostle