SlideShare une entreprise Scribd logo
1  sur  32
Implementing External DSLs Using Scala Parser Combinators St. Louis Lambda Lounge Sept. 3, 2009 Tim Dalton Senior Software Engineer Object Computing Inc.
External vs Internal DSL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is a Combinator ? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Scala’s Parser Implementation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scala Combinator Parser Hierarchy ,[object Object],[object Object],[object Object],[object Object],[object Object]
A Simple Logo(-Like) Interpreter ,[object Object],[object Object],[object Object],[object Object],[object Object]
Grammar for Simple Logo ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scala Code to Implement Parser ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scala Code to Implement Parser ,[object Object],[object Object],[object Object]
A Closer Look ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Implicit Conversions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Back to the Parser ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Parser[T]’s and ParseResult[T]’s ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Combining Parser[T]’s ,[object Object],[object Object],[object Object],[object Object],[object Object]
Combining Parser[T]’s ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Forward March ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Repetition ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Repetition ,[object Object],[object Object],[object Object],[object Object]
Other Forms of Repetition ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Execution ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Not-so-Happy Path ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Making Something Useful ,[object Object],[object Object],[object Object],[object Object]
Eye Brows Example ,[object Object],[object Object],[object Object],[object Object],[object Object]
Implementing Commands ,[object Object],[object Object],[object Object],[object Object],[object Object]
Transforming into Commands ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Derivates of “~” ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Updated Parser ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Updated Parser Results ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Evaluation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Evaluation (More Functional) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Evaluation (More Imperative) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Demonstration

Contenu connexe

Tendances

Recursive descent parsing
Recursive descent parsingRecursive descent parsing
Recursive descent parsing
Boy Baukema
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
 

Tendances (19)

Topdown parsing
Topdown parsingTopdown parsing
Topdown parsing
 
Functions
FunctionsFunctions
Functions
 
Ch2
Ch2Ch2
Ch2
 
Ch4a
Ch4aCh4a
Ch4a
 
Operator precedence
Operator precedenceOperator precedence
Operator precedence
 
Types of Parser
Types of ParserTypes of Parser
Types of Parser
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
 
Module 11
Module 11Module 11
Module 11
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Nonrecursive predictive parsing
Nonrecursive predictive parsingNonrecursive predictive parsing
Nonrecursive predictive parsing
 
Recursive descent parsing
Recursive descent parsingRecursive descent parsing
Recursive descent parsing
 
Parsing
ParsingParsing
Parsing
 
Left factor put
Left factor putLeft factor put
Left factor put
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Python (regular expression)
Python (regular expression)Python (regular expression)
Python (regular expression)
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 

En vedette

Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in Scala
Abhijit Sharma
 
Markaların Logo Değişimleri
Markaların Logo  DeğişimleriMarkaların Logo  Değişimleri
Markaların Logo Değişimleri
Yunus Emre
 
Coches Fantasticos
Coches FantasticosCoches Fantasticos
Coches Fantasticos
josevlc
 
MTech13: "The Power of Marketing Automation in an Inbound World" - Nick Salva...
MTech13: "The Power of Marketing Automation in an Inbound World" - Nick Salva...MTech13: "The Power of Marketing Automation in an Inbound World" - Nick Salva...
MTech13: "The Power of Marketing Automation in an Inbound World" - Nick Salva...
New England Direct Marketing Association
 

En vedette (20)

Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in Scala
 
Virtualization
VirtualizationVirtualization
Virtualization
 
Hpt performance
Hpt   performanceHpt   performance
Hpt performance
 
About Blogs
About BlogsAbout Blogs
About Blogs
 
PO
POPO
PO
 
Downtown Ferndale Business Guide 2011
Downtown Ferndale Business Guide 2011Downtown Ferndale Business Guide 2011
Downtown Ferndale Business Guide 2011
 
Markaların Logo Değişimleri
Markaların Logo  DeğişimleriMarkaların Logo  Değişimleri
Markaların Logo Değişimleri
 
Coches Fantasticos
Coches FantasticosCoches Fantasticos
Coches Fantasticos
 
NEDMAInno14: The Fundamental Things Still Apply: How to Deal with "Innovation...
NEDMAInno14: The Fundamental Things Still Apply: How to Deal with "Innovation...NEDMAInno14: The Fundamental Things Still Apply: How to Deal with "Innovation...
NEDMAInno14: The Fundamental Things Still Apply: How to Deal with "Innovation...
 
MTech13: "How to Jump Start Sales Productivity with Content" - Paula Crerar
MTech13: "How to Jump Start Sales Productivity with Content" - Paula CrerarMTech13: "How to Jump Start Sales Productivity with Content" - Paula Crerar
MTech13: "How to Jump Start Sales Productivity with Content" - Paula Crerar
 
Yahoo Korea 10th anniversary Plan Concept
Yahoo Korea 10th anniversary Plan ConceptYahoo Korea 10th anniversary Plan Concept
Yahoo Korea 10th anniversary Plan Concept
 
Google Places - Global Approach ISS 2012
Google Places - Global Approach ISS 2012Google Places - Global Approach ISS 2012
Google Places - Global Approach ISS 2012
 
Учебные форматы МАСП
Учебные форматы МАСПУчебные форматы МАСП
Учебные форматы МАСП
 
A Redesign of VisitPhilly.com by Happy Cog
A Redesign of VisitPhilly.com by Happy CogA Redesign of VisitPhilly.com by Happy Cog
A Redesign of VisitPhilly.com by Happy Cog
 
everdo for ad
everdo for adeverdo for ad
everdo for ad
 
CEO Roundtable on Local and State Tax Laws
CEO Roundtable on Local and State Tax LawsCEO Roundtable on Local and State Tax Laws
CEO Roundtable on Local and State Tax Laws
 
MTech13: "The Power of Marketing Automation in an Inbound World" - Nick Salva...
MTech13: "The Power of Marketing Automation in an Inbound World" - Nick Salva...MTech13: "The Power of Marketing Automation in an Inbound World" - Nick Salva...
MTech13: "The Power of Marketing Automation in an Inbound World" - Nick Salva...
 
Istant report Open Spece Technology "Facciamo il Macello"
Istant report Open Spece Technology "Facciamo il Macello"Istant report Open Spece Technology "Facciamo il Macello"
Istant report Open Spece Technology "Facciamo il Macello"
 
Print Technology: Functional Printed Electronics - RFID & NFC versus QR Codes...
Print Technology: Functional Printed Electronics - RFID & NFC versus QR Codes...Print Technology: Functional Printed Electronics - RFID & NFC versus QR Codes...
Print Technology: Functional Printed Electronics - RFID & NFC versus QR Codes...
 
Workflow NPW2010
Workflow NPW2010Workflow NPW2010
Workflow NPW2010
 

Similaire à Implementing External DSLs Using Scala Parser Combinators

The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
zone
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
birbal
 
TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretation
Eelco Visser
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
stopgolook
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuation
lotlot
 
C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 

Similaire à Implementing External DSLs Using Scala Parser Combinators (20)

Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Javascript
JavascriptJavascript
Javascript
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
 
TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretation
 
Javascript
JavascriptJavascript
Javascript
 
Programming
ProgrammingProgramming
Programming
 
Beginning Scala Svcc 2009
Beginning Scala Svcc 2009Beginning Scala Svcc 2009
Beginning Scala Svcc 2009
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
2 R Tutorial Programming
2 R Tutorial Programming2 R Tutorial Programming
2 R Tutorial Programming
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
 
C intro
C introC intro
C intro
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuation
 
Oscon 2010 Specs talk
Oscon 2010 Specs talkOscon 2010 Specs talk
Oscon 2010 Specs talk
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 

Dernier

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
Earley Information Science
 

Dernier (20)

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?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Implementing External DSLs Using Scala Parser Combinators

  • 1. Implementing External DSLs Using Scala Parser Combinators St. Louis Lambda Lounge Sept. 3, 2009 Tim Dalton Senior Software Engineer Object Computing Inc.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.

Notes de l'éditeur

  1. (|) = OR logic { } = repetition
  2. The multiline string notation is used so escaping “\\” in the regex is not needed
  3. Internal DSLs in Scala leverage implicit conversion to a great degree to allow a more flexible “syntax”
  4. ~ is a case class.
  5. Because statement and repeat invoke each other and therefore can be invoked recursively, The return type for one must be specified
  6. There is also rep1sep
  7. Demonstrate no so precise message “RT” -> “ET”
  8. For some reason Scala compile didn’t like { Turn(-_) }
  9. Tail Recursive !!