Debian Codegraph @

documentation/manual/class/lex.yo

raw
1 The tt(int lex()) private member function is called by the tt(parse())
2 member to obtain the next lexical token. By default it is not implemented, but
3 the tt(%scanner) directive (see section ref(SCANNER)) may be used to
4 pre-implement a standard interface to a lexical analyzer.
5
6 The tt(lex()) member function interfaces to the lexical scanner, and it is
7 expected to return the next token produced by the lexical scanner. This token
8 may either be a plain character or it may be one of the symbolic tokens
9 defined in the bf(Parser::Tokens) enumeration. Any zero or negative token
10 value is interpreted as `end of input', causing tt(parse()) to return.
11
12 The tt(lex()) member function may be implemented in various ways:
13 itemization(
14 it() By default, if the tt(--scanner) option or tt(%scanner) directive is
15 provided bic() assumes that it should interface to the scanner generated by
16 bf(flexc++)(1). In this case, the scanner token function is called as
17 verb(
18 d_scanner.lex()
19 )
20 and the scanner's matched text function is called as
21 verb(
22 d_scanner.matched()
23 )
24
25
26 it() tt(lex()) may itself implement a lexical analyzer (a
27 em(scanner)). This may actually be a useful option when the input offered to
28 the program using b()'s parser class is not overly complex. This approach was
29 used when implementing the earlier examples (see sections ref(RPNLEX) and
30 ref(MFLEX)).
31
32 it() tt(lex()) may call a external function or member function of class
33 implementing a lexical scanner, and return the information offered by this
34 external function. When using a class, an object of that class could also be
35 defined as additional data member of the parser (see the next
36 alternative). This approach can be followed when generating a lexical scanner
37 from a lexical scanner generating tool like bf(lex)(1) or bf(flex++)(1). The
38 latter program allows its users to generate a scanner em(class).
39
40 it() To interface bic() to code generated by bf(flex)(1), the tt(--flex)
41 option or tt(%flex) directive can be used in combination with the
42 tt(--scanner) directive or tt(%scanner) option. In this case the scanner token
43 function is called as
44 verb(
45 d_scanner.yylex()
46 )
47 and the scanner's matched text function is called as
48 verb(
49 d_scanner.YYText()
50 )
51 )
52
53