Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How To Create Your Own Programming Language

How To Create Your Own Programming Language

A recent talk I gave in my Code Fellows class covering what I learned in the "How To Create Your Own Freaking Awesome Programming Language" by Marc-André Cournoyer.

Aaron Trostle

June 17, 2013
Tweet

More Decks by Aaron Trostle

Other Decks in Technology

Transcript

  1. 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
  2. Four Parts of a Language • The Lexer • The

    Parser • The Interpreter • The Runtime
  3. 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
  4. 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
  5. The Runtime • How we represent objects, methods, types and

    structures in memory • Defines how a language behaves • Many ways to model a runtime
  6. 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
  7. 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