<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage 2.0">
<title>Gelex: The Generated Scanner</title>
</head>

<body bgcolor="#FFFFFF">

<table border="0" width="100%">
    <tr>
        <td><font size="6"><strong>The Generated Scanner</strong></font></td>
        <td align="right"><a href="description.html"><img
        src="image/previous.gif" alt="Previous" border="0"
        width="40" height="40"></a><a href="options.html"><img
        src="image/next.gif" alt="Next" border="0" width="40"
        height="40"></a></td>
    </tr>
</table>

<hr size="1">

<p>For each scanner description file given as input, <em>gelex</em>
will generate an Eiffel class as output. By default <em>gelex</em>
sends its output to the standard output but this can easily be
overridden with option <a href="options.html#outfile"><font
color="#800000"><tt>-o filename</tt></font></a>.</p>

<p>The deferred class <a href="skeleton.html"><font
color="#008080"><em><tt>YY_SCANNER</tt></em></font></a>, which is
part of <em>Gobo Eiffel Lexical Library</em>, provides an
abstraction for scanners. Every scanner class generated by <em>gelex</em>
will be a descendant of this class. The main feature of <font
color="#008080"><em><tt>YY_SCANNER</tt></em></font> is routine <a
href="skeleton.html#read_token" name="read_token"><font
color="#008080"><em><tt>read_token</tt></em></font></a> which,
when called, scans tokens from the <a
href="actions.html#input_buffer">input buffer</a> until it either
reaches an end-of-file or <a href="actions.html#last_token"><font
color="#008080"><em><tt>last_token</tt></em></font></a> is given
a non-negative value. Each time <font color="#008080"><em><tt>read_token</tt></em></font>
is called again it continues processing tokens from where it last
left off until it either reaches the end of the file or <font
color="#008080"><em><tt>last_token</tt></em></font> is given a
non-negative value again. On the other hand, the routine <a
href="skeleton.html#scan" name="scan"><font color="#008080"><em><tt>scan</tt></em></font></a>
scans the input buffer until it reaches the end-of-file, ignoring
successive values of <font color="#008080"><em><tt>last_token</tt></em></font>.
Class <font color="#008080"><em><tt>YY_SCANNER</tt></em></font>
is equipped with three procedures which should be used as
creation routines in descendant classes. These routines are <a
href="skeleton.html#make" name="make"><font color="#008080"><em><tt>make</tt></em></font></a>
which prepares the scanner for scanning from the standard input, <a
href="skeleton.html#make_with_file" name="make_with_file"><font
color="#008080"><em><tt>make_with_file</tt></em></font></a> or
<a href="skeleton.html#make_with_unicode_file" name="make_with_unicode_file"><font
color="#008080"><em><tt>make_with_unicode_file</tt></em></font></a>
for scanning from a given file, and <a
href="skeleton.html#make_with_buffer" name="make_with_buffer"><font
color="#008080"><em><tt>make_with_buffer</tt></em></font></a> for
scanning from a given input buffer. Before scanning a new input
buffer, the scanner should be reinitialized using routine <a
href="skeleton.html#reset" name="reset"><font color="#008080"><em><tt>reset</tt></em></font></a>.
Also available to descendants of <font color="#008080"><em><tt>YY_SCANNER</tt></em></font><font
color="#008080" size="2" face="Courier New"><em> </em></font>is a
set of features which can be called from the semantic <a
href="actions.html">actions</a>.</p>

<p>An implementation for most of these routines described above
is provided in class <font color="#008080"><em><tt>YY_SCANNER_SKELETON</tt></em></font>.
This class has itself three descendants, each of them providing a
different flavor of the pattern-matching engine <font
face="Symbol">-</font> a Deterministic Finite Automaton (or <font
size="2">DFA</font> for short) <font face="Symbol">-</font> used
for the implementation of feature <font color="#008080"><em><tt>read_token</tt></em></font>.
The first of these three classes is <font color="#008080"><em><tt>YY_COMPRESSED_SCANNER_SKELETON</tt></em></font>
whose <font size="2">DFA</font> is optimized in terms of memory
space. <em>Gelex</em> should in that case compress the generated
tables by taking advantage of similar transition functions for
different states. This is what<em> gelex</em> does by default.
The second class is <font color="#008080"><em><tt>YY_FULL_SCANNER_SKELETON</tt></em></font>
whose <font size="2">DFA</font> is optimized in terms of
execution speed but uses big tables. In this case the option <a
href="options.html#full"><font color="#800000"><tt>full</tt></font></a>
has to be specified for <em>gelex</em> to generate non-compressed
tables. The last class is <font color="#008080"><em><tt>YY_INTERACTIVE_SCANNER_SKELETON</tt></em></font>
whose <font size="2">DFA</font> can deal with interactive input
such as input from the keyboard. An interactive
scanner is one that only looks ahead to decide what token has
been matched if it absolutely has to. It turns out that always
looking one extra character ahead, even if the scanner has
already seen enough text to disambiguate the current token, is a
bit faster than only looking ahead when necessary. But scanners
that always look ahead give dreadful interactive performance; for
example, when one types a newline, it is not recognized as a
newline token until one enters another token, which often means
typing in another whole line. <font color="#008080"><em><tt>YY_INTERACTIVE_SCANNER_SKELETON</tt></em></font>
is an heir of <font color="#008080"><em><tt>YY_COMPRESSED_SCANNER_SKELETON</tt></em></font>
and only requires from <em>gelex</em> to generated compressed
tables. Because of the performance penalty already implied by
this more intuitive interactive behavior, this facility is not
available in conjunction with full table scanners.</p>

<p><em>Gelex</em> does not automatically generate the note,
class header, formal generics, obsolete, inheritance, creation
and invariant clauses. These have to be specified in <a
href="description.html#eiffel_declarations">Eiffel declarations</a>
in the first section and in the <a
href="description.html#user_code">user code section</a> of the
scanner <a href="description.html">description file</a>. In
particular, one has to specify which of the three scanner
skeleton classes described above (namely <font color="#008080"><em><tt>YY_COMPRESSED_SCANNER_SKELETON</tt></em></font>,<font
color="#008080" size="2" face="Courier New"><em> </em></font><font
color="#008080"><em><tt>YY_FULL_SCANNER_SKELETON</tt></em></font>
or <font color="#008080"><em><tt>YY_INTERACTIVE_SCANNER_SKELETON</tt></em></font>)
to inherit from as an implementation for its pattern-matching
engine. The following example shows a typical scanner description
file:</p>

<blockquote>
    <pre><font color="#0000FF">%{</font>
<font color="#008080"><em><strong>class</strong></em><em> MY_SCANNER

</em><em><strong>inherit</strong></em><em>

    YY_COMPRESSED_SCANNER_SKELETON
        </em><em><strong>redefine</strong></em><em>
            make, reset
        </em><em><strong>end</strong></em><em>

</em><em><strong>create</strong></em><em>

    make</em><em>
</em><font color="#0000FF">%}</font>

<font color="#0000FF">%%</font>

<font color="#FF0000">...patterns...</font>   </font><font color="#008080"><em>...actions</em>...</font>

<font color="#0000FF">%%</font>

<font color="#008080"><em><strong>feature</strong></em><em> </em>{<em>NONE</em>} -- Initialization<em>

    make
            </em>-- Create a new scanner with
            -- standard input as input file.<em>
        </em><em><strong>do</strong></em><em>
            Precursor
            </em><em><strong>create</strong> buffer.make </em>(<em>256</em>)<em>
        </em><em><strong>end</strong></em><em>

</em><em><strong>feature</strong></em><em> </em>-- Initialization<em>

    reset
            </em>-- Reset scanner before scanning next input file.<em>
        </em><em><strong>do</strong></em><em>
            Precursor
            buffer.wipe_out
        </em><em><strong>end</strong></em><em>

</em><em><strong>feature</strong></em><em> </em>-- Access<em>

    buffer</em>:<em> STRING
            </em>-- Scanner's buffer<em>

</em><em><strong>invariant</strong></em><em>

    buffer_not_void</em>:<em> buffer </em>/=<em> Void

</em><em><strong>end</strong></em><em> </em></font></pre>
</blockquote>

<p>The generated scanner class, named <font color="#008080"><em><tt>MY_SCANNER</tt></em></font>,
uses a pattern-matching engine optimized in terms of memory
space. It redefines features <font color="#008080"><em><tt>make</tt></em></font>
and <font color="#008080"><em><tt>reset</tt></em></font>
inherited from <font color="#008080"><em><tt>YY_COMPRESSED_SCANNER_SKELETON</tt></em></font>
to take into account its internal buffer and preserve the
invariant. The last two examples are excerpts from descriptions
of a scanner optimized in terms of execution speed and an
interactive scanner:</p>

<blockquote>
    <pre><font color="#0000FF">%{</font>
<font color="#008080"><em><strong>class</strong></em><em> MY_FAST_SCANNER

</em><em><strong>inherit</strong></em><em>

    YY_FULL_SCANNER_SKELETON

</em><em><strong>create</strong></em><em>

    make</em></font><em>
</em><font color="#0000FF">%}</font>

<font color="#0000FF">%option</font> </font><font color="#800000">full</font>

<font color="#0000FF">%%</font>

<font color="#FF0000">...patterns...</font>   </font><font
color="#008080"><em>...actions</em>...</font>

<font color="#0000FF">%%</font><font
color="#008080"><em>

</em><em><strong>end</strong></em><em> </em></font></pre>
</blockquote>

<p>Please note in particular in the above example the <font
color="#0000FF"><tt>%option</tt></font><tt> </tt><font
color="#800000"><tt>full</tt></font> directing <em>gelex</em> to
generate non-compressed tables.</p>

<blockquote>
    <pre><font color="#0000FF">%{</font>
<font color="#008080"><em><strong>class</strong></em><em> MY_INTERACTIVE_SCANNER

</em><em><strong>inherit</strong></em><em>

    YY_INTERACTIVE_SCANNER_SKELETON

</em><em><strong>create</strong></em><em>

    make</em></font><em>
</em><font color="#0000FF">%}</font>

<font color="#0000FF">%%</font>

<font color="#FF0000">...patterns...</font>   <font color="#008080"><em>...actions</em>...</font>

<font color="#0000FF">%%</font><font
color="#008080"><em>

</em><em><strong>end</strong></em><em> </em></font></pre>
</blockquote>

<hr size="1">

<table border="0" width="100%">
    <tr>
        <td><address>
            <font size="2"><b>Copyright © 1998-2019</b></font><font
            size="1"><b>, </b></font><font size="2"><strong>Eric
            Bezault</strong></font><strong> </strong><font
            size="2"><br>
            <strong>mailto:</strong></font><a
            href="mailto:ericb@gobosoft.com"><font size="2">ericb@gobosoft.com</font></a><font
            size="2"><br>
            <strong>http:</strong></font><a
            href="http://www.gobosoft.com"><font size="2">//www.gobosoft.com</font></a><font
            size="2"><br>
            <strong>Last Updated:</strong> 25 September 2019</font><br>
            <!--webbot bot="PurpleText"
            preview="
$Date$
$Revision$"
            -->
        </address>
        </td>
        <td align="right" valign="top"><a
        href="http://www.gobosoft.com"><img
        src="image/home.gif" alt="Home" border="0" width="40"
        height="40"></a><a href="index.html"><img
        src="image/toc.gif" alt="Toc" border="0" width="40"
        height="40"></a><a href="description.html"><img
        src="image/previous.gif" alt="Previous" border="0"
        width="40" height="40"></a><a href="options.html"><img
        src="image/next.gif" alt="Next" border="0" width="40"
        height="40"></a></td>
    </tr>
</table>
</body>
</html>
