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

Viewers also liked

Rubinius and Ruby | A Love Story
Rubinius and Ruby | A Love Story Rubinius and Ruby | A Love Story
Rubinius and Ruby | A Love Story
Engine Yard
 

Viewers also liked (6)

Getting Started with PHP on Engine Yard Cloud
Getting Started with PHP on Engine Yard CloudGetting Started with PHP on Engine Yard Cloud
Getting Started with PHP on Engine Yard Cloud
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
JRuby Jam Session
JRuby Jam Session JRuby Jam Session
JRuby Jam Session
 
St Charles ©Tytel Mkt
St Charles ©Tytel MktSt Charles ©Tytel Mkt
St Charles ©Tytel Mkt
 
Engine Yard Cloud Architecture Enhancements
Engine Yard Cloud Architecture EnhancementsEngine Yard Cloud Architecture Enhancements
Engine Yard Cloud Architecture Enhancements
 
Rubinius and Ruby | A Love Story
Rubinius and Ruby | A Love Story Rubinius and Ruby | A Love Story
Rubinius and Ruby | A Love Story
 

Similar to Developing a Language

Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
OpenBlend society
 
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
jbellis
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JS
Caridy Patino
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
smueller_sandsmedia
 
Writing a Crawler with Python and TDD
Writing a Crawler with Python and TDDWriting a Crawler with Python and TDD
Writing a Crawler with Python and TDD
Andrea Francia
 

Similar to Developing a Language (16)

Doctrine in the Real World
Doctrine in the Real WorldDoctrine in the Real World
Doctrine in the Real World
 
When?, Why? and What? of MongoDB
When?, Why? and What? of MongoDBWhen?, Why? and What? of MongoDB
When?, Why? and What? of MongoDB
 
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
 
JavaSE 7
JavaSE 7JavaSE 7
JavaSE 7
 
Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)
Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)
Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)
 
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
 
Caridy patino - node-js
Caridy patino - node-jsCaridy patino - node-js
Caridy patino - node-js
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JS
 
A Look at the Future of HTML5
A Look at the Future of HTML5A Look at the Future of HTML5
A Look at the Future of HTML5
 
The Enumerable Module or How I Fell in Love with Ruby
The Enumerable Module or How I Fell in Love with RubyThe Enumerable Module or How I Fell in Love with Ruby
The Enumerable Module or How I Fell in Love with Ruby
 
Web Scraping using Diazo!
Web Scraping using Diazo!Web Scraping using Diazo!
Web Scraping using Diazo!
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 
Parser combinators
Parser combinatorsParser combinators
Parser combinators
 
A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy Ecosystem
 
Node js techtalksto
Node js techtalkstoNode js techtalksto
Node js techtalksto
 
Writing a Crawler with Python and TDD
Writing a Crawler with Python and TDDWriting a Crawler with Python and TDD
Writing a Crawler with Python and TDD
 

More from Engine Yard

Everything Rubinius
Everything RubiniusEverything Rubinius
Everything Rubinius
Engine Yard
 

More from Engine Yard (12)

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

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 

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