SlideShare a Scribd company logo
Developing
                                 a
                             Language
                            @evanphx     github.com/evanphx

                              Evan Phoenix Feb 5th, 2011




Tuesday, February 8, 2011
#11
Tuesday, February 8, 2011
LA.RB
                               Los Angeles Ruby Brigade

                            Tuesday Night. Every Week.
                                    http://rb.la




Tuesday, February 8, 2011
DINNER


Tuesday, February 8, 2011
DINNER

Tuesday, February 8, 2011
DINNER
Tuesday, February 8, 2011
DINNER
Tuesday, February 8, 2011
Which came first?


Tuesday, February 8, 2011
Language > Idea


Tuesday, February 8, 2011
Language < Idea


Tuesday, February 8, 2011
Language = Idea


Tuesday, February 8, 2011
The programmer, like the poet,
                            works only slightly removed
                            from pure thought-stuff.

                                                 - Fred Brooks




Tuesday, February 8, 2011
If ideas are a
                       manifestation of
                           language


Tuesday, February 8, 2011
Can better
                  language lead to
                    better ideas?


Tuesday, February 8, 2011
better
                              !=
                            newer


Tuesday, February 8, 2011
Tuesday, February 8, 2011
To craft a language from
                            scratch is to take 95% from the
                            past and call it groundbreaking.

                                                 - Evan Phoenix




Tuesday, February 8, 2011
Peek back


Tuesday, February 8, 2011
Tuesday, February 8, 2011
RLK

Tuesday, February 8, 2011
RLK
                            Implement with ease




Tuesday, February 8, 2011
RLK
                            KPeg




Tuesday, February 8, 2011
RLK
                                  KPeg
                            A new parsing library




Tuesday, February 8, 2011
Prattle < RLK

Tuesday, February 8, 2011
URLs

             In the Building

                      git://192.168.2.88/prattle
             In the Cloud

            github.com/evanphx/prattle.git

                   github.com/evanphx/kpeg.git




Tuesday, February 8, 2011
Tuesday, February 8, 2011
Dude.
                            Really?




Tuesday, February 8, 2011
Prattle


Tuesday, February 8, 2011
self
                            true
                            false
                             nil

Tuesday, February 8, 2011
+module Prattle
                            + module AST
                            +    class Self < AST::Node
                            +      Prattle::Parser.register self
                            +
                            +      def self.rule_name
                            +        "self"
                            +      end
                            +
                            +      def initialize
                            +        # Nothing.
                            +      end
                            +
                            +      def self.grammar(g)
                            +        g.self = g.str("self") { Self.new }
                            +      end
                            +    end
                            + end
                            +end




Tuesday, February 8, 2011
+module Prattle
                            + module AST
                            +    class Self < AST::Node
                            +      Prattle::Parser.register self
                            +
                            +      def self.rule_name
                            +        "self"
                            +      end
                            +
                            +      def initialize
                            +        # Nothing.
                            +      end
                            +
                            +      def self.grammar(g)
                            +        g.self = g.str("self") { Self.new }
                            +      end
                            +    end
                            + end
                            +end




Tuesday, February 8, 2011
Self


                    def self.grammar(g)
                      g.self = g.str("self") {
                                 Self.new
                               }
                    end

    047b522




Tuesday, February 8, 2011
True


                    def self.grammar(g)
                      g.true = g.str("true") {
                                 True.new
                               }
                    end

    04ad51b




Tuesday, February 8, 2011
False


                    def self.grammar(g)
                      g.false = g.str("false") {
                                  False.new
                                }
                    end

    04ad51b




Tuesday, February 8, 2011
Nil


                    def self.grammar(g)
                      g.nil = g.str("nil") {
                                Nil.new
                              }
                    end

    7609e64




Tuesday, February 8, 2011
Number




                              0
                             10
                             42
                            10323

Tuesday, February 8, 2011
Number

              def self.grammar(g)
               g.number =
                  g.reg(/0|([1-9][0-9]*)/) {
                         |i|
                         Number.new(i.to_i)
                  }
              end

   a06d98c



Tuesday, February 8, 2011
Root


                    def self.grammar(g)
                     g.root = g.any(:true, :false,
                                    :self, :nil,
                                    :number)
                    end

    dfd78cb




Tuesday, February 8, 2011
root =   self
                                 |   true
                                 |   false
                                 |   nil
                                 |   number




Tuesday, February 8, 2011
REPL


Tuesday, February 8, 2011
REPL
                            Instant Gratification




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 42
                   #<Prattle::AST::Number:0x9c
                     @value=42>
                   > true
                   #<Prattle::AST::True:0x9d>




Tuesday, February 8, 2011
Self
                            def bytecode(g)
                              g.push :self
                            end




    4e4c1c9




Tuesday, February 8, 2011
True
                            def bytecode(g)
                              g.push :true
                            end




    4e4c1c9




Tuesday, February 8, 2011
False
                            def bytecode(g)
                              g.push :false
                            end




    4e4c1c9




Tuesday, February 8, 2011
Nil
                            def bytecode(g)
                              g.push :nil
                            end




    4e4c1c9




Tuesday, February 8, 2011
Number
                            def bytecode(g)
                              g.push @value
                            end




    4e4c1c9




Tuesday, February 8, 2011
String

             def self.grammar(g)
               not_quote = g.many(
                 g.any(escapes, /[^']/)) {
                     |*a| a.join
                 }
               g.string = g.seq("'",
                   g.t(not_quote), "'") {
                      |str| String.new(str)
                   }
             end

Tuesday, February 8, 2011
String

                  char =    escapes
                       |    [^’]
             not_quote =    char*
                string =    “‘“ not_quote “‘“




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 42
                   => 42
                   > true
                   => 42
                   > ‘hello’
                   => “hello”




Tuesday, February 8, 2011
BORING


Tuesday, February 8, 2011
Unary Send




                            3 class


Tuesday, February 8, 2011
Unary Send




                            3.class
                                      Ruby




Tuesday, February 8, 2011
Unary Send




                            3 class


Tuesday, February 8, 2011
Unary Send




                            3 class


Tuesday, February 8, 2011
Unary Send

            g.seq(:number, “ “,
                   :method_name) { |v,_,n|
                      UnarySend.new(v,n)
                 }




Tuesday, February 8, 2011
Unary Send


                  us = number “ “ method_name




Tuesday, February 8, 2011
Unary Send




            true class


Tuesday, February 8, 2011
Unary Send

            g.seq(:atom, “ “,
                   :method_name) { |v,_,n|
                      UnarySend.new(v,n)
                 }




Tuesday, February 8, 2011
atom =   true
                                 |   false
                                 |   self
                                 |   nil
                                 |   number
                                 |   string




Tuesday, February 8, 2011
Unary Send


                  us = atom “ “ method_name




Tuesday, February 8, 2011
Unary Send




                      3 class class



Tuesday, February 8, 2011
Unary Send

            g.any(
              g.seq(:unary_send, “ “,
                     :method_name) { |v,_,n|
                        UnarySend.new(v,n)
                   },
              g.seq(:atom, “ “,
                     :method_name) { |v,_,n|
                        UnarySend.new(v,n)
                   }
              )

Tuesday, February 8, 2011
Unary Send


                  us =   us “ “ method_name
                     | atom “ “ method_name




Tuesday, February 8, 2011
Unary Send

        def bytecode(g)
          @receiver.bytecode(g)
          g.send @method_name.to_sym, 0
        end




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 3 class
                   => Fixnum
                   > 3 class class
                   => Class
                   > ‘hello’ class
                   => String




Tuesday, February 8, 2011
Keyword Send



‘hello’ index: ‘o’




Tuesday, February 8, 2011
Keyword Send



“hello”.index(“o”)
                            Ruby




Tuesday, February 8, 2011
Keyword Send


g.keyword_send =
  g.seq(:atom, ‘ ‘,
        :method_name, “:”,
        “ “, :atom)




Tuesday, February 8, 2011
Keyword Send


   ks = atom “ “ method_name
          “: ” :atom




Tuesday, February 8, 2011
Keyword Send



‘hello’ at: 0
        put: ‘j’



Tuesday, February 8, 2011
Keyword Send



“hello”[0] = “j”
                            Ruby




Tuesday, February 8, 2011
Keyword Send



g.pairs =
  g.seq(:method_name, “:”,
        “ “, :atom)




Tuesday, February 8, 2011
Keyword Send


g.keyword_send =
  g.seq(
    :atom, ‘ ‘,
    g.many([:pair, ‘ ‘]),
    :pair
  )


Tuesday, February 8, 2011
Keyword Send


                ks = atom (pair ‘ ‘)+
                     pair




Tuesday, February 8, 2011
Keyword Send

           def bytecode(g)
             @receiver.bytecode(g)
             @arguments.each do |a|
               a.bytecode(a)
             end
             g.send @method_name.to_sym,
                    @arguments.size
           end



Tuesday, February 8, 2011
Keyword Send

           def bytecode(g)
             @receiver.bytecode(g)
             @arguments.each do |a|
               a.bytecode(a)
             end
             g.send @method_name.to_sym,
                    @arguments.size
           end



Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > ‘hello’ index: ‘o’

                   NoMethodError:
                     Unknown method ‘index:’




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > ‘hello’ index: ‘o’

                   NoMethodError:
                     Unknown method ‘index:’




Tuesday, February 8, 2011
Keyword Send



‘hello’ index: ‘o’




Tuesday, February 8, 2011
Keyword Send



     “hello”.send(
         “index:”, “o”
       )
                            Ruby




Tuesday, February 8, 2011
Keyword Send



‘hello’ ~index: ‘o’




Tuesday, February 8, 2011
Keyword Send

           def bytecode(g)
             if @method_name[0] == ?~
               ruby_style
             else
               smalltalk_style
             end
           end




Tuesday, February 8, 2011
Keyword Send



     “hello”.send(
         “index”, “o”
       )
                            Ruby




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > ‘hello’ ~index: ‘o’
                   => 4
                   NoMethodError:
                     Unknown method ‘index:’




Tuesday, February 8, 2011
Keyword Send



          obj string
                  at: 0
                 put: ‘j’


Tuesday, February 8, 2011
Keyword Send



          obj string
                  at: 0
                 put: ‘j’


Tuesday, February 8, 2011
Keyword Send



          obj string
                  at: 0
                 put: ‘j’


Tuesday, February 8, 2011
Keyword Send


g.keyword_send =
  g.seq(
    :atom, ‘ ‘,
    g.many([:pair, ‘ ‘]),
    :pair
  )


Tuesday, February 8, 2011
Keyword Send


g.keyword_send =
  g.seq(
    :atom, ‘ ‘,
    g.many([:pair, ‘ ‘]),
    :pair
  )


Tuesday, February 8, 2011
Keyword Send


                ks = atom (pair ‘ ‘)+
                     pair




Tuesday, February 8, 2011
Keyword Send




                            g.any(:atom,
                                  :unary_send)




Tuesday, February 8, 2011
Keyword Send


         recv = us | atom
           ks = recv (pair ‘ ‘)+
                pair




Tuesday, February 8, 2011
Block




                            [ 1 ]


Tuesday, February 8, 2011
Keyword Send


       g.block =
         g.seq(‘[‘, :expr, ‘]’)




Tuesday, February 8, 2011
Keyword Send



               expr = ks | us | atom




Tuesday, February 8, 2011
Keyword Send



                       block = “[“ expr “]




Tuesday, February 8, 2011
Block




                            [ 1. 2 ]


Tuesday, February 8, 2011
Keyword Send
       g.exprs =
         g.seq(:expr,
           g.kleene(‘.’,
                    :expr))




Tuesday, February 8, 2011
Keyword Send



                      exprs = (‘.’ expr)*




Tuesday, February 8, 2011
Keyword Send



                       block = “[“ exprs “]




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 10 ~times: [
                       Kernel ~puts: ‘hello’
                     ]




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 10 ~times: [
                       Kernel ~puts: ‘rb.la’
                     ]
                   “rb.la”
                   “rb.la”
                   “rb.la”
                   ...
                   => 10


Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 10 ~times: [ :x |
                       Kernel ~p: x
                     ]




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 10 ~times: [ :x |
                       Kernel ~p: x
                     ]
                   0
                   1
                   2
                   ...
                   => 10


Tuesday, February 8, 2011
Cascade Send



          ary concat: a;
              concat: b;
              concat: c


Tuesday, February 8, 2011
Operators




                            3 + 4 * 5




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 3 + 4 * 5




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 3 + 4 * 5
                   => 35




Tuesday, February 8, 2011
Parens



                   parens = “(“ expr “)




Tuesday, February 8, 2011
$ rbx bin/repl.rb
                   > 3 + (4 * 5)
                   => 23




Tuesday, February 8, 2011
zero to usable


Tuesday, February 8, 2011
BIG IDEA
Tuesday, February 8, 2011
little idea




Tuesday, February 8, 2011
Complex
                 Language
Tuesday, February 8, 2011
simple language




Tuesday, February 8, 2011
Thanks!

                            See ya out there.


Tuesday, February 8, 2011
MIA: Return


Tuesday, February 8, 2011
MIA: =


Tuesday, February 8, 2011

More Related Content

PDF
Developing a Language
PDF
JavaScript 101
PDF
Javascript, Do you speak it!
PDF
CPython 3.2 SourceCodeReading
PDF
What's Cooking in Xtext 2.0
PDF
Think like an ant, distribute the workload - PhpDay, Italy, 2011
POTX
Engine Yard Partner Program 2014
PDF
Rails Hosting and the Woes
Developing a Language
JavaScript 101
Javascript, Do you speak it!
CPython 3.2 SourceCodeReading
What's Cooking in Xtext 2.0
Think like an ant, distribute the workload - PhpDay, Italy, 2011
Engine Yard Partner Program 2014
Rails Hosting and the Woes

Viewers also liked (6)

PDF
Getting Started with PHP on Engine Yard Cloud
PDF
Introduction to Ruby
PDF
JRuby Jam Session
PPS
St Charles ©Tytel Mkt
PDF
Engine Yard Cloud Architecture Enhancements
PDF
Rubinius and Ruby | A Love Story
Getting Started with PHP on Engine Yard Cloud
Introduction to Ruby
JRuby Jam Session
St Charles ©Tytel Mkt
Engine Yard Cloud Architecture Enhancements
Rubinius and Ruby | A Love Story
Ad

Similar to Developing a Language (20)

PDF
Parser combinators
PDF
Of Rats And Dragons
PDF
lisp (vs ruby) metaprogramming
PDF
Ruby & Machine Vision - Talk at Sheffield Hallam University Feb 2009
PDF
Basic Regular Expressions
PDF
Text Manipulation with/without Parsec
PDF
Boost your-oop-with-fp
PDF
Python & Stuff
PDF
Erlang Introduction
PDF
Generating Assertion Code from OCL: A Transformational Approach Based on Simi...
PDF
A General Extension System for Event Processing Languages
PDF
The Enterprise Strikes Back
PDF
The Basis of Making DSL with Ruby
PDF
Appengine ja-night-10
PDF
Helvetia
PDF
PDF
Rcos presentation
PDF
Slaying the Dragon: Implementing a Programming Language in Ruby
PDF
Beyond the Basics: Regular Expressions in Ruby
Parser combinators
Of Rats And Dragons
lisp (vs ruby) metaprogramming
Ruby & Machine Vision - Talk at Sheffield Hallam University Feb 2009
Basic Regular Expressions
Text Manipulation with/without Parsec
Boost your-oop-with-fp
Python & Stuff
Erlang Introduction
Generating Assertion Code from OCL: A Transformational Approach Based on Simi...
A General Extension System for Event Processing Languages
The Enterprise Strikes Back
The Basis of Making DSL with Ruby
Appengine ja-night-10
Helvetia
Rcos presentation
Slaying the Dragon: Implementing a Programming Language in Ruby
Beyond the Basics: Regular Expressions in Ruby
Ad

More from Engine Yard (12)

PDF
6 tips for improving ruby performance
PDF
Simplifying PCI on a PaaS Environment
PDF
The Tao of Documentation
PDF
Innovate Faster in the Cloud with a Platform as a Service
PDF
JRuby: Enhancing Java Developers Lives
PDF
High Performance Ruby: Evented vs. Threaded
PDF
Release Early & Release Often: Reducing Deployment Friction
KEY
Rails Antipatterns | Open Session with Chad Pytel
PDF
JRuby: Apples and Oranges
PDF
Debugging Ruby Systems
KEY
Geemus
PDF
Everything Rubinius
6 tips for improving ruby performance
Simplifying PCI on a PaaS Environment
The Tao of Documentation
Innovate Faster in the Cloud with a Platform as a Service
JRuby: Enhancing Java Developers Lives
High Performance Ruby: Evented vs. Threaded
Release Early & Release Often: Reducing Deployment Friction
Rails Antipatterns | Open Session with Chad Pytel
JRuby: Apples and Oranges
Debugging Ruby Systems
Geemus
Everything Rubinius

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
Teaching material agriculture food technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Machine learning based COVID-19 study performance prediction
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Teaching material agriculture food technology
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars
Mobile App Security Testing_ A Comprehensive Guide.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Developing a Language

  • 1. Developing a Language @evanphx github.com/evanphx Evan Phoenix Feb 5th, 2011 Tuesday, February 8, 2011
  • 3. LA.RB Los Angeles Ruby Brigade Tuesday Night. Every Week. http://rb.la Tuesday, February 8, 2011
  • 8. Which came first? Tuesday, February 8, 2011
  • 9. Language > Idea Tuesday, February 8, 2011
  • 10. Language < Idea Tuesday, February 8, 2011
  • 11. Language = Idea Tuesday, February 8, 2011
  • 12. The programmer, like the poet, works only slightly removed from pure thought-stuff. - Fred Brooks Tuesday, February 8, 2011
  • 13. If ideas are a manifestation of language Tuesday, February 8, 2011
  • 14. Can better language lead to better ideas? Tuesday, February 8, 2011
  • 15. better != newer Tuesday, February 8, 2011
  • 17. To craft a language from scratch is to take 95% from the past and call it groundbreaking. - Evan Phoenix Tuesday, February 8, 2011
  • 21. RLK Implement with ease Tuesday, February 8, 2011
  • 22. RLK KPeg Tuesday, February 8, 2011
  • 23. RLK KPeg A new parsing library Tuesday, February 8, 2011
  • 24. Prattle < RLK Tuesday, February 8, 2011
  • 25. URLs In the Building git://192.168.2.88/prattle In the Cloud github.com/evanphx/prattle.git github.com/evanphx/kpeg.git Tuesday, February 8, 2011
  • 27. Dude. Really? Tuesday, February 8, 2011
  • 29. self true false nil Tuesday, February 8, 2011
  • 30. +module Prattle + module AST + class Self < AST::Node + Prattle::Parser.register self + + def self.rule_name + "self" + end + + def initialize + # Nothing. + end + + def self.grammar(g) + g.self = g.str("self") { Self.new } + end + end + end +end Tuesday, February 8, 2011
  • 31. +module Prattle + module AST + class Self < AST::Node + Prattle::Parser.register self + + def self.rule_name + "self" + end + + def initialize + # Nothing. + end + + def self.grammar(g) + g.self = g.str("self") { Self.new } + end + end + end +end Tuesday, February 8, 2011
  • 32. Self def self.grammar(g) g.self = g.str("self") { Self.new } end 047b522 Tuesday, February 8, 2011
  • 33. True def self.grammar(g) g.true = g.str("true") { True.new } end 04ad51b Tuesday, February 8, 2011
  • 34. False def self.grammar(g) g.false = g.str("false") { False.new } end 04ad51b Tuesday, February 8, 2011
  • 35. Nil def self.grammar(g) g.nil = g.str("nil") { Nil.new } end 7609e64 Tuesday, February 8, 2011
  • 36. Number 0 10 42 10323 Tuesday, February 8, 2011
  • 37. Number def self.grammar(g) g.number = g.reg(/0|([1-9][0-9]*)/) { |i| Number.new(i.to_i) } end a06d98c Tuesday, February 8, 2011
  • 38. Root def self.grammar(g) g.root = g.any(:true, :false, :self, :nil, :number) end dfd78cb Tuesday, February 8, 2011
  • 39. root = self | true | false | nil | number Tuesday, February 8, 2011
  • 41. REPL Instant Gratification Tuesday, February 8, 2011
  • 42. $ rbx bin/repl.rb > 42 #<Prattle::AST::Number:0x9c @value=42> > true #<Prattle::AST::True:0x9d> Tuesday, February 8, 2011
  • 43. Self def bytecode(g) g.push :self end 4e4c1c9 Tuesday, February 8, 2011
  • 44. True def bytecode(g) g.push :true end 4e4c1c9 Tuesday, February 8, 2011
  • 45. False def bytecode(g) g.push :false end 4e4c1c9 Tuesday, February 8, 2011
  • 46. Nil def bytecode(g) g.push :nil end 4e4c1c9 Tuesday, February 8, 2011
  • 47. Number def bytecode(g) g.push @value end 4e4c1c9 Tuesday, February 8, 2011
  • 48. String def self.grammar(g) not_quote = g.many( g.any(escapes, /[^']/)) { |*a| a.join } g.string = g.seq("'", g.t(not_quote), "'") { |str| String.new(str) } end Tuesday, February 8, 2011
  • 49. String char = escapes | [^’] not_quote = char* string = “‘“ not_quote “‘“ Tuesday, February 8, 2011
  • 50. $ rbx bin/repl.rb > 42 => 42 > true => 42 > ‘hello’ => “hello” Tuesday, February 8, 2011
  • 52. Unary Send 3 class Tuesday, February 8, 2011
  • 53. Unary Send 3.class Ruby Tuesday, February 8, 2011
  • 54. Unary Send 3 class Tuesday, February 8, 2011
  • 55. Unary Send 3 class Tuesday, February 8, 2011
  • 56. Unary Send g.seq(:number, “ “, :method_name) { |v,_,n| UnarySend.new(v,n) } Tuesday, February 8, 2011
  • 57. Unary Send us = number “ “ method_name Tuesday, February 8, 2011
  • 58. Unary Send true class Tuesday, February 8, 2011
  • 59. Unary Send g.seq(:atom, “ “, :method_name) { |v,_,n| UnarySend.new(v,n) } Tuesday, February 8, 2011
  • 60. atom = true | false | self | nil | number | string Tuesday, February 8, 2011
  • 61. Unary Send us = atom “ “ method_name Tuesday, February 8, 2011
  • 62. Unary Send 3 class class Tuesday, February 8, 2011
  • 63. Unary Send g.any( g.seq(:unary_send, “ “, :method_name) { |v,_,n| UnarySend.new(v,n) }, g.seq(:atom, “ “, :method_name) { |v,_,n| UnarySend.new(v,n) } ) Tuesday, February 8, 2011
  • 64. Unary Send us = us “ “ method_name | atom “ “ method_name Tuesday, February 8, 2011
  • 65. Unary Send def bytecode(g) @receiver.bytecode(g) g.send @method_name.to_sym, 0 end Tuesday, February 8, 2011
  • 66. $ rbx bin/repl.rb > 3 class => Fixnum > 3 class class => Class > ‘hello’ class => String Tuesday, February 8, 2011
  • 67. Keyword Send ‘hello’ index: ‘o’ Tuesday, February 8, 2011
  • 68. Keyword Send “hello”.index(“o”) Ruby Tuesday, February 8, 2011
  • 69. Keyword Send g.keyword_send = g.seq(:atom, ‘ ‘, :method_name, “:”, “ “, :atom) Tuesday, February 8, 2011
  • 70. Keyword Send ks = atom “ “ method_name “: ” :atom Tuesday, February 8, 2011
  • 71. Keyword Send ‘hello’ at: 0 put: ‘j’ Tuesday, February 8, 2011
  • 72. Keyword Send “hello”[0] = “j” Ruby Tuesday, February 8, 2011
  • 73. Keyword Send g.pairs = g.seq(:method_name, “:”, “ “, :atom) Tuesday, February 8, 2011
  • 74. Keyword Send g.keyword_send = g.seq( :atom, ‘ ‘, g.many([:pair, ‘ ‘]), :pair ) Tuesday, February 8, 2011
  • 75. Keyword Send ks = atom (pair ‘ ‘)+ pair Tuesday, February 8, 2011
  • 76. Keyword Send def bytecode(g) @receiver.bytecode(g) @arguments.each do |a| a.bytecode(a) end g.send @method_name.to_sym, @arguments.size end Tuesday, February 8, 2011
  • 77. Keyword Send def bytecode(g) @receiver.bytecode(g) @arguments.each do |a| a.bytecode(a) end g.send @method_name.to_sym, @arguments.size end Tuesday, February 8, 2011
  • 78. $ rbx bin/repl.rb > ‘hello’ index: ‘o’ NoMethodError: Unknown method ‘index:’ Tuesday, February 8, 2011
  • 79. $ rbx bin/repl.rb > ‘hello’ index: ‘o’ NoMethodError: Unknown method ‘index:’ Tuesday, February 8, 2011
  • 80. Keyword Send ‘hello’ index: ‘o’ Tuesday, February 8, 2011
  • 81. Keyword Send “hello”.send( “index:”, “o” ) Ruby Tuesday, February 8, 2011
  • 82. Keyword Send ‘hello’ ~index: ‘o’ Tuesday, February 8, 2011
  • 83. Keyword Send def bytecode(g) if @method_name[0] == ?~ ruby_style else smalltalk_style end end Tuesday, February 8, 2011
  • 84. Keyword Send “hello”.send( “index”, “o” ) Ruby Tuesday, February 8, 2011
  • 85. $ rbx bin/repl.rb > ‘hello’ ~index: ‘o’ => 4 NoMethodError: Unknown method ‘index:’ Tuesday, February 8, 2011
  • 86. Keyword Send obj string at: 0 put: ‘j’ Tuesday, February 8, 2011
  • 87. Keyword Send obj string at: 0 put: ‘j’ Tuesday, February 8, 2011
  • 88. Keyword Send obj string at: 0 put: ‘j’ Tuesday, February 8, 2011
  • 89. Keyword Send g.keyword_send = g.seq( :atom, ‘ ‘, g.many([:pair, ‘ ‘]), :pair ) Tuesday, February 8, 2011
  • 90. Keyword Send g.keyword_send = g.seq( :atom, ‘ ‘, g.many([:pair, ‘ ‘]), :pair ) Tuesday, February 8, 2011
  • 91. Keyword Send ks = atom (pair ‘ ‘)+ pair Tuesday, February 8, 2011
  • 92. Keyword Send g.any(:atom, :unary_send) Tuesday, February 8, 2011
  • 93. Keyword Send recv = us | atom ks = recv (pair ‘ ‘)+ pair Tuesday, February 8, 2011
  • 94. Block [ 1 ] Tuesday, February 8, 2011
  • 95. Keyword Send g.block = g.seq(‘[‘, :expr, ‘]’) Tuesday, February 8, 2011
  • 96. Keyword Send expr = ks | us | atom Tuesday, February 8, 2011
  • 97. Keyword Send block = “[“ expr “] Tuesday, February 8, 2011
  • 98. Block [ 1. 2 ] Tuesday, February 8, 2011
  • 99. Keyword Send g.exprs = g.seq(:expr, g.kleene(‘.’, :expr)) Tuesday, February 8, 2011
  • 100. Keyword Send exprs = (‘.’ expr)* Tuesday, February 8, 2011
  • 101. Keyword Send block = “[“ exprs “] Tuesday, February 8, 2011
  • 102. $ rbx bin/repl.rb > 10 ~times: [ Kernel ~puts: ‘hello’ ] Tuesday, February 8, 2011
  • 103. $ rbx bin/repl.rb > 10 ~times: [ Kernel ~puts: ‘rb.la’ ] “rb.la” “rb.la” “rb.la” ... => 10 Tuesday, February 8, 2011
  • 104. $ rbx bin/repl.rb > 10 ~times: [ :x | Kernel ~p: x ] Tuesday, February 8, 2011
  • 105. $ rbx bin/repl.rb > 10 ~times: [ :x | Kernel ~p: x ] 0 1 2 ... => 10 Tuesday, February 8, 2011
  • 106. Cascade Send ary concat: a; concat: b; concat: c Tuesday, February 8, 2011
  • 107. Operators 3 + 4 * 5 Tuesday, February 8, 2011
  • 108. $ rbx bin/repl.rb > 3 + 4 * 5 Tuesday, February 8, 2011
  • 109. $ rbx bin/repl.rb > 3 + 4 * 5 => 35 Tuesday, February 8, 2011
  • 110. Parens parens = “(“ expr “) Tuesday, February 8, 2011
  • 111. $ rbx bin/repl.rb > 3 + (4 * 5) => 23 Tuesday, February 8, 2011
  • 112. zero to usable Tuesday, February 8, 2011
  • 115. Complex Language Tuesday, February 8, 2011
  • 117. Thanks! See ya out there. Tuesday, February 8, 2011