Ticket #2511: roman.patch
File roman.patch, 3.3 KB (added by , 14 years ago) |
---|
-
libs/spirit/doc/qi_and_karma/roman.qbk
19 19 The symbol table holds a dictionary of symbols where each symbol is a sequence 20 20 of characters (a `char`, `wchar_t`, `int`, enumeration etc.) . The template 21 21 class, parameterized by the character type, can work efficiently with 8, 16, 32 22 and even 64 bit characters. Mutable data of type T isassociated with each22 and even 64 bit characters. Mutable data of type T are associated with each 23 23 symbol. 24 24 25 Traditionally, symbol table management is maintained sep erately outside the BNF25 Traditionally, symbol table management is maintained separately outside the BNF 26 26 grammar through semantic actions. Contrary to standard practice, the Spirit 27 symbol table class symbols is-a parser . An object of which may be used27 symbol table class symbols is-a parser an object of which may be used 28 28 anywhere in the EBNF grammar specification. It is an example of a dynamic 29 29 parser. A dynamic parser is characterized by its ability to modify its behavior 30 30 at run time. Initially, an empty symbols object matches nothing. At any time, … … 63 63 to the `phrase_parse` function. The expression evaluates into a temporary, 64 64 unnamed parser which is passed into the `phrase_parse` function, used, and then 65 65 destroyed. This is fine for small parsers. When the expressions get complicated, 66 you'd want to break the expressions into smaller easier tounderstand pieces,66 you'd want to break the expressions into smaller, easier-to-understand pieces, 67 67 name them, and refer to them from other parser expressions by name. 68 68 69 A parser expression can be assigned to , what is called,a "rule". There are69 A parser expression can be assigned to what is called a "rule". There are 70 70 various ways to declare rules. The simplest form is: 71 71 72 72 rule<Iterator> r; … … 119 119 120 120 # deriving a struct (or class) from the `grammar` class template 121 121 # declare one or more rules as member variables 122 # initialize the base grammar class by giving it the start rule (it s the first122 # initialize the base grammar class by giving it the start rule (it's the first 123 123 rule that gets called when the grammar starts parsing) 124 124 # initialize your rules in your constructor 125 125 … … 137 137 numerals. 138 138 139 139 * `roman::base_type` is a typedef for `grammar<Iterator, unsigned()>`. If 140 `roman` was not a template, you c ansimply write: base_type(start)140 `roman` was not a template, you could simply write: base_type(start) 141 141 142 * But it's best to make your grammar templates, sothat they can be reused142 * It's best to make your grammar templates such that they can be reused 143 143 for different iterator types. 144 144 145 145 * `_val` is another __phoenix__ placeholder representing the rule's synthesized … … 160 160 [tutorial_roman_grammar_parse] 161 161 162 162 `roman_parser` is an object of type `roman` -our roman numeral parser. This time 163 around ,we are using the no-skipping version of the parse functions. We do not163 around we are using the no-skipping version of the parse functions. We do not 164 164 want to skip any spaces! We are also passing in an attribute, `unsigned result`, 165 165 which will receive the parsed value. 166 166