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

Halunke, or: How and why I built a programming ...

Halunke, or: How and why I built a programming language

Lucas Dohmen will tell you the story of why and how he built Halunke. We will first learn about the motivation for building a toy programming language that explores the boundaries between functional and object oriented programming. We will then dive into the language, its features and see a quick demo in the interactive REPL. In the second part of the talk, we will get into the nitty-gritty of Halunke’s Open Source Ruby implementation.

Lucas Dohmen

March 14, 2018
Tweet

More Decks by Lucas Dohmen

Other Decks in Programming

Transcript

  1. •All objects are immutable •A reference created with ‘a can’t

    be reassigned •In the future, there will be reassignable references with @a
  2. No nil/null REPL Define own functions Define own classes Conditionals

    are messages, not syntax Number, String, Array, Dictionary, Regexp Web Module & a tiny Routing Lib
  3. ('a = 12) ('my = "str") ("hello" replace (my replac

    "i" wit "a") with "mumpf") (stdio puts "a") Currently in Development 4 | ("hello" replace (my replac "i" wit "a") with "mumpf") ^^^^^^^^^^^^^^^^^^^^^^^ The String "str" received the message `replac wit`. It doesn't know how to handle that. Did you mean `replace with`?
  4. => [[:OPEN_PAREN, “(“], [:STRING, “Halunke“], [:BAREWORD, “replace“], [:STRING, “Ha“], [:BAREWORD,

    “with“], [:STRING, “Spe“], [:CLOSE_PAREN, “)“]] a = Halunke ::Lexer.new a.tokenize(‘ ‘) (“Halunke“ replace “Ha“ with “Spe“) Lexer
  5. Lexer (with Ragel) string = '"' [^"]* '"'; bareword =

    [a-zA-Z_]+ | '+' | '-' | '*' | '/' | '<' | '>' | '=' | '@'; open_paren = '('; close_paren = ')'; 1. Define Tokens
  6. Lexer (with Ragel) 2. React to tokens string => {

    emit(:STRING, data[ts+1 ...te-1]) }; bareword => { emit(:BAREWORD, data[ts ...te]) }; open_paren => { emit(:OPEN_PAREN, data[ts ...te]) }; close_paren => { emit(:CLOSE_PAREN, data[ts ...te]) }; space; any => { raise "Could not lex ' #{ data[ts ...te] }'" };
  7. Parser b = Halunke ::Parser.new b.parse('("Halunke" replace "Ha" with “Spe")')

    => #<struct Halunke ::Nodes nodes=[ #<struct Halunke ::MessageSendNode receiver=#<struct Halunke ::StringNode value=“Halunke">, message=#<struct Halunke ::MessageNode nodes=[ #<struct Halunke ::BarewordNode value=“replace">, #<struct Halunke ::StringNode value=“Ha">, #<struct Halunke ::BarewordNode value=“with">, #<struct Halunke ::StringNode value=“Spe"> ]> > ]>
  8. Parser (with racc) Program: Expressions { val[0] } ; Expressions:

    /* empty */ { Nodes.new([]) } | Expression Expressions { Nodes.new([val[0]].concat(val[1].nodes)) } ; Expression: STRING { StringNode.new(val[0]) } | BAREWORD { BarewordNode.new(val[0]) } | OPEN_PAREN Expression Expressions CLOSE_PAREN { MessageSendNode.new(val[1], val[2].to_message) } ;
  9. Regular C ontext Free C ontext Sensitive Recursively Enum erable

    Chomsky hierarchy Finite Statem achine Pushdow n Autom aton Linear-bounded non-determ inistic Turing m achine Turing M achine More powerful, less guarantees, less performance
  10. Regular C ontext Free Chomsky hierarchy Finite Statem achine Pushdow

    n Autom aton More powerful, less guarantees, less performance
  11. Regular C ontext Free Chomsky hierarchy Regular Expressions C ontext

    Free G ram m ar More powerful, less guarantees, less performance