Ticket #2511: roman.patch

File roman.patch, 3.3 KB (added by Charles Brockman <cmbrockman@…>, 14 years ago)
  • libs/spirit/doc/qi_and_karma/roman.qbk

     
    1919The symbol table holds a dictionary of symbols where each symbol is a sequence
    2020of characters (a `char`, `wchar_t`, `int`, enumeration etc.) . The template
    2121class, parameterized by the character type, can work efficiently with 8, 16, 32
    22 and even 64 bit characters. Mutable data of type T is associated with each
     22and even 64 bit characters. Mutable data of type T are associated with each
    2323symbol.
    2424
    25 Traditionally, symbol table management is maintained seperately outside the BNF
     25Traditionally, symbol table management is maintained separately outside the BNF
    2626grammar through semantic actions. Contrary to standard practice, the Spirit
    27 symbol table class symbols is-a parser. An object of which may be used
     27symbol table class symbols is-a parser an object of which may be used
    2828anywhere in the EBNF grammar specification. It is an example of a dynamic
    2929parser. A dynamic parser is characterized by its ability to modify its behavior
    3030at run time. Initially, an empty symbols object matches nothing. At any time,
     
    6363to the `phrase_parse` function. The expression evaluates into a temporary,
    6464unnamed parser which is passed into the `phrase_parse` function, used, and then
    6565destroyed. This is fine for small parsers. When the expressions get complicated,
    66 you'd want to break the expressions into smaller easier to understand pieces,
     66you'd want to break the expressions into smaller, easier-to-understand pieces,
    6767name them, and refer to them from other parser expressions by name.
    6868
    69 A parser expression can be assigned to, what is called, a "rule". There are
     69A parser expression can be assigned to what is called a "rule". There are
    7070various ways to declare rules. The simplest form is:
    7171
    7272    rule<Iterator> r;
     
    119119
    120120# deriving a struct (or class) from the `grammar` class template
    121121# declare one or more rules as member variables
    122 # initialize the base grammar class by giving it the start rule (its the first
     122# initialize the base grammar class by giving it the start rule (it's the first
    123123  rule that gets called when the grammar starts parsing)
    124124# initialize your rules in your constructor
    125125
     
    137137  numerals.
    138138
    139139* `roman::base_type` is a typedef for `grammar<Iterator, unsigned()>`. If
    140    `roman` was not a template, you can simply write: base_type(start)
     140   `roman` was not a template, you could simply write: base_type(start)
    141141
    142 * But it's best to make your grammar templates, so that they can be reused
     142* It's best to make your grammar templates such that they can be reused
    143143  for different iterator types.
    144144
    145145* `_val` is another __phoenix__ placeholder representing the rule's synthesized
     
    160160[tutorial_roman_grammar_parse]
    161161
    162162`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 not
     163around we are using the no-skipping version of the parse functions. We do not
    164164want to skip any spaces! We are also passing in an attribute, `unsigned result`,
    165165which will receive the parsed value.
    166166