Spirit 2.1 Joel De Guzman Hartmut Kaiser Copyright © 2001-2009 Joel De Guzman, Hartmut Kaiser
Total Page:16
File Type:pdf, Size:1020Kb
Spirit 2.1 Joel de Guzman Hartmut Kaiser Copyright © 2001-2009 Joel de Guzman, Hartmut Kaiser Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Table of Contents Preface ................................................................................................................................................................. 3 What's New .......................................................................................................................................................... 6 Introduction .......................................................................................................................................................... 8 Structure ............................................................................................................................................................. 13 Include ....................................................................................................................................................... 13 Abstracts ............................................................................................................................................................ 15 Syntax Diagram ........................................................................................................................................... 15 Parsing Expression Grammar .......................................................................................................................... 17 Attributes .................................................................................................................................................... 19 Attributes of Primitive Components ......................................................................................................... 19 Attributes of Compound Components ....................................................................................................... 20 More About Attributes of Compound Components ...................................................................................... 22 Attributes of Rules and Grammars ........................................................................................................... 23 Qi - Writing Parsers .............................................................................................................................................. 24 Tutorials ..................................................................................................................................................... 24 Quick Start .......................................................................................................................................... 24 Warming up ........................................................................................................................................ 24 Semantic Actions ................................................................................................................................. 27 Complex - Our first complex parser ......................................................................................................... 29 Sum - adding numbers ........................................................................................................................... 30 Number List - stuffing numbers into a std::vector ....................................................................................... 32 Number List Redux - list syntax .............................................................................................................. 33 Number List Attribute - one more, with style ............................................................................................. 34 Roman Numerals .................................................................................................................................. 35 Employee - Parsing into structs ............................................................................................................... 40 Mini XML - ASTs! ............................................................................................................................... 45 Mini XML - Error Handling ................................................................................................................... 51 Quick Reference .......................................................................................................................................... 54 Common Notation ................................................................................................................................ 54 Qi Parsers ........................................................................................................................................... 56 Compound Attribute Rules ..................................................................................................................... 61 Nonterminals ....................................................................................................................................... 65 Semantic Actions ................................................................................................................................. 66 Phoenix .............................................................................................................................................. 67 Reference ................................................................................................................................................... 67 Parser Concepts ................................................................................................................................... 67 Basics ................................................................................................................................................ 74 Parse API ............................................................................................................................................ 78 Action ................................................................................................................................................ 82 Auxiliary ............................................................................................................................................ 83 Binary ................................................................................................................................................ 93 Char ................................................................................................................................................. 100 Directive ........................................................................................................................................... 106 1 XML to PDF by RenderX XEP XSL-FO Formatter, visit us at http://www.renderx.com/ Spirit 2.1 Nonterminal ...................................................................................................................................... 116 Numeric ............................................................................................................................................ 121 Operator ........................................................................................................................................... 137 Stream .............................................................................................................................................. 155 String ............................................................................................................................................... 158 Karma - Writing Generators .................................................................................................................................. 164 Tutorials ................................................................................................................................................... 164 Quick Start ........................................................................................................................................ 164 Warming up ....................................................................................................................................... 164 Semantic Actions ................................................................................................................................ 167 Complex - A first more complex generator ............................................................................................... 170 Complex - Made easier ........................................................................................................................ 171 Number List - Printing Numbers From a std::vector ................................................................................... 174 Matrix of Numbers - Printing Numbers From a Matrix ............................................................................... 176 Quick Reference ......................................................................................................................................... 176 Common Notation .............................................................................................................................. 176 Karma Generators ............................................................................................................................... 177 Compound Attribute Rules ..................................................................................................................