SlideShare una empresa de Scribd logo
1 de 119
Descargar para leer sin conexión
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

Más contenido relacionado

Destacado

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 CloudEngine Yard
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to RubyEngine Yard
 
JRuby Jam Session
JRuby Jam Session JRuby Jam Session
JRuby Jam Session Engine Yard
 
St Charles ©Tytel Mkt
St Charles ©Tytel MktSt Charles ©Tytel Mkt
St Charles ©Tytel Mktjtytel
 
Engine Yard Cloud Architecture Enhancements
Engine Yard Cloud Architecture EnhancementsEngine Yard Cloud Architecture Enhancements
Engine Yard Cloud Architecture EnhancementsEngine Yard
 
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
 

Destacado (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 a Developing a Language

Doctrine in the Real World
Doctrine in the Real WorldDoctrine in the Real World
Doctrine in the Real WorldJonathan Wage
 
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
 
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)jeremymcanally
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSCaridy Patino
 
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 HTML5Tim Wright
 
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 Rubyharisamin
 
Web Scraping using Diazo!
Web Scraping using Diazo!Web Scraping using Diazo!
Web Scraping using Diazo!pythonchile
 
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 PHPsmueller_sandsmedia
 
Parser combinators
Parser combinatorsParser combinators
Parser combinatorslifecoder
 
A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemLeonard Axelsson
 
Node js techtalksto
Node js techtalkstoNode js techtalksto
Node js techtalkstoJason Diller
 
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 TDDAndrea Francia
 

Similar a Developing a Language (15)

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
 
JavaSE 7
JavaSE 7JavaSE 7
JavaSE 7
 
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)
 
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)
 
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
 

Más de Engine Yard

6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performanceEngine Yard
 
Simplifying PCI on a PaaS Environment
Simplifying PCI on a PaaS EnvironmentSimplifying PCI on a PaaS Environment
Simplifying PCI on a PaaS EnvironmentEngine Yard
 
The Tao of Documentation
The Tao of DocumentationThe Tao of Documentation
The Tao of DocumentationEngine Yard
 
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 ServiceEngine Yard
 
JRuby: Enhancing Java Developers Lives
JRuby: Enhancing Java Developers LivesJRuby: Enhancing Java Developers Lives
JRuby: Enhancing Java Developers LivesEngine Yard
 
High Performance Ruby: Evented vs. Threaded
High Performance Ruby: Evented vs. ThreadedHigh Performance Ruby: Evented vs. Threaded
High Performance Ruby: Evented vs. ThreadedEngine Yard
 
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 FrictionEngine Yard
 
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 Engine Yard
 
JRuby: Apples and Oranges
JRuby: Apples and OrangesJRuby: Apples and Oranges
JRuby: Apples and OrangesEngine Yard
 
Debugging Ruby Systems
Debugging Ruby SystemsDebugging Ruby Systems
Debugging Ruby SystemsEngine Yard
 
Everything Rubinius
Everything RubiniusEverything Rubinius
Everything RubiniusEngine Yard
 

Más de 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
 

Último

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

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