preface.qbk
来自「Boost provides free peer-reviewed portab」· QBK 代码 · 共 218 行
QBK
218 行
[/============================================================================== Copyright (C) 2001-2008 Joel de Guzman Copyright (C) 2001-2008 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)===============================================================================/][section Preface][:['["Examples of designs that meet most of the criteria for"goodness" (easy to understand, flexible, efficient) are a recursive-descent parser, which is traditional procedural code. Another exampleis the STL, which is a generic library of containers and algorithmsdepending crucially on both traditional procedural code and onparametric polymorphism.]] [*--Bjarne Stroustrup]][heading History][heading /80s/]In the Mid 80s, Joel wrote his first calculator in Pascal. It has beenan unforgettable coding experience. He was amazed how a mutuallyrecursive set of functions can model a grammar specification. In time,the skills he acquired from that academic experience became verypractical. Periodically Joel was tasked to do some parsing. Forinstance, whenever he needs to perform any form of I/O, even inbinary, he tries to approach the task somewhat formally by writing agrammar using Pascal- like syntax diagrams and then write acorresponding recursive-descent parser. This worked very well.[heading /90s/]The arrival of the Internet and the World Wide Web magnified thisthousand-fold. At one point Joel had to write an HTML parser for a Webbrowser project. He got a recursive-descent HTML parser working basedon the W3C formal specifications easily. He was certainly glad thatHTML had a formal grammar specification. Because of the influence ofthe Internet, Joel then had to do more parsing. RFC specificationswere everywhere. SGML, HTML, XML, even email addresses and thoseseemingly trivial URLs were all formally specified using small EBNF-style grammar specifications. This made him wish for a tool similar tobig- time parser generators such as YACC and ANTLR, where a parser isbuilt automatically from a grammar specification. Yet, he wants it tobe extremely small; small enough to fit in my pocket, yet scalable.It must be able to practically parse simple grammars such as emailaddresses to moderately complex grammars such as XML and perhaps somesmall to medium-sized scripting languages. Scalability is a primegoal. You should be able to use it for small tasks such as parsingcommand lines without incurring a heavy payload, as you do when youare using YACC or PCCTS. Even now that it has evolved and matured tobecome a multi-module library, true to its original intent, Spirit canstill be used for extreme micro-parsing tasks. You only pay forfeatures that you need. The power of Spirit comes from its modularityand extensibility. Instead of giving you a sledgehammer, it gives youthe right ingredients to create a sledgehammer easily.The result was Spirit. Spirit was a personal project that wasconceived when Joel was doing R&D in Japan. Inspired by the GoF'scomposite and interpreter patterns, he realized that he can model arecursive-descent parser with hierarchical-object composition ofprimitives (terminals) and composites (productions). The originalversion was implemented with run-time polymorphic classes. A parser isgenerated at run time by feeding in production rule strings such as: "prod ::= {'A' | 'B'} 'C';"A compile function compiled the parser, dynamically creating ahierarchy of objects and linking semantic actions on the fly. A veryearly text can be found here: __early_spirit__.[heading /2001 to 2006/]Version 1.0 to 1.8 was a complete rewrite of the original Spiritparser using expression templates and static polymorphism, inspired bythe works of Todd Veldhuizen (__todd__exprtemplates__, C++ Report,June 1995). Initially, the static-Spirit version was meant only toreplace the core of the original dynamic-Spirit. Dynamic-spiritneeded a parser to implement itself anyway. The original employed ahand-coded recursive-descent parser to parse the input grammarspecification strings. Incidentially it was the time, when Hartmutjoined the Spirit development.After its initial "open-source" debut in May 2001, static-Spiritbecame a success. At around November 2001, the Spirit website had anactivity percentile of 98%, making it the number one parser tool atSource Forge at the time. Not bad for such a niche project such as aparser library. The "static" portion of Spirit was forgotten andstatic-Spirit simply became Spirit. The library soon evolved toacquire more dynamic features.Spirit was formally accepted into __boost__ in October 2002. Boost isa peer-reviewed, open collaborative development effort that is acollection of free Open Source C++ libraries covering a wide range ofdomains. The Boost Libraries have become widely known as an industrystandard for design and implementation quality, robustness, andreusability.[heading /2007/]Over the years, especially after Spirit was accepted into Boost,Spirit has served its purpose quite admirably. The focus of what we'llnow call [*/Classic-Spirit/] (versions prior to 2.0) was ontransduction parsing where the input string is merely translated to anoutput string. A lot of parsers are of the transduction type. When thetime came to add attributes to the parser library, it was done ratherin an ad-hoc manner, with the goal being 100% backward compatible withclassic Spirit. Some parsers have attributes, some don't.Spirit V2 is another major rewrite. Spirit V2 grammars are fullyattributed (see __attr_grammar__). All parser components haveattributes. To do this efficiently and ellegantly, we had to use acouple of infrastructure libraries. Some of which haven't been writtenyet at the time, some were quite new when Spirit debuted, and someneeded work. __mpl__ is an important infrastructure library, yet isnot sufficient to implement Spirit V2. Another library had to bewritten: __fusion__. Fusion sits between MPL and STL --between compiletime and runtime -- mapping types to values. Fusion is a directdescendant of both MPL and __boost_tuples__ (Fusion is now a fullfledged __boost__ library). __phoenix__ also had to be beefed up tosupport Spirit V2. The result is __phoenix2__. Last but not least,Spirit V2 uses an __todd__exprtemplates__ library called__boost_proto__.[heading New Ideas: Spirit V2]Just before the development of Spirit V2 began, Hartmut came acrossthe __string_template__ library which is a part of the ANTLR parserframework. It is a Java template engine (with ports for C# and Python)for generating source code, web pages, emails, or any other formattedtext output. With it, he got the the idea of using a formal notation(a grammar) to describe the expected structure of an input charactersequence. The same grammar may be used to formalize the structure of acorresponding output character sequence. This is possible becauseparsing, most of the time, is implemented by comparing the input withthe patterns defined by the grammar. If we use the same patterns toformat a matching output, the generated sequence will follow the rulesof the grammar as well.This insight lead to the implementation of a grammar driven output generationlibrary compatibile with the Spirit parser library. As it turned out, parsingand generation are tightly connected and have very similar concepts. Theduality of these two sides of the same medal is ubiquitous, whichallowed us to build the parser library __qi__ and the generator library__karma__ using the same component infastructure.The idea of creating a lexer library well integrated with the Spirit parsers isnot new. This has been discussed almost for the whole time of the existence ofClassic-Spirit (pre V2) now. Several attempts to integrate existing lexerlibraries and frameworks with Spirit have been made and served as a proof ofconcept and usability (for example see __wave__: The Boost C/C++ PreprocessorLibrary, and __slex__: a fully dynamic C++ lexer implemented with Spirit).Based on these experiences we added __lex__: a fully integrated lexer libraryto the mix, allowing to take advantage of the power of regular expressions fortoken matching, removing pressure from the parser components, simplifyingparser grammars. Again, Spirit's modular structure allowed us to reuse the sameunderlying component library as for the parser and generator libraries.[heading How to use this manual]Each major section (there are two: __sec_qi_and_karma__, and __sec_lex__) isroughly divided into 3 parts:# Tutorials: A step by step guide with heavily annotated code. These are meant to get the user acquainted with the library as quickly as possible. The objective is to build the confidence of the user in using the library using abundant examples and detailed instructions. Examples speak volumes.# Abstracts: A high level summary of key topics. The objective is to give the user a high level view of the library, the key concepts, background and theories.# Reference: Detailed formal technical reference. We start with a quick reference -- an easy to use table that maps into the reference proper. The reference proper starts with C++ __cpp_concepts__ followed by models of the concepts.Some icons are used to mark certain topics indicative of their relevance.These icons precede some text to indicate:[table Icons [[Icon] [Name] [Meaning]] [[__note__] [Note] [Generally useful information (an aside that doesn't fit in the flow of the text)]] [[__tip__] [Tip] [Suggestion on how to do something (especially something that not be obvious)]] [[__important__] [Important] [Important note on something to take particular notice of]] [[__caution__] [Caution] [Take special care with this - it may not be what you expect and may cause bad results]] [[__danger__] [Danger] [This is likely to cause serious trouble if ignored]]]This documentation is automatically generated by Boost QuickBook documentationtool. QuickBook can be found in the __boost_tools__.[heading Support]Please direct all questions to Spirit's mailing list. You can subscribe to the__spirit_list__. The mailing list has a searchable archive. A search link tothis archive is provided in __spirit__'s home page. You may also read and postmessages to the mailing list through __spirit_general__ (thanks to __gmane__).The news group mirrors the mailing list. Here is a link to the archives:__mlist_archive__.[endsect] [/ Preface]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?