Debian Codegraph @

documentation/manual/grammar/polymorphicdirective.yo

raw
1 Specifying the tt(%polymorphic) directive results in a parser using
2 polymorphic semantic values. Polymorphic semantic value specifications
3 consist of a em(tag), which is a bf(C++) identifier, and a bf(C++) type
4 definition.
5
6 Tags and type definitions are separated by colons, and multiple semantic
7 value specifications are separated by semicolons. The semicolon trailing the
8 final semantic value specification is optional: type name specifications
9 end at a semicolon or at a percent character (indicating the beginning of the
10 next directive). End of line comment and standard bf(C) comment may also be
11 used, but both are ignored.
12
13 The tt(%polymorphic) directive may be specified only once, and the
14 tt(%polymorphic, %stype) and tt(%union) directives are mutually exclusive.
15
16 Here is an example, defining three semantic values types: tt(int),
17 tt(std::string) and tt(std::vector<double>):
18 verb(
19 %polymorphic INT: int; STRING: std::string;
20 VECT: std::vector<double>
21 )
22 The identifier to the left of the colon is called the em(type-tag) (or
23 simply `em(tag)'), and the type definition to the right of the colon is called
24 the em(type-definition). Types specified at the tt(%polymorphic)
25 type-definitions must be built-in types or class-type declarations. Since
26 bic() version 4.12.00 the types no longer have to be default-constructible.
27
28 As the parser's generic semantic value type is called tt(STYPE_), and as
29 functions called by the parser may return tt(STYPE_) values and may expect
30 tt(STYPE_) arguments, grammar symbols can also be associated with the generic
31 tt(STYPE_) semantic type using tt(%type <STYPE_>) directives.
32
33 To prevent ambiguities the generic tt(STYPE_) type cannot be specified as a
34 polymorphic type. E.g., a specification like tt(GENERIC: STYPE_) cannot be
35 used when defining the tag/type pairs at the tt(%polymorphic)
36 directive.
37
38 When polymorphic type-names refer to types that have not yet been declared
39 by the parser's base class header, then these types must be declared in a
40 separate header file, included into the parser's base class header file
41 through the tt(%baseclass-preinclude) directive.