SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
Intro to Boost Spirit
Will Shen
2013/03/25
TDD Your Shape Grammar
Make it can compile “rulessimpleStreets.cga”
2
BOOST Spirit.Qi
Spirit.Qi is designed to be a practical
parsing tool.
The ability to generate a fully-working
parser from a formal EBNF specification
inlined in C++ significantly reduces
development time.
3
Tutorials – Parsing Floating Number
• Parsing a number: double_
• Parsing two numbers: double_ >> double_
• Parsing zero of more numbers: *double_
• Parsing a comma-delimited list of numbers:
double_ >> *( char_(„,‟) >> double_)
4
Parsing Semantic Actions
void Print(int n);
Presented are various ways to attach semantic
actions:
• Using plain function pointer
• Using simple function object
• Using Boost.Bind with a plain function
• Using Boost.Bind with a member function
• Using Boost.Lambda
5
Parsing Semantic Actions
"{integer}"
6
The First Complex parser 1/2
1. Alternates: e.g. a | b. Try a first. If it succeeds, good.
If not, try the next alternative, b.
2. Optional: e.g. -p. Match the parser p zero or one time.
The complex parser presented above reads as:
• One or two real numbers in parentheses, separated by comma (the second
number is optional)
• OR a single real number.
This parser can parse complex numbers of the form:
• (123.45, 987.65)
• (123.45)
• 123.45
7
The First Complex parser 2/2
8
Sum – Adding Numbers
9
Number List –
stuffing numbers into a std::vector
10
Roman Numerals
11
Roman Numerals - Grammars
A grammar encapsulates one or more rules. It
has the same template parameters as the rule.
You declare a grammar by:
1. deriving a struct (or class) from the grammar class
template
2. declare one or more rules as member variables
3. initialize the base grammar class by giving it the start rule
(its the first rule that gets called when the grammar starts
parsing)
4. initialize your rules in your constructor
12
Roman Numerals - Grammars
The grammar and start rule
signature is unsigned().
We did not specify a skip-
parser
_val is another Phoenix
placeholder representing the
rule's synthesized attribute.
eps is a special spirit parser
that consumes no input but
is always successful.
The expression a || b reads:
match a or b and in
sequence. That is, if both a
and b match, it must be in
sequence
13
Employee – Parsing into structs
14
•we need to tell Boost.Fusion about
our employee struct to make it a
first-class fusion citizen that the
grammar can utilize.
•a struct is just a form of a tuple
Employee – Parsing into structs
15
Calculator Grammar
Expr ::= Term ('+' Term | '-' Term)*
Term ::= Factor ('*' Factor | '/' Factor)*
Factor ::= ['-'] (Number | '(' Expr ')')
Number ::= Digit+
“10+9-8*7/6”
16
Calculator
17
Calc Grammar
Parser
(spirit.qi)
Calculator
“10+9-8*7/6”
“10”
The Calculator class
18
Calc Parser
Full match
Boost::spirit::qi
19
Expr ::= Term ('+' Term | '-' Term)*
Term ::= Factor ('*' Factor | '/' Factor)*
Factor ::= ['-'] (Number | '(' Expr ')')
Number ::= Digit+

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Python functions
Python   functionsPython   functions
Python functions
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
Computer Science:Pointers in C
Computer Science:Pointers in CComputer Science:Pointers in C
Computer Science:Pointers in C
 
Introduction to Python Basics
Introduction to Python BasicsIntroduction to Python Basics
Introduction to Python Basics
 
FUNDAMENTAL OF C
FUNDAMENTAL OF CFUNDAMENTAL OF C
FUNDAMENTAL OF C
 
Python libraries
Python librariesPython libraries
Python libraries
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
 
Pointers In C
Pointers In CPointers In C
Pointers In C
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3
 
3 Function Overloading
3 Function Overloading3 Function Overloading
3 Function Overloading
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
5.functions
5.functions5.functions
5.functions
 
Python Data Types
Python Data TypesPython Data Types
Python Data Types
 
Procedures And Functions in Matlab
Procedures And Functions in MatlabProcedures And Functions in Matlab
Procedures And Functions in Matlab
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Handout # 4 functions + scopes
Handout # 4   functions + scopes Handout # 4   functions + scopes
Handout # 4 functions + scopes
 

Similar a Intro To BOOST.Spirit

ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdflailoesakhan
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxfestockton
 
c_programming.pdf
c_programming.pdfc_programming.pdf
c_programming.pdfHome
 
Functions in c
Functions in cFunctions in c
Functions in creshmy12
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptxNileshBorkar12
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptxzueZ3
 
Presentation 5th
Presentation 5thPresentation 5th
Presentation 5thConnex
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3Ahmet Bulut
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
 
Functions in Python Syntax and working .
Functions in Python Syntax and working .Functions in Python Syntax and working .
Functions in Python Syntax and working .tarunsharmaug23
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptxmiki304759
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuplesMalligaarjunanN
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptxKarthickT28
 
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docxCSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docxfaithxdunce63732
 

Similar a Intro To BOOST.Spirit (20)

ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
 
c_programming.pdf
c_programming.pdfc_programming.pdf
c_programming.pdf
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptx
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
Presentation 5th
Presentation 5thPresentation 5th
Presentation 5th
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
 
Python functions
Python functionsPython functions
Python functions
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
Functions in Python Syntax and working .
Functions in Python Syntax and working .Functions in Python Syntax and working .
Functions in Python Syntax and working .
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuples
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docxCSC8503 Principles of Programming Languages Semester 1, 2015.docx
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
 

Más de Will Shen

20180717 Introduction of Seamless BLE Connection Migration System (SeamBlue)
20180717 Introduction of Seamless BLE Connection Migration System (SeamBlue)20180717 Introduction of Seamless BLE Connection Migration System (SeamBlue)
20180717 Introduction of Seamless BLE Connection Migration System (SeamBlue)Will Shen
 
16格筆記讀書法
16格筆記讀書法16格筆記讀書法
16格筆記讀書法Will Shen
 
Bade Smells in Code
Bade Smells in CodeBade Smells in Code
Bade Smells in CodeWill Shen
 
20070514 introduction to test ng and its application for test driven gui deve...
20070514 introduction to test ng and its application for test driven gui deve...20070514 introduction to test ng and its application for test driven gui deve...
20070514 introduction to test ng and its application for test driven gui deve...Will Shen
 
20060411 face recognition using face arg matching
20060411 face recognition using face arg matching20060411 face recognition using face arg matching
20060411 face recognition using face arg matchingWill Shen
 
20060411 Analytic Hierarchy Process (AHP)
20060411 Analytic Hierarchy Process (AHP)20060411 Analytic Hierarchy Process (AHP)
20060411 Analytic Hierarchy Process (AHP)Will Shen
 
20050713 critical paths for gui regression testing
20050713 critical paths for gui regression testing20050713 critical paths for gui regression testing
20050713 critical paths for gui regression testingWill Shen
 
20050314 specification based regression test selection with risk analysis
20050314 specification based regression test selection with risk analysis20050314 specification based regression test selection with risk analysis
20050314 specification based regression test selection with risk analysisWill Shen
 
20041113 A Test Generation Tool for Specifications in the Form of State Machine
20041113 A Test Generation Tool for Specifications in the Form of State Machine20041113 A Test Generation Tool for Specifications in the Form of State Machine
20041113 A Test Generation Tool for Specifications in the Form of State MachineWill Shen
 
Junit Recipes - Elementary tests (2/2)
Junit Recipes - Elementary tests (2/2)Junit Recipes - Elementary tests (2/2)
Junit Recipes - Elementary tests (2/2)Will Shen
 
Junit Recipes - Elementary tests (1/2)
Junit Recipes  - Elementary tests (1/2)Junit Recipes  - Elementary tests (1/2)
Junit Recipes - Elementary tests (1/2)Will Shen
 
Junit Recipes - Intro
Junit Recipes - IntroJunit Recipes - Intro
Junit Recipes - IntroWill Shen
 
20051019 automating regression testing for evolving gui software
20051019 automating regression testing for evolving gui software20051019 automating regression testing for evolving gui software
20051019 automating regression testing for evolving gui softwareWill Shen
 
20060712 automated model based testing of community-driven open-source gui ap...
20060712 automated model based testing of community-driven open-source gui ap...20060712 automated model based testing of community-driven open-source gui ap...
20060712 automated model based testing of community-driven open-source gui ap...Will Shen
 
20041221 gui testing survey
20041221 gui testing survey20041221 gui testing survey
20041221 gui testing surveyWill Shen
 
20060927 application facades
20060927 application facades20060927 application facades
20060927 application facadesWill Shen
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtestWill Shen
 
Data collection for field studies
Data collection for field studiesData collection for field studies
Data collection for field studiesWill Shen
 

Más de Will Shen (18)

20180717 Introduction of Seamless BLE Connection Migration System (SeamBlue)
20180717 Introduction of Seamless BLE Connection Migration System (SeamBlue)20180717 Introduction of Seamless BLE Connection Migration System (SeamBlue)
20180717 Introduction of Seamless BLE Connection Migration System (SeamBlue)
 
16格筆記讀書法
16格筆記讀書法16格筆記讀書法
16格筆記讀書法
 
Bade Smells in Code
Bade Smells in CodeBade Smells in Code
Bade Smells in Code
 
20070514 introduction to test ng and its application for test driven gui deve...
20070514 introduction to test ng and its application for test driven gui deve...20070514 introduction to test ng and its application for test driven gui deve...
20070514 introduction to test ng and its application for test driven gui deve...
 
20060411 face recognition using face arg matching
20060411 face recognition using face arg matching20060411 face recognition using face arg matching
20060411 face recognition using face arg matching
 
20060411 Analytic Hierarchy Process (AHP)
20060411 Analytic Hierarchy Process (AHP)20060411 Analytic Hierarchy Process (AHP)
20060411 Analytic Hierarchy Process (AHP)
 
20050713 critical paths for gui regression testing
20050713 critical paths for gui regression testing20050713 critical paths for gui regression testing
20050713 critical paths for gui regression testing
 
20050314 specification based regression test selection with risk analysis
20050314 specification based regression test selection with risk analysis20050314 specification based regression test selection with risk analysis
20050314 specification based regression test selection with risk analysis
 
20041113 A Test Generation Tool for Specifications in the Form of State Machine
20041113 A Test Generation Tool for Specifications in the Form of State Machine20041113 A Test Generation Tool for Specifications in the Form of State Machine
20041113 A Test Generation Tool for Specifications in the Form of State Machine
 
Junit Recipes - Elementary tests (2/2)
Junit Recipes - Elementary tests (2/2)Junit Recipes - Elementary tests (2/2)
Junit Recipes - Elementary tests (2/2)
 
Junit Recipes - Elementary tests (1/2)
Junit Recipes  - Elementary tests (1/2)Junit Recipes  - Elementary tests (1/2)
Junit Recipes - Elementary tests (1/2)
 
Junit Recipes - Intro
Junit Recipes - IntroJunit Recipes - Intro
Junit Recipes - Intro
 
20051019 automating regression testing for evolving gui software
20051019 automating regression testing for evolving gui software20051019 automating regression testing for evolving gui software
20051019 automating regression testing for evolving gui software
 
20060712 automated model based testing of community-driven open-source gui ap...
20060712 automated model based testing of community-driven open-source gui ap...20060712 automated model based testing of community-driven open-source gui ap...
20060712 automated model based testing of community-driven open-source gui ap...
 
20041221 gui testing survey
20041221 gui testing survey20041221 gui testing survey
20041221 gui testing survey
 
20060927 application facades
20060927 application facades20060927 application facades
20060927 application facades
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
 
Data collection for field studies
Data collection for field studiesData collection for field studies
Data collection for field studies
 

Último

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 MountPuma Security, LLC
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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 interpreternaman860154
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
🐬 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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Último (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Intro To BOOST.Spirit

  • 1. Intro to Boost Spirit Will Shen 2013/03/25
  • 2. TDD Your Shape Grammar Make it can compile “rulessimpleStreets.cga” 2
  • 3. BOOST Spirit.Qi Spirit.Qi is designed to be a practical parsing tool. The ability to generate a fully-working parser from a formal EBNF specification inlined in C++ significantly reduces development time. 3
  • 4. Tutorials – Parsing Floating Number • Parsing a number: double_ • Parsing two numbers: double_ >> double_ • Parsing zero of more numbers: *double_ • Parsing a comma-delimited list of numbers: double_ >> *( char_(„,‟) >> double_) 4
  • 5. Parsing Semantic Actions void Print(int n); Presented are various ways to attach semantic actions: • Using plain function pointer • Using simple function object • Using Boost.Bind with a plain function • Using Boost.Bind with a member function • Using Boost.Lambda 5
  • 7. The First Complex parser 1/2 1. Alternates: e.g. a | b. Try a first. If it succeeds, good. If not, try the next alternative, b. 2. Optional: e.g. -p. Match the parser p zero or one time. The complex parser presented above reads as: • One or two real numbers in parentheses, separated by comma (the second number is optional) • OR a single real number. This parser can parse complex numbers of the form: • (123.45, 987.65) • (123.45) • 123.45 7
  • 8. The First Complex parser 2/2 8
  • 9. Sum – Adding Numbers 9
  • 10. Number List – stuffing numbers into a std::vector 10
  • 12. Roman Numerals - Grammars A grammar encapsulates one or more rules. It has the same template parameters as the rule. You declare a grammar by: 1. deriving a struct (or class) from the grammar class template 2. declare one or more rules as member variables 3. initialize the base grammar class by giving it the start rule (its the first rule that gets called when the grammar starts parsing) 4. initialize your rules in your constructor 12
  • 13. Roman Numerals - Grammars The grammar and start rule signature is unsigned(). We did not specify a skip- parser _val is another Phoenix placeholder representing the rule's synthesized attribute. eps is a special spirit parser that consumes no input but is always successful. The expression a || b reads: match a or b and in sequence. That is, if both a and b match, it must be in sequence 13
  • 14. Employee – Parsing into structs 14 •we need to tell Boost.Fusion about our employee struct to make it a first-class fusion citizen that the grammar can utilize. •a struct is just a form of a tuple
  • 15. Employee – Parsing into structs 15
  • 16. Calculator Grammar Expr ::= Term ('+' Term | '-' Term)* Term ::= Factor ('*' Factor | '/' Factor)* Factor ::= ['-'] (Number | '(' Expr ')') Number ::= Digit+ “10+9-8*7/6” 16
  • 18. The Calculator class 18 Calc Parser Full match
  • 19. Boost::spirit::qi 19 Expr ::= Term ('+' Term | '-' Term)* Term ::= Factor ('*' Factor | '/' Factor)* Factor ::= ['-'] (Number | '(' Expr ')') Number ::= Digit+