Skip to content

Details

Almost 10 years ago, we looked at Spirit 2.x for parsing. Since that time the Spirit library has evolved to Spirit X3, a C++14 version of Spirit that is "an object-oriented, recursive-descent parser for C++". Spirit X3 is a header-only library that allows you to write your grammar directly in C++ using the mechanism of expression templates. When expressed as a Spirit X3 grammar in C++, the resulting code closely resembles BNF (Backus-Naur Form) representations of a grammar.

The common result of parsing a piece of text is an abstract syntax tree (AST) that represents the structure parsed from the input. Spirit has a rich system of attribute synthesis that can be used to build the AST directly during parsing. The application uses the resulting AST from parsing to perform some function. In a compiler, the AST is used to generate code in some form for the target processor.

This month, Richard Thomson will give us a refresher on parsing with Spirit X3. Along the way we'll look at the following topics:

  • How to parse basic primitive values (float, int, string, etc.)
  • How to combine primitive parsers to handle complex sequences and structures
  • How to add error handling to the parse process
  • How to annotate parsed elements with the location in the source input for better error messages
  • How to customize the parsing process with a custom AST data structure
  • How to traverse the custom AST using the Visitor pattern

This will be an online meeting, so drinks and snacks are on you!

Join the meeting here: https://meet.xmission.com/Utah-Cpp-Programmers

Watch previous topics on the Utah C++ Programmers YouTube channel:
https://www.youtube.com/@UtahCppProgrammers

Future topics: https://utahcpp.wordpress.com/future-meeting-topics/
Past topics: https://utahcpp.wordpress.com/past-meeting-topics/

Related topics

C & C++
Programming Languages
Computer Programming
Mobile Development
Software Development

You may also like