SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
with




        Lukas Renggli
www.tudorgirba.com
based on the work of Lukas Renggli
www.lukas-renggli.ch
with




            Lukas Renggli
built by Lukas Renggli
deeply integrated with Smalltalk
part of the Moose Suite
input   parse   output
Mastering Grammars
          with



      parse
      Lukas Renggli
Root := Document ?
Document := OPEN ElementNode * CLOSE
ElementNode := OPEN ELEMENTNAME AttributeNode * CLOSE
AttributeNode := OPEN SIMPLENAME ValueNode * CLOSE
ValueNode := Primitive | ElementNode
Primitive := STRING | NUMBER
OPEN := "("
CLOSE := ")"
ELEMENTNAME := letter ( letter | digit ) * ( "." letter ( letter | digit ) ) *
SIMPLENAME := letter ( letter | digit ) *
NUMBER := "-" ? digit + ( "." digit + ) ? ( ( "e" | "E" ) ( "-" | "+" ) ? digit + ) ?
STRING := ( "'" [^'] * "'" ) +
digit := [0-9]
letter := [a-zA-Z_]
comment := """ [^"] * """




target
IDENTIFIER ::=	letter
               ( letter |
                 digit ) *




         a..z          a..z


                       0..9
identifier := #letter asParser ,
              ( #letter asParser /
                #digit asParser ) star.




         a..z          a..z


                       0..9
exercise
identifier := #letter asParser ,
              ( #letter asParser /
                #digit asParser ) star.




         a..z          a..z


                       0..9
identifier := #letter asParser ,
              ( #letter asParser /
                #digit asParser ) star.


             sequence



    letter               many



                        choice



              letter             digit
identifier := #letter asParser ,
                ( #letter asParser /
                  #digit asParser ) star.


               sequence



      letter               many



parsers are objects       choice



                letter             digit
terminals
$c        asParser   parse character “c”

‘string’ asParser    parse string “string”

#any      asParser   parse any character

#digit    asParser   parse one digit

#letter   asParser   parse one letter
terminals are defined in PPPredicateObjectParser




exercise:!browse!PPPredicateObjectParser
combinators
p1 , p2       parse p1 followed by p2 (sequence)


p1 / p2       parse p1, otherwise parse p2 (ordered choice)


p star        parse zero or more p


p plus        parse one or more p


p optional    parse p if possible



predicates
p not         negation (non-consuming look-ahead)

p negate      negation (consuming)

p end         end of input
PPParser is the root of all parsers




all operations are defined in this class
exercise:!browse!PPParser!operations
exercise
actions
p ==> aBlock   Transforms the result of p through aBlock.


p flatten      Creates a string from the result of p.


p token        Creates a token from the result of p.


p trim         Trims whitespaces before and after p.
string   := $' asParser ,
            $' asParser negate star ,
            $' asParser.
string   := $' asParser ,
            $' asParser negate star flatten ,
            $' asParser
            ==> [:token | token second ].
stringText := $' asParser negate star flatten.
string     := $' asParser ,
              stringText ,
              $' asParser
              ==> [:token | token second ].
exercise
Root := Document ?
Document := OPEN ElementNode * CLOSE

                                                                      exercise
ElementNode := OPEN ELEMENTNAME AttributeNode * CLOSE
AttributeNode := OPEN SIMPLENAME ValueNode * CLOSE
ValueNode := Primitive | ElementNode
Primitive := STRING | NUMBER
OPEN := "("
CLOSE := ")"
ELEMENTNAME := letter ( letter | digit ) * ( "." letter ( letter | digit ) *)
SIMPLENAME := letter ( letter | digit ) *
NUMBER := "-" ? digit + ( "." digit + ) ? ( ( "e" | "E" ) ( "-" | "+" ) ? digit + ) ?
STRING := ( "'" [^'] * "'" ) +
digit := [0-9]
letter := [a-zA-Z_]
comment := """ [^"] * """



(
    (FAMIX.Package
       (name 'PackageP'))
    (FAMIX.Class
       (name 'ClassA'))
    (FAMIX.Method
       (name 'methodM'))
)
stringText   := $' asParser negate star flatten.
string       := $' asParser ,
                stringText ,
                $' asParser
                ==> [:token | token second ].
stringText   := PPUnresolvedParser new.
string       := $' asParser ,
                stringText ,
                $' asParser
                ==> [:token | token second ].
stringText def: ($' asParser negate star flatten).
Root := Document ?
Document := OPEN ElementNode * CLOSE
                                                                     exercise
ElementNode := OPEN ELEMENTNAME Serial ? AttributeNode * CLOSE
Serial := OPEN ID INTEGER CLOSE
AttributeNode := OPEN SIMPLENAME ValueNode * CLOSE
ValueNode := Primitive | Reference | ElementNode
Primitive := STRING | NUMBER | Boolean | Unlimited
Boolean := TRUE | FALSE
Unlimited := NIL
Reference := IntegerReference | NameReference
IntegerReference := OPEN REF INTEGER CLOSE
NameReference := OPEN REF ELEMENTNAME CLOSE
OPEN := "("
CLOSE := ")"
ID := "id:"
REF := "ref:"
TRUE := "true"
FALSE := "false"
ELEMENTNAME := letter ( letter | digit ) * ( "." letter ( letter | digit ) ) *
SIMPLENAME := letter ( letter | digit ) *
INTEGER := digit +
NUMBER := "-" ? digit + ( "." digit + ) ? ( ( "e" | "E" ) ( "-" | "+" ) ? digit + ) ?
STRING := ( "'" [^'] * "'" ) +
digit := [0-9]
letter := [a-zA-Z_]
comment := """ [^"] * """
exercise


(
    (FAMIX.Package (id: 1)
       (name 'PackageP'))
    (FAMIX.Class (id: 2)
       (name 'ClassA')
       (parentPackage (ref: 1)))
    (FAMIX.Method (id: 3)
       (name 'methodA')
       (declaredType (ref: 1))
       (parentType (ref: 2)))
)
scripting = ! nice for prototyping
            ! but messy
subclass PPCompositeParser




start = default start parser
externally, parsers map on methods




internally, parsers map on instance variables
to specify actions, subclass the base grammar
subclass tests from PPCompositeParserTest




specify the parserClass
use #parse:rule: to check the grammar
subclass to check the parser result
PetitParser comes with a dedicated user interface




PPBrowser open.
with




            Lukas Renggli
built by Lukas Renggli
deeply integrated with Smalltalk
part of the Moose Suite
Tudor Gîrba
        www.tudorgirba.com




creativecommons.org/licenses/by/3.0/

Contenu connexe

Tendances

UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2Nihar Ranjan Paital
 
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.Samuel Fortier-Galarneau
 
Decorators in Python
Decorators in PythonDecorators in Python
Decorators in PythonBen James
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursPhillip Trelford
 
CGI With Object Oriented Perl
CGI With Object Oriented PerlCGI With Object Oriented Perl
CGI With Object Oriented PerlBunty Ray
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming LanguageGiuseppe Arici
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Parkpointstechgeeks
 
Advanced perl finer points ,pack&unpack,eval,files
Advanced perl   finer points ,pack&unpack,eval,filesAdvanced perl   finer points ,pack&unpack,eval,files
Advanced perl finer points ,pack&unpack,eval,filesShankar D
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awkYogesh Sawant
 
Python decorators
Python decoratorsPython decorators
Python decoratorsAlex Su
 
FParsec Hands On - F#unctional Londoners 2014
FParsec Hands On -  F#unctional Londoners 2014FParsec Hands On -  F#unctional Londoners 2014
FParsec Hands On - F#unctional Londoners 2014Phillip Trelford
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisaujihisa
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, SwiftYandex
 

Tendances (20)

UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Awk programming
Awk programming Awk programming
Awk programming
 
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
 
Decorators in Python
Decorators in PythonDecorators in Python
Decorators in Python
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Awk essentials
Awk essentialsAwk essentials
Awk essentials
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 Hours
 
Cleancode
CleancodeCleancode
Cleancode
 
CGI With Object Oriented Perl
CGI With Object Oriented PerlCGI With Object Oriented Perl
CGI With Object Oriented Perl
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Python decorators
Python decoratorsPython decorators
Python decorators
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
 
Advanced perl finer points ,pack&unpack,eval,files
Advanced perl   finer points ,pack&unpack,eval,filesAdvanced perl   finer points ,pack&unpack,eval,files
Advanced perl finer points ,pack&unpack,eval,files
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
Python decorators
Python decoratorsPython decorators
Python decorators
 
FParsec Hands On - F#unctional Londoners 2014
FParsec Hands On -  F#unctional Londoners 2014FParsec Hands On -  F#unctional Londoners 2014
FParsec Hands On - F#unctional Londoners 2014
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisa
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 

Similaire à Petitparser at the Deep into Smalltalk School 2011

Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of RubyTom Crinson
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...adrianoalmeida7
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangSean Cribbs
 
Beginning Scala Svcc 2009
Beginning Scala Svcc 2009Beginning Scala Svcc 2009
Beginning Scala Svcc 2009David Pollak
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubyJason Yeo Jie Shun
 
TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationEelco Visser
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parserkamaelian
 
Perl Xpath Lightning Talk
Perl Xpath Lightning TalkPerl Xpath Lightning Talk
Perl Xpath Lightning Talkddn123456
 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Contextlichtkind
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)ujihisa
 
あたかも自然言語を書くようにコーディングしてみる
あたかも自然言語を書くようにコーディングしてみるあたかも自然言語を書くようにコーディングしてみる
あたかも自然言語を書くようにコーディングしてみるKazuya Numata
 
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallyRound PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallySean Cribbs
 
Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWorkhorse Computing
 

Similaire à Petitparser at the Deep into Smalltalk School 2011 (20)

Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of Ruby
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Ch2
Ch2Ch2
Ch2
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
 
Beginning Scala Svcc 2009
Beginning Scala Svcc 2009Beginning Scala Svcc 2009
Beginning Scala Svcc 2009
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in Ruby
 
TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretation
 
Antlr V3
Antlr V3Antlr V3
Antlr V3
 
SWP - A Generic Language Parser
SWP - A Generic Language ParserSWP - A Generic Language Parser
SWP - A Generic Language Parser
 
Perl Xpath Lightning Talk
Perl Xpath Lightning TalkPerl Xpath Lightning Talk
Perl Xpath Lightning Talk
 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Context
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)
 
Tork03 LT
Tork03 LT Tork03 LT
Tork03 LT
 
あたかも自然言語を書くようにコーディングしてみる
あたかも自然言語を書くようにコーディングしてみるあたかも自然言語を書くようにコーディングしてみる
あたかも自然言語を書くようにコーディングしてみる
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallyRound PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing Functionally
 
Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility Modules
 

Plus de Tudor Girba

Beyond software evolution: Software environmentalism
Beyond software evolution: Software environmentalismBeyond software evolution: Software environmentalism
Beyond software evolution: Software environmentalismTudor Girba
 
Software craftsmanship meetup (Zurich 2015) on solving real problems without ...
Software craftsmanship meetup (Zurich 2015) on solving real problems without ...Software craftsmanship meetup (Zurich 2015) on solving real problems without ...
Software craftsmanship meetup (Zurich 2015) on solving real problems without ...Tudor Girba
 
Don't demo facts. Demo stories! (handouts)
Don't demo facts. Demo stories! (handouts)Don't demo facts. Demo stories! (handouts)
Don't demo facts. Demo stories! (handouts)Tudor Girba
 
Don't demo facts. Demo stories!
Don't demo facts. Demo stories!Don't demo facts. Demo stories!
Don't demo facts. Demo stories!Tudor Girba
 
Humane assessment on cards
Humane assessment on cardsHumane assessment on cards
Humane assessment on cardsTudor Girba
 
Underneath Scrum: Reflective Thinking
Underneath Scrum: Reflective ThinkingUnderneath Scrum: Reflective Thinking
Underneath Scrum: Reflective ThinkingTudor Girba
 
1800+ TED talks later
1800+ TED talks later1800+ TED talks later
1800+ TED talks laterTudor Girba
 
Software assessment by example (lecture at the University of Bern)
Software assessment by example (lecture at the University of Bern)Software assessment by example (lecture at the University of Bern)
Software assessment by example (lecture at the University of Bern)Tudor Girba
 
Humane assessment: Taming the elephant from the development room
Humane assessment: Taming the elephant from the development roomHumane assessment: Taming the elephant from the development room
Humane assessment: Taming the elephant from the development roomTudor Girba
 
Moose: how to solve real problems without reading code
Moose: how to solve real problems without reading codeMoose: how to solve real problems without reading code
Moose: how to solve real problems without reading codeTudor Girba
 
Software Environmentalism (ECOOP 2014 Keynote)
Software Environmentalism (ECOOP 2014 Keynote)Software Environmentalism (ECOOP 2014 Keynote)
Software Environmentalism (ECOOP 2014 Keynote)Tudor Girba
 
The emergent nature of software systems
The emergent nature of software systemsThe emergent nature of software systems
The emergent nature of software systemsTudor Girba
 
Presenting is storytelling at Uni Zurich - slides (2014-03-05)
Presenting is storytelling at Uni Zurich - slides (2014-03-05)Presenting is storytelling at Uni Zurich - slides (2014-03-05)
Presenting is storytelling at Uni Zurich - slides (2014-03-05)Tudor Girba
 
Presenting is storytelling at Uni Zurich - handouts (2014-03-05)
Presenting is storytelling at Uni Zurich - handouts (2014-03-05)Presenting is storytelling at Uni Zurich - handouts (2014-03-05)
Presenting is storytelling at Uni Zurich - handouts (2014-03-05)Tudor Girba
 
Underneath Scrum: Reflective Thinking (talk at Scrum Breakfast Bern, 2013)
Underneath Scrum: Reflective Thinking (talk at Scrum Breakfast Bern, 2013)Underneath Scrum: Reflective Thinking (talk at Scrum Breakfast Bern, 2013)
Underneath Scrum: Reflective Thinking (talk at Scrum Breakfast Bern, 2013)Tudor Girba
 
Demo-driven innovation teaser
Demo-driven innovation teaserDemo-driven innovation teaser
Demo-driven innovation teaserTudor Girba
 
Software assessment essentials (lecture at the University of Bern 2013)
Software assessment essentials (lecture at the University of Bern 2013)Software assessment essentials (lecture at the University of Bern 2013)
Software assessment essentials (lecture at the University of Bern 2013)Tudor Girba
 
Demo-driven innovation (University of Zurich, June 2013)
Demo-driven innovation (University of Zurich, June 2013)Demo-driven innovation (University of Zurich, June 2013)
Demo-driven innovation (University of Zurich, June 2013)Tudor Girba
 
Humane assessment with Moose at GOTO Aarhus 2011
Humane assessment with Moose at GOTO Aarhus 2011Humane assessment with Moose at GOTO Aarhus 2011
Humane assessment with Moose at GOTO Aarhus 2011Tudor Girba
 

Plus de Tudor Girba (20)

Beyond software evolution: Software environmentalism
Beyond software evolution: Software environmentalismBeyond software evolution: Software environmentalism
Beyond software evolution: Software environmentalism
 
Software craftsmanship meetup (Zurich 2015) on solving real problems without ...
Software craftsmanship meetup (Zurich 2015) on solving real problems without ...Software craftsmanship meetup (Zurich 2015) on solving real problems without ...
Software craftsmanship meetup (Zurich 2015) on solving real problems without ...
 
GT Spotter
GT SpotterGT Spotter
GT Spotter
 
Don't demo facts. Demo stories! (handouts)
Don't demo facts. Demo stories! (handouts)Don't demo facts. Demo stories! (handouts)
Don't demo facts. Demo stories! (handouts)
 
Don't demo facts. Demo stories!
Don't demo facts. Demo stories!Don't demo facts. Demo stories!
Don't demo facts. Demo stories!
 
Humane assessment on cards
Humane assessment on cardsHumane assessment on cards
Humane assessment on cards
 
Underneath Scrum: Reflective Thinking
Underneath Scrum: Reflective ThinkingUnderneath Scrum: Reflective Thinking
Underneath Scrum: Reflective Thinking
 
1800+ TED talks later
1800+ TED talks later1800+ TED talks later
1800+ TED talks later
 
Software assessment by example (lecture at the University of Bern)
Software assessment by example (lecture at the University of Bern)Software assessment by example (lecture at the University of Bern)
Software assessment by example (lecture at the University of Bern)
 
Humane assessment: Taming the elephant from the development room
Humane assessment: Taming the elephant from the development roomHumane assessment: Taming the elephant from the development room
Humane assessment: Taming the elephant from the development room
 
Moose: how to solve real problems without reading code
Moose: how to solve real problems without reading codeMoose: how to solve real problems without reading code
Moose: how to solve real problems without reading code
 
Software Environmentalism (ECOOP 2014 Keynote)
Software Environmentalism (ECOOP 2014 Keynote)Software Environmentalism (ECOOP 2014 Keynote)
Software Environmentalism (ECOOP 2014 Keynote)
 
The emergent nature of software systems
The emergent nature of software systemsThe emergent nature of software systems
The emergent nature of software systems
 
Presenting is storytelling at Uni Zurich - slides (2014-03-05)
Presenting is storytelling at Uni Zurich - slides (2014-03-05)Presenting is storytelling at Uni Zurich - slides (2014-03-05)
Presenting is storytelling at Uni Zurich - slides (2014-03-05)
 
Presenting is storytelling at Uni Zurich - handouts (2014-03-05)
Presenting is storytelling at Uni Zurich - handouts (2014-03-05)Presenting is storytelling at Uni Zurich - handouts (2014-03-05)
Presenting is storytelling at Uni Zurich - handouts (2014-03-05)
 
Underneath Scrum: Reflective Thinking (talk at Scrum Breakfast Bern, 2013)
Underneath Scrum: Reflective Thinking (talk at Scrum Breakfast Bern, 2013)Underneath Scrum: Reflective Thinking (talk at Scrum Breakfast Bern, 2013)
Underneath Scrum: Reflective Thinking (talk at Scrum Breakfast Bern, 2013)
 
Demo-driven innovation teaser
Demo-driven innovation teaserDemo-driven innovation teaser
Demo-driven innovation teaser
 
Software assessment essentials (lecture at the University of Bern 2013)
Software assessment essentials (lecture at the University of Bern 2013)Software assessment essentials (lecture at the University of Bern 2013)
Software assessment essentials (lecture at the University of Bern 2013)
 
Demo-driven innovation (University of Zurich, June 2013)
Demo-driven innovation (University of Zurich, June 2013)Demo-driven innovation (University of Zurich, June 2013)
Demo-driven innovation (University of Zurich, June 2013)
 
Humane assessment with Moose at GOTO Aarhus 2011
Humane assessment with Moose at GOTO Aarhus 2011Humane assessment with Moose at GOTO Aarhus 2011
Humane assessment with Moose at GOTO Aarhus 2011
 

Dernier

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Dernier (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Petitparser at the Deep into Smalltalk School 2011

  • 1. with Lukas Renggli www.tudorgirba.com based on the work of Lukas Renggli www.lukas-renggli.ch
  • 2. with Lukas Renggli built by Lukas Renggli deeply integrated with Smalltalk part of the Moose Suite
  • 3. input parse output
  • 4. Mastering Grammars with parse Lukas Renggli
  • 5. Root := Document ? Document := OPEN ElementNode * CLOSE ElementNode := OPEN ELEMENTNAME AttributeNode * CLOSE AttributeNode := OPEN SIMPLENAME ValueNode * CLOSE ValueNode := Primitive | ElementNode Primitive := STRING | NUMBER OPEN := "(" CLOSE := ")" ELEMENTNAME := letter ( letter | digit ) * ( "." letter ( letter | digit ) ) * SIMPLENAME := letter ( letter | digit ) * NUMBER := "-" ? digit + ( "." digit + ) ? ( ( "e" | "E" ) ( "-" | "+" ) ? digit + ) ? STRING := ( "'" [^'] * "'" ) + digit := [0-9] letter := [a-zA-Z_] comment := """ [^"] * """ target
  • 6.
  • 7. IDENTIFIER ::= letter ( letter | digit ) * a..z a..z 0..9
  • 8. identifier := #letter asParser , ( #letter asParser / #digit asParser ) star. a..z a..z 0..9
  • 10. identifier := #letter asParser , ( #letter asParser / #digit asParser ) star. a..z a..z 0..9
  • 11. identifier := #letter asParser , ( #letter asParser / #digit asParser ) star. sequence letter many choice letter digit
  • 12. identifier := #letter asParser , ( #letter asParser / #digit asParser ) star. sequence letter many parsers are objects choice letter digit
  • 13. terminals $c asParser parse character “c” ‘string’ asParser parse string “string” #any asParser parse any character #digit asParser parse one digit #letter asParser parse one letter
  • 14. terminals are defined in PPPredicateObjectParser exercise:!browse!PPPredicateObjectParser
  • 15. combinators p1 , p2 parse p1 followed by p2 (sequence) p1 / p2 parse p1, otherwise parse p2 (ordered choice) p star parse zero or more p p plus parse one or more p p optional parse p if possible predicates p not negation (non-consuming look-ahead) p negate negation (consuming) p end end of input
  • 16. PPParser is the root of all parsers all operations are defined in this class
  • 19. actions p ==> aBlock Transforms the result of p through aBlock. p flatten Creates a string from the result of p. p token Creates a token from the result of p. p trim Trims whitespaces before and after p.
  • 20.
  • 21. string := $' asParser , $' asParser negate star , $' asParser.
  • 22. string := $' asParser , $' asParser negate star flatten , $' asParser ==> [:token | token second ].
  • 23. stringText := $' asParser negate star flatten. string := $' asParser , stringText , $' asParser ==> [:token | token second ].
  • 25. Root := Document ? Document := OPEN ElementNode * CLOSE exercise ElementNode := OPEN ELEMENTNAME AttributeNode * CLOSE AttributeNode := OPEN SIMPLENAME ValueNode * CLOSE ValueNode := Primitive | ElementNode Primitive := STRING | NUMBER OPEN := "(" CLOSE := ")" ELEMENTNAME := letter ( letter | digit ) * ( "." letter ( letter | digit ) *) SIMPLENAME := letter ( letter | digit ) * NUMBER := "-" ? digit + ( "." digit + ) ? ( ( "e" | "E" ) ( "-" | "+" ) ? digit + ) ? STRING := ( "'" [^'] * "'" ) + digit := [0-9] letter := [a-zA-Z_] comment := """ [^"] * """ ( (FAMIX.Package (name 'PackageP')) (FAMIX.Class (name 'ClassA')) (FAMIX.Method (name 'methodM')) )
  • 26. stringText := $' asParser negate star flatten. string := $' asParser , stringText , $' asParser ==> [:token | token second ].
  • 27. stringText := PPUnresolvedParser new. string := $' asParser , stringText , $' asParser ==> [:token | token second ]. stringText def: ($' asParser negate star flatten).
  • 28.
  • 29. Root := Document ? Document := OPEN ElementNode * CLOSE exercise ElementNode := OPEN ELEMENTNAME Serial ? AttributeNode * CLOSE Serial := OPEN ID INTEGER CLOSE AttributeNode := OPEN SIMPLENAME ValueNode * CLOSE ValueNode := Primitive | Reference | ElementNode Primitive := STRING | NUMBER | Boolean | Unlimited Boolean := TRUE | FALSE Unlimited := NIL Reference := IntegerReference | NameReference IntegerReference := OPEN REF INTEGER CLOSE NameReference := OPEN REF ELEMENTNAME CLOSE OPEN := "(" CLOSE := ")" ID := "id:" REF := "ref:" TRUE := "true" FALSE := "false" ELEMENTNAME := letter ( letter | digit ) * ( "." letter ( letter | digit ) ) * SIMPLENAME := letter ( letter | digit ) * INTEGER := digit + NUMBER := "-" ? digit + ( "." digit + ) ? ( ( "e" | "E" ) ( "-" | "+" ) ? digit + ) ? STRING := ( "'" [^'] * "'" ) + digit := [0-9] letter := [a-zA-Z_] comment := """ [^"] * """
  • 30. exercise ( (FAMIX.Package (id: 1) (name 'PackageP')) (FAMIX.Class (id: 2) (name 'ClassA') (parentPackage (ref: 1))) (FAMIX.Method (id: 3) (name 'methodA') (declaredType (ref: 1)) (parentType (ref: 2))) )
  • 31. scripting = ! nice for prototyping ! but messy
  • 32. subclass PPCompositeParser start = default start parser
  • 33. externally, parsers map on methods internally, parsers map on instance variables
  • 34. to specify actions, subclass the base grammar
  • 35. subclass tests from PPCompositeParserTest specify the parserClass
  • 36. use #parse:rule: to check the grammar
  • 37. subclass to check the parser result
  • 38. PetitParser comes with a dedicated user interface PPBrowser open.
  • 39. with Lukas Renggli built by Lukas Renggli deeply integrated with Smalltalk part of the Moose Suite
  • 40. Tudor Gîrba www.tudorgirba.com creativecommons.org/licenses/by/3.0/