Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
usr
/
share
/
doc
/
re2c
/
manual
/
eof
/
Filename :
03_eof_rule.rst_
back
Copy
Sentinel character with bounds checks ------------------------------------- In this example the lexer uses sentinel character with bounds checks to handle the end of input (this method was added in version 1.2). The program counts single-quoted strings separated with spaces. The sentinel character is null, which is specified with ``re2c:eof = 0;`` configuration. Null is the last character of each input string --- this is essential to detect the end of input. Null, as well as any other character, is allowed in the middle of a rule (for example, ``'aaa\0aa'\0`` is valid input, but ``'aaa\0`` is a syntax error). Bounds checks are generated in each state that has a switch on an input character, in the conditional branch that corresponds to null (that branch may also cover other characters --- re2c does not split out a separate branch for sentinel, because increasing the number of branches degrades performance more than bounds checks do). Bounds checks are of the form ``YYLIMIT <= YYCURSOR`` or ``YYLESSTHAN(1)`` with generic API. If a bounds check succeeds, the lexer will continue matching. If a bounds check fails, the lexer has reached the end of input, and it should stop. In this example ``YYFILL`` is disabled with ``re2c:yyfill:enable = 0;`` and the lexer does not attempt to get more input (see another example that uses ``YYFILL`` in the `YYFILL with sentinel character`_ section). When the end of input has been reached, there are three possibilities: if the lexer is in the initial state, it will match the end of input rule ``$``, otherwise it will either fallback to a previously matched rule (including default rule ``*``) or go to a default state, causing `-Wundefined-control-flow <https://re2c.org/manual/warnings/warnings.html#wundefined-control-flow>`_.