In this section a small demo-parser is developed using polymorphic semantic
values.  Its tt(%polymorphic) directive looks like this:
        verb(
    %polymorphic INT: int; TEXT: std::string;
        )
    Furthermore, the grammar declares tokens tt(INT) and tt(IDENTIFIER), and
pre-associates the tt(TEXT) tag with the tt(identifier) nonterminal,
associates the tt(INT) tag with the tt(int) nonterminal. The tt(combi)
nonterminal is associated with the generic tt(STYPE_) semantic value type:
        verb(
    %type <TEXT>    identifier
    %type <INT>     int
    %type <STYPE_> combi
        )
    
    The parser's grammar is simple, expecting input lines, formatted
according to the following (tt(rule)) production rule:
        verb(
    rule:
        identifier '(' identifier ')' '\n'
    |
        identifier '=' int '\n'
    |
        combi '\n'
    ;
        )
    
    The rules for tt(identifier) and tt(int) return, respectively, text and an
tt(int) value:
        verb(
    identifier:
        IDENTIFIER
        {
            $$ = d_scanner.matched();
        }
    ;
    int:
        INT
        {
            $$ = d_scanner.intValue();
        }
    ;
        )

These simple assignments can be used as tt(int) is pre-associated with the
tt(INT) tag and tt(identifier) is asociated with the tt(TEXT) tag. 

The tt(combi) rule, which is used in one of the production rules of
`tt(rule)', accepts a single tt(int) value, as well as an identifier. So it
cannot be associated with a single polymorphic type. But as it is associated
with the generic tt(STYPE_) type, it can pass on any polymorphic value. In
tt(rule's) production rule the generic semantic value is then simply passed on
to tt(process), expecting a plain tt(STYPE_ const &). The function
tt(process) has to inspect the semantic value's tag to learn what
kind of value is stored inside the received semantic value. Here are the
definition of the tt(combi) nonterminal and action blocks for the tt(rule)
nonterminal:
        verb(
    combi:          
        int
    |
        identifier
    ;
        
    rule:
        identifier '(' identifier ')' '\n'
        {
            cout << $1 << " " << $3 << '\n';
        }
    |
        identifier '=' int '\n'
        {
            cout << $1 << " " << $3 << '\n';
        }
    |
        combi '\n'
        {
            process($1);
        }
    ;
        )

Note that tt(combi's) production rules do not define action blocks. The
standard way to handle these situations is to add tt($$ = $1) action blocks to
non-empty production rules not defining final action blocks. This works well
in the current example, but a tt(default-actions quiet) (or tt(warn)) option
or directive can also be used.

The function tt(process), called from tt(combi's) action block, inspects the
semantic value's tag to select the proper way of handling the received
semantic value. Here is its implementation:
        verb(
    void Parser::process(STYPE_ &semVal) const
    {
        if (semVal.tag() == Tag_::INT)
            cout << "Saw an int-value: " << semVal.get<Tag_::INT>() << '\n';
        else
            cout << "Saw text: " << semVal.get<Tag_::TEXT>() << '\n';
    }
        )






