Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > 52a37fb77746ef557a2ec666070d732e > files > 16

bigloo-doc-3.2b-3.fc12.i686.rpm

<!-- 95% W3C COMPLIANT, 95% CSS FREE, RAW HTML -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title>BiglooA ``practical Scheme compiler''User manual for version 3.2bJune 2009</title>
 <style type="text/css">
  <!--
  pre { font-family: monospace }
  tt { font-family: monospace }
  code { font-family: monospace }
  p.flushright { text-align: right }
  p.flushleft { text-align: left }
  span.sc { font-variant: small-caps }
  span.sf { font-family: sans-serif }
  span.skribetitle { font-family: sans-serif; font-weight: bolder; font-size: x-large; }
  span.refscreen { }
  span.refprint { display: none; }
  -->
 </style>
</head>

<body class="chapter" bgcolor="#ffffff">
<table width="100%" class="skribetitle" cellspacing="0" cellpadding="0"><tbody>
<tr><td align="center" bgcolor="#8381de"><div class="skribetitle"><strong><big><big><big>11. Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009 -- Regular parsing</big></big></big></strong></div><center>
</center>
</td></tr></tbody></table>
<table cellpadding="3" cellspacing="0" width="100%" class="skribe-margins"><tr>
<td align="left" valign="top" class="skribe-left-margin" width="20%" bgcolor="#dedeff"><div class="skribe-left-margin">
<br/><center id='center27972'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc27962" align="center" colspan="1"><font color="#ffffff"><strong id='bold27960'
>main page</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc27969" align="center" colspan="1"><table width="100%" border="0" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc27965" align="left" valign="top" colspan="1"><strong id='bold27964'
>top:</strong></td><td id="tc27966" align="right" valign="top" colspan="1"><a href="bigloo.html#Bigloo-A-``practical-Scheme-compiler''-User-manual-for-version-3.2b-June-2009" class="inbound">Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009</a></td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</center>
<br/><br/><center id='center27982'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc27976" align="center" colspan="1"><font color="#ffffff"><strong id='bold27974'
>Regular parsing</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc27979" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc">
<tbody>
 <tr><td valign="top" align="left">11.1</td><td colspan="4" width="100%"><a href="bigloo-12.html#A-new-way-of-reading">A new way of reading</a></td></tr>
 <tr><td valign="top" align="left">11.2</td><td colspan="4" width="100%"><a href="bigloo-12.html#The-syntax-of-the-regular-grammar">The syntax of the regular grammar</a></td></tr>
 <tr><td valign="top" align="left">11.3</td><td colspan="4" width="100%"><a href="bigloo-12.html#The-semantics-actions">The semantics actions</a></td></tr>
 <tr><td valign="top" align="left">11.4</td><td colspan="4" width="100%"><a href="bigloo-12.html#Options-and-user-definitions">Options and user definitions</a></td></tr>
 <tr><td valign="top" align="left">11.5</td><td colspan="4" width="100%"><a href="bigloo-12.html#Examples-of-regular-grammar">Examples of regular grammar</a></td></tr>
 <tr><td></td><td valign="top" align="left">11.5.1</td><td colspan="3" width="100%"><a href="bigloo-12.html#Word-count">Word count</a></td></tr>
 <tr><td></td><td valign="top" align="left">11.5.2</td><td colspan="3" width="100%"><a href="bigloo-12.html#Roman-numbers">Roman numbers</a></td></tr>
</tbody>
</table>
</td></tr>
</tbody></table>
</center>
<br/><br/><center id='center27992'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc27986" align="center" colspan="1"><font color="#ffffff"><strong id='bold27984'
>Chapters</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc27989" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc">
<tbody>
 <tr><td valign="top" align="left"></td><td colspan="4" width="100%"><a href="bigloo-1.html#Acknowledgements">Acknowledgements</a></td></tr>
 <tr><td valign="top" align="left">1</td><td colspan="4" width="100%"><a href="bigloo-2.html#Table-of-contents">Table of contents</a></td></tr>
 <tr><td valign="top" align="left">2</td><td colspan="4" width="100%"><a href="bigloo-3.html#Overview-of-Bigloo">Overview of Bigloo</a></td></tr>
 <tr><td valign="top" align="left">3</td><td colspan="4" width="100%"><a href="bigloo-4.html#Modules">Modules</a></td></tr>
 <tr><td valign="top" align="left">4</td><td colspan="4" width="100%"><a href="bigloo-5.html#Core-Language">Core Language</a></td></tr>
 <tr><td valign="top" align="left">5</td><td colspan="4" width="100%"><a href="bigloo-6.html#DSSSL-support">DSSSL support</a></td></tr>
 <tr><td valign="top" align="left">6</td><td colspan="4" width="100%"><a href="bigloo-7.html#Standard-Library">Standard Library</a></td></tr>
 <tr><td valign="top" align="left">7</td><td colspan="4" width="100%"><a href="bigloo-8.html#Pattern-Matching">Pattern Matching</a></td></tr>
 <tr><td valign="top" align="left">8</td><td colspan="4" width="100%"><a href="bigloo-9.html#Fast-search">Fast search</a></td></tr>
 <tr><td valign="top" align="left">9</td><td colspan="4" width="100%"><a href="bigloo-10.html#Structures-and-Records">Structures and Records</a></td></tr>
 <tr><td valign="top" align="left">10</td><td colspan="4" width="100%"><a href="bigloo-11.html#Object-System">Object System</a></td></tr>
 <tr><td valign="top" align="left">11</td><td colspan="4" width="100%"><a href="bigloo-12.html#Regular-parsing">Regular parsing</a></td></tr>
 <tr><td valign="top" align="left">12</td><td colspan="4" width="100%"><a href="bigloo-13.html#Lalr(1)-parsing">Lalr(1) parsing</a></td></tr>
 <tr><td valign="top" align="left">13</td><td colspan="4" width="100%"><a href="bigloo-14.html#Posix-Regular-Expressions">Posix Regular Expressions</a></td></tr>
 <tr><td valign="top" align="left">14</td><td colspan="4" width="100%"><a href="bigloo-15.html#Command-Line-Parsing">Command Line Parsing</a></td></tr>
 <tr><td valign="top" align="left">15</td><td colspan="4" width="100%"><a href="bigloo-16.html#Cryptography">Cryptography</a></td></tr>
 <tr><td valign="top" align="left">16</td><td colspan="4" width="100%"><a href="bigloo-17.html#Errors-Assertions-and-Traces">Errors, Assertions, and Traces</a></td></tr>
 <tr><td valign="top" align="left">17</td><td colspan="4" width="100%"><a href="bigloo-18.html#Threads">Threads</a></td></tr>
 <tr><td valign="top" align="left">18</td><td colspan="4" width="100%"><a href="bigloo-19.html#Database-library">Database library</a></td></tr>
 <tr><td valign="top" align="left">19</td><td colspan="4" width="100%"><a href="bigloo-20.html#Multimedia-library">Multimedia library</a></td></tr>
 <tr><td valign="top" align="left">20</td><td colspan="4" width="100%"><a href="bigloo-21.html#Mail-library">Mail library</a></td></tr>
 <tr><td valign="top" align="left">21</td><td colspan="4" width="100%"><a href="bigloo-22.html#Eval-and-code-interpretation">Eval and code interpretation</a></td></tr>
 <tr><td valign="top" align="left">22</td><td colspan="4" width="100%"><a href="bigloo-23.html#Macro-expansion">Macro expansion</a></td></tr>
 <tr><td valign="top" align="left">23</td><td colspan="4" width="100%"><a href="bigloo-24.html#Parameters">Parameters</a></td></tr>
 <tr><td valign="top" align="left">24</td><td colspan="4" width="100%"><a href="bigloo-25.html#Explicit-typing">Explicit typing</a></td></tr>
 <tr><td valign="top" align="left">25</td><td colspan="4" width="100%"><a href="bigloo-26.html#The-C-interface">The C interface</a></td></tr>
 <tr><td valign="top" align="left">26</td><td colspan="4" width="100%"><a href="bigloo-27.html#The-Java-interface">The Java interface</a></td></tr>
 <tr><td valign="top" align="left">27</td><td colspan="4" width="100%"><a href="bigloo-28.html#Bigloo-Libraries">Bigloo Libraries</a></td></tr>
 <tr><td valign="top" align="left">28</td><td colspan="4" width="100%"><a href="bigloo-29.html#Extending-the-Runtime-System">Extending the Runtime System</a></td></tr>
 <tr><td valign="top" align="left">29</td><td colspan="4" width="100%"><a href="bigloo-30.html#SRFIs">SRFIs</a></td></tr>
 <tr><td valign="top" align="left">30</td><td colspan="4" width="100%"><a href="bigloo-31.html#Compiler-description">Compiler description</a></td></tr>
 <tr><td valign="top" align="left">31</td><td colspan="4" width="100%"><a href="bigloo-32.html#User-Extensions">User Extensions</a></td></tr>
 <tr><td valign="top" align="left">32</td><td colspan="4" width="100%"><a href="bigloo-33.html#Bigloo-Development-Environment">Bigloo Development Environment</a></td></tr>
 <tr><td valign="top" align="left">33</td><td colspan="4" width="100%"><a href="bigloo-34.html#Global-Index">Global Index</a></td></tr>
 <tr><td valign="top" align="left">34</td><td colspan="4" width="100%"><a href="bigloo-35.html#Library-Index">Library Index</a></td></tr>
 <tr><td valign="top" align="left"></td><td colspan="4" width="100%"><a href="bigloo-36.html#Bibliography">Bibliography</a></td></tr>
</tbody>
</table>
</td></tr>
</tbody></table>
</center>
</div></td>
<td align="left" valign="top" class="skribe-body"><div class="skribe-body">
<a name="Regular-Parsing" class="mark"></a><a name="g15677" class="mark"></a><a name="g15679" class="mark"></a>
Programming languages have poor reading libraries since the lexical
information that can be specified is directly tied to the structure of
the language. For example, in C it's hard to read a rational number
because there is no type rational.  Programs have been written to
circumvent this problem: Lex [Lesk75], for example, is one of them.
We choose to incorporate in Bigloo a set of new functions to assist in
such parsing. The syntax for regular grammar (also known as regular
analyser) of Bigloo 2.0 (the one described in this document) is not
compatible with former Bigloo versions.<br/><br/>
<!-- A new way of reading -->
<a name="A-new-way-of-reading"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">11.1 A new way of reading</font>
</h3></td></tr></table>
</div><div class="section">
<a name="A-New-Way-of-Reading" class="mark"></a><a name="g15682" class="mark"></a>
There is only one way in Bigloo to read text, <em id='emph15684'
>regular reading</em>,
which is done by the new form:<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15688" align="left" colspan="1"><strong id='bold15686'
>read/rp</strong><em id='it15687'
> regular-grammar input-port</em></td><td id="tc15689" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>

The first argument is a regular grammar (also known as regular
analyser) and the second a Scheme port.  This way of reading is almost
the same as the Lex's one. The reader tries to match the longest
input, from the stream pointed to by <code id='code15693'
><em id='it15692'
>input-port</em></code>, with one of
several regular expressions contained in <code id='code15695'
><em id='it15694'
>regular-grammar</em></code>. If
many rules match, the reader takes the first one defined in the
grammar. When the regular rule has been found the corresponding Scheme
expression is evaluated.<br/><br/><em id='emph15697'
>remark: </em> The traditional <code id='code15698'
>read</code> Scheme function is implemented as:
<center id='center15702'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15700'
>(<font color="#6959cf"><strong id='bold27993'
>define-inline</strong></font> (<font color="#6959cf"><strong id='bold27995'
>read</strong></font> port)
   (read/rp scheme-grammar port))
</pre>
</td></tr>
</tbody></table></center>
</td></tr>
</tbody></table><br/>
</div><br>
<!-- The syntax of the regular grammar -->
<a name="The-syntax-of-the-regular-grammar"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">11.2 The syntax of the regular grammar</font>
</h3></td></tr></table>
</div><div class="section">
<a name="The-Syntax-of-The-Regular-Grammar" class="mark"></a><a name="g15705" class="mark"></a>
A regular grammar is built by the means of the form <code id='code15707'
>regular-grammar</code>:<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15710" class="mark"></a><a name="regular-grammar" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15714" align="left" colspan="1"><strong id='bold15712'
>regular-grammar</strong><em id='it15713'
> (binding ...) rule ...</em></td><td id="tc15715" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>

The <code id='code15719'
><em id='it15718'
>binding</em></code> and <code id='code15721'
><em id='it15720'
>rule</em></code> are defined by 
the following grammar:<br/><br/><center id='center15747'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog15745'
>&lt;binding&gt;  ==&gt; (&lt;variable&gt; &lt;re&gt;)
             | &lt;option&gt;
&lt;option&gt;   ==&gt; &lt;variable&gt;
&lt;rule&gt;     ==&gt; &lt;define&gt;
             | (&lt;cre&gt; &lt;s-expression&gt; &lt;s-expression&gt; ...)
             | (<code id='code15723'
>else</code> &lt;s-expression&gt; &lt;s-expression&gt; ...)
&lt;define&gt;   ==&gt; (define &lt;s-expression&gt;)
&lt;cre&gt;      ==&gt; &lt;re&gt;
             | (<code id='code15724'
>context</code> &lt;symbol&gt; &lt;re&gt;)
             | (<code id='code15725'
>when</code> &lt;s-expr&gt; &lt;re&gt;)
             | (<code id='code15726'
>bol</code> &lt;re&gt;)
             | (<code id='code15727'
>eol</code> &lt;re&gt;)
             | (<code id='code15728'
>bof</code> &lt;re&gt;)
             | (<code id='code15729'
>eof</code> &lt;re&gt;)
&lt;re&gt;       ==&gt; &lt;variable&gt;
             | &lt;char&gt;
             | &lt;string&gt;
             | (<code id='code15730'
>:</code> &lt;re&gt; ...)
             | (<code id='code15731'
>or</code> &lt;re&gt; ...)
             | (<code id='code15732'
>*</code> &lt;re&gt;)
             | (<code id='code15733'
>+</code> &lt;re&gt;)
             | (<code id='code15734'
>?</code> &lt;re&gt;)
             | (<code id='code15735'
>=</code> &lt;integer&gt; &lt;re&gt;)
             | (<code id='code15736'
>&gt;=</code> &lt;integer&gt; &lt;re&gt;)
             | (<code id='code15737'
>**</code> &lt;integer&gt; &lt;integer&gt; &lt;re&gt;)
             | (<code id='code15738'
>...</code> &lt;integer&gt; &lt;re&gt;)
             | (<code id='code15739'
>uncase</code> &lt;re&gt;)
             | (<code id='code15740'
>in</code> &lt;cset&gt; ...)
             | (<code id='code15741'
>out</code> &lt;cset&gt; ...)
             | (<code id='code15742'
>and</code> &lt;cset&gt; &lt;cset&gt;)
             | (<code id='code15743'
>but</code> &lt;cset&gt; &lt;cset&gt;)
             | (<code id='code15744'
>posix</code> &lt;string&gt;)
&lt;variable&gt; ==&gt; &lt;symbol&gt;
&lt;cset&gt;     ==&gt; &lt;string&gt;
             | &lt;char&gt;
             | (&lt;string&gt;)
             | (&lt;char&gt; &lt;char&gt;)
</pre>
</td></tr>
</tbody></table></center>

Here is a description of each construction.<br/><br/><dl class="description" id='description15977'
> <dt><code id='code15749'
>(context &lt;symbol&gt; &lt;re&gt;)</code></dt> <dt><code id='code15750'
>
</code></dt><dd>This allows us to <em id='emph15751'
>protect</em> an expression. A <em id='emph15752'
>protected</em>
expression matches (or accepts) a word only if the grammar has been set to
the corresponding context. See <a href="bigloo-12.html#The-Semantics-Actions" class="inbound">The Semantics Actions</a>, for more details.<br/><br/></dd>
 <dt><code id='code15755'
>(when &lt;s-expr&gt; &lt;re&gt;)</code></dt> <dt><code id='code15756'
>
</code></dt><dd>This allows us to <em id='emph15757'
>protect</em> an expression. A <em id='emph15758'
>protected</em>
expression matches (or accepts) a word only if the evaluation of 
<code id='code15759'
>&lt;s-expr&gt;</code> is <code id='code15760'
>#t</code>. For instance,<br/><br/><center id='center15774'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15772'
>(<font color="#6959cf"><strong id='bold27997'
>define</strong></font> <font color="#6959cf"><strong id='bold27999'
>*g*</strong></font>
   (<strong id='bold28001'
>let</strong> ((armed #f))
      (<strong id='bold28002'
>regular-grammar</strong> ()
	 ((when (not armed) (: <font color="red">&quot;#!&quot;</font> (+ (or #\/ alpha))))
	  (<strong id='bold28004'
>set!</strong> armed #t)
	  (print <font color="red">&quot;start [&quot;</font> (the-string) <font color="red">&quot;]&quot;</font>)
	  (ignore))
	 ((+ (in #\Space #\Tab))
	  (ignore))
	 (else
	  (the-failure)))))
   
(<font color="#6959cf"><strong id='bold28007'
>define</strong></font> (<font color="#6959cf"><strong id='bold28009'
>main</strong></font> argv)
   (<strong id='bold28011'
>let</strong> ((port (open-input-string <font color="red">&quot;#!/bin/sh #!/bin/zsh&quot;</font>)))
      (print (read/rp *g* port))))
</pre>
</td></tr>
</tbody></table></center>

</dd>
 <dt><code id='code15776'
>(bol &lt;re&gt;)</code></dt> <dt><code id='code15777'
>
</code></dt><dd>Matches <code id='code15778'
>&lt;re&gt;</code> at the beginning of line.<br/><br/></dd>
 <dt><code id='code15781'
>(eol &lt;re&gt;)</code></dt> <dt><code id='code15782'
>
</code></dt><dd>Matches <code id='code15783'
>&lt;re&gt;</code> at the end of line.<br/><br/></dd>
 <dt><code id='code15786'
>(bof &lt;re&gt;)</code></dt> <dt><code id='code15787'
>
</code></dt><dd>Matches <code id='code15788'
>&lt;re&gt;</code> at the beginning of file.<br/><br/></dd>
 <dt><code id='code15791'
>(eof &lt;re&gt;)</code></dt> <dt><code id='code15792'
>
</code></dt><dd>Matches <code id='code15793'
>&lt;re&gt;</code> at the end of file.<br/><br/></dd>
 <dt><code id='code15796'
>&lt;variable&gt;</code></dt> <dt><code id='code15797'
>
</code></dt><dd>This is the name of a variable bound by a &lt;binding&gt; construction. In addition 
to user defined variables, some already exist. These are:<br/><br/><center id='center15801'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog15799'
>all    &lt;=&gt; (out #\Newline)
lower  &lt;=&gt; (in (&quot;az&quot;))
upper  &lt;=&gt; (in (&quot;AZ&quot;))
alpha  &lt;=&gt; (or lower upper)
digit  &lt;=&gt; (in (&quot;09&quot;))
xdigit &lt;=&gt; (uncase (in (&quot;af09&quot;)))
alnum  &lt;=&gt; (uncase (in (&quot;az09&quot;)))
punct  &lt;=&gt; (in &quot;.,;!?&quot;)
blank  &lt;=&gt; (in #&quot; \t\n&quot;)
space  &lt;=&gt; #\Space
</pre>
</td></tr>
</tbody></table></center>
<br/><br/>It is a error to reference a variable that it is not bound by a &lt;binding&gt;.
Defining a variable that already exists is acceptable and causes the former
variable definition to be erased. Here is an example of a grammar that binds
two variables, one called <samp id='samp15803'
>ident</samp> and one called <samp id='samp15804'
>number</samp>. These
two variables are used within the grammar to match identifiers and numbers.<br/><br/><center id='center15809'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15807'
>(<strong id='bold28013'
>regular-grammar</strong> ((ident  (: alpha (* alnum)))
                  (number (+ digit)))
   (ident  (cons 'ident (the-string)))
   (number (cons 'number (the-string)))
   (else   (cons 'else (the-failure))))
</pre>
</td></tr>
</tbody></table></center>

</dd>
 <dt><code id='code15811'
>&lt;char&gt;</code></dt> <dt><code id='code15812'
>
</code></dt><dd>The regular language described by one unique character. Here is an example of
a grammar that accepts either the character <code id='code15813'
>#\a</code> or the character
<code id='code15814'
>#\b</code>:<br/><br/><center id='center15819'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15817'
>(<strong id='bold28014'
>regular-grammar</strong> ()
   (#\a (cons 'a (the-string)))
   (#\b (cons 'b (the-string)))
   (else (cons 'else (the-failure))))
</pre>
</td></tr>
</tbody></table></center>

</dd>
 <dt><code id='code15821'
>&lt;string&gt;</code></dt> <dt><code id='code15822'
>
</code></dt><dd>This simple form of regular expression denotes the language represented
by the string. For instance the regular expression <code id='code15823'
>&quot;Bigloo&quot;</code> matches
only the string composed of <code id='code15824'
>#\B #\i #\g #\l #\o #\o</code>. The regular 
expression <code id='code15825'
>&quot;.*[&quot;</code> matches the string <code id='code15826'
>#\. #\* #\[</code>.<br/><br/></dd>
 <dt><code id='code15829'
>(: &lt;re&gt; ...)</code></dt> <dt><code id='code15830'
>
</code></dt><dd>This form constructs sequence of regular expression. That is a form
<code id='code15831'
>&lt;re1&gt; &lt;re2&gt; ... &lt;ren&gt;</code> matches the language construction by
concatenation of the language described by <code id='code15832'
>&lt;re1&gt;</code>, <code id='code15833'
>&lt;re2&gt;</code>, 
<code id='code15834'
>&lt;ren&gt;</code>. Thus, <code id='code15835'
>(: &quot;x&quot; all &quot;y&quot;)</code> matches all words of three
letters, started by character the <code id='code15836'
>#\x</code> and ended with the character
<code id='code15837'
>#\y</code>.<br/><br/></dd>
 <dt><code id='code15840'
>(or &lt;re&gt; ...)</code></dt> <dt><code id='code15841'
>
</code></dt><dd>This construction denotes conditions. The language described by
<code id='code15842'
>(or re1 re2)</code> accepts words accepted by either <code id='code15843'
>re1</code> or <code id='code15844'
>re2</code>.
 
</dd>
 <dt><code id='code15846'
>(* &lt;re&gt;)</code></dt> <dt><code id='code15847'
>
</code></dt><dd>This is the Kleene operator, the language described by <code id='code15848'
>(* &lt;re&gt;)</code> is
the language containing, 0 or more occurrences of <code id='code15849'
>&lt;re&gt;</code>. Thus, 
the language described by <code id='code15850'
>(* &quot;abc&quot;)</code> accepts the empty word and
any word composed by a repetition of the <code id='code15851'
>abc</code> (<code id='code15852'
>abc</code>,
<code id='code15853'
>abcabc</code>, <code id='code15854'
>abcabcabc</code>, ...).<br/><br/></dd>
 <dt><code id='code15857'
>(+ &lt;re&gt;)</code></dt> <dt><code id='code15858'
>
</code></dt><dd>This expression described non empty repetitions. The form <code id='code15859'
>(+ re)</code> is
equivalent to <code id='code15860'
>(: re (* re))</code>. Thus, <code id='code15861'
>(+ &quot;abc&quot;)</code> matches the
words <code id='code15862'
>abc</code>, <code id='code15863'
>abcabc</code>, etc.<br/><br/></dd>
 <dt><code id='code15866'
>(? &lt;re&gt;)</code></dt> <dt><code id='code15867'
>
</code></dt><dd>This expression described one or zero occurrence. Thus, 
<code id='code15868'
>(? &quot;abc&quot;)</code> matches the empty word or the words <code id='code15869'
>abc</code>.<br/><br/></dd>
 <dt><code id='code15872'
>(= &lt;integer&gt; &lt;re&gt;)</code></dt> <dt><code id='code15873'
>
</code></dt><dd>This expression described a fix number of repetitions. The form
<code id='code15874'
>(= num re)</code> is equivalent to <code id='code15875'
>(: re re ... re)</code>. Thus,
the expression <code id='code15876'
>(= 3 &quot;abc&quot;)</code> matches the only word <code id='code15877'
>abcabcabc</code>.
In order to avoid code size explosion when compiling, <code id='code15878'
>&lt;integer&gt;</code> 
must be smaller than an arbitrary constant. In the current version that 
value is <code id='code15879'
>81</code>.<br/><br/></dd>
 <dt><code id='code15882'
>(&gt;= &lt;integer&gt; &lt;re&gt;)</code></dt> <dt><code id='code15883'
>
</code></dt><dd>The language described by the expression <code id='code15884'
>(&gt;= int re)</code> accepts word
that are, at least, <code id='code15885'
>int</code> repetitions of <code id='code15886'
>re</code>. For instance,
<code id='code15887'
>(&gt;= 10 #\a)</code>, accepts words compound of, at least, 10 times the
character <code id='code15888'
>#\a</code>. In order to avoid code size explosion when compiling, 
<code id='code15889'
>&lt;integer&gt;</code> must be smaller than an arbitrary constant. In the current 
version that value is <code id='code15890'
>81</code>.
 
</dd>
 <dt><code id='code15892'
>(** &lt;integer&gt; &lt;integer&gt; &lt;re&gt;)</code></dt> <dt><code id='code15893'
>
</code></dt><dd>The language described by the expression <code id='code15894'
>(** min max re)</code> accepts
word that are repetitions of <code id='code15895'
>re</code>; the number of repetition is in
the range <code id='code15896'
>min</code>, <code id='code15897'
>max</code>. For instance, <code id='code15898'
>(** 10 20 #\a)</code>.
In order to avoid code size explosion when compiling, 
<code id='code15899'
>&lt;integer&gt;</code> must be smaller than an arbitrary constant. In the current 
version that value is <code id='code15900'
>81</code>.<br/><br/></dd>
 <dt><code id='code15903'
>(... &lt;integer&gt; &lt;re&gt;)</code></dt> <dt><code id='code15904'
>
</code></dt><dd>The subexpression <code id='code15905'
>&lt;re&gt;</code> has to be a sequence
of characters. Sequences are build by the operator <code id='code15906'
>:</code> or by string
literals. The language described by <code id='code15907'
>(... int re)</code>, denotes, the
first letter of <code id='code15908'
>re</code>, or the two first letters of <code id='code15909'
>re</code>, or the
three first letters of <code id='code15910'
>re</code> or the <code id='code15911'
>int</code> first letters of
<code id='code15912'
>re</code>. Thus, <code id='code15913'
>(... 3 &quot;begin&quot;)</code> is equivalent to 
<code id='code15914'
>(or &quot;b&quot; &quot;be&quot; &quot;beg&quot;)</code>.<br/><br/></dd>
 <dt><code id='code15917'
>(uncase &lt;re&gt;)</code></dt> <dt><code id='code15918'
>
</code></dt><dd>The subexpression <code id='code15919'
>&lt;re&gt;</code> has to be a sequence
construction. The language described by <code id='code15920'
>(uncase re)</code> is the
same as <code id='code15921'
>re</code> where letters may be upper case or lower case. For
instance, <code id='code15922'
>(uncase &quot;begin&quot;)</code>, accepts the words <code id='code15923'
>&quot;begin&quot;</code>,
<code id='code15924'
>&quot;beGin&quot;</code>, <code id='code15925'
>&quot;BEGIN&quot;</code>, <code id='code15926'
>&quot;BegiN&quot;</code>, etc.<br/><br/></dd>
 <dt><code id='code15929'
>(in &lt;cset&gt; ...)</code></dt> <dt><code id='code15930'
>
</code></dt><dd>Denotes union of characters. Characters may be described individually
such as in <code id='code15931'
>(in #\a #\b #\c #\d)</code>. They may be described by
strings. The expression <code id='code15932'
>(in &quot;abcd&quot;)</code> is equivalent to <code id='code15933'
>(in
#\a #\b #\c #\d)</code>.  Characters may also be described using a range
notation that is a list of two characters. The expression <code id='code15934'
>(in (#\a
#\d))</code> is equivalent to <code id='code15935'
>(in #\a #\b #\c #\d)</code>. The Ranges may be
expresses using lists of string. The expression <code id='code15936'
>(in (&quot;ad&quot;))</code>
is equivalent to <code id='code15937'
>(in #\a #\b #\c #\d)</code>.<br/><br/></dd>
 <dt><code id='code15940'
>(out &lt;cset&gt; ...)</code></dt> <dt><code id='code15941'
>
</code></dt><dd>The language described by <code id='code15942'
>(out cset ...)</code> is opposite to
the one described by <code id='code15943'
>(in cset ...)</code>. For instance, 
<code id='code15944'
>(out (&quot;azAZ&quot;) (#\0 #\9))</code> accepts all words of one character
that are neither letters nor digits. One should not that if the character
numbered zero may be used inside regular grammar, the <code id='code15945'
>out</code> 
construction never matches it. Thus to write a rule that, for instances,
matches every character but <code id='code15946'
>#\Newline</code> including the character
zero, one should write: <br/><br/><center id='center15950'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15948'
>(or (out #\Newline) #a000)
</pre>
</td></tr>
</tbody></table></center>

</dd>
 <dt><code id='code15952'
>(and &lt;cset&gt; &lt;cset&gt;)</code></dt> <dt><code id='code15953'
>
</code></dt><dd>The language described by <code id='code15954'
>(and cset1 cset2)</code> accepts words 
made of characters that are in both <code id='code15955'
>cset1</code> and <code id='code15956'
>cset2</code>. <br/><br/></dd>
 <dt><code id='code15959'
>(but &lt;cset&gt; &lt;cset&gt;)</code></dt> <dt><code id='code15960'
>
</code></dt><dd>The language described by <code id='code15961'
>(but cset1 cset2)</code> accepts words 
made of characters of <code id='code15962'
>cset1</code> that are not member of <code id='code15963'
>cset2</code>. 
 
</dd>
 <dt><code id='code15965'
>(posix &lt;string&gt;)</code></dt> <dt><code id='code15966'
>
</code></dt><dd>The expression <code id='code15967'
>(posix string)</code> allows one to use Posix string
notation for regular expressions. So, for example, the following two
expressions are equivalent:<br/><br/><center id='center15975'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15973'
>(posix &quot;[az]+|x*|y{3,5}&quot;)<br/><br/>(or (+ (in (<font color="red">&quot;az&quot;</font>))) (* <font color="red">&quot;x&quot;</font>) (** 3 5 <font color="red">&quot;y&quot;</font>))
</pre>
</td></tr>
</tbody></table></center>

</dd>
</dl></td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15981" class="mark"></a><a name="string-case" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15985" align="left" colspan="1"><strong id='bold15983'
>string-case</strong><em id='it15984'
> string rule ...</em></td><td id="tc15986" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
This form dispatches on strings. it opens an input on <code id='code15989'
>string</code>
a read into it according to the regular grammar defined by the
<code id='code15990'
>binding</code> and <code id='code15991'
>rule</code>. Example:<br/><br/><center id='center15998'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15996'
>(<font color="#6959cf"><strong id='bold28018'
>define</strong></font> (<font color="#6959cf"><strong id='bold28020'
>suffix</strong></font> string)
   (string-case string
      ((: (* all) <font color="red">&quot;.&quot;</font>)
       (ignore))
      ((+ (out #\.))
       (the-string))
      (else
       <font color="red">&quot;&quot;</font>)))
</pre>
</td></tr>
</tbody></table></center>
</td></tr>
</tbody></table><br/>   
</div><br>
<!-- The semantics actions -->
<a name="The-semantics-actions"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">11.3 The semantics actions</font>
</h3></td></tr></table>
</div><div class="section">
<a name="The-Semantics-Actions" class="mark"></a><a name="g16001" class="mark"></a>
The semantics actions are regular Scheme expressions. These expressions
appear in an environment where some ``extra procedures'' are defined.
These procedures are:<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16005" class="mark"></a><a name="the-port" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16009" align="left" colspan="1"><strong id='bold16007'
>the-port</strong><em id='it16008'
></em></td><td id="tc16010" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Returns the input port currently in used.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16016" class="mark"></a><a name="the-length" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16020" align="left" colspan="1"><strong id='bold16018'
>the-length</strong><em id='it16019'
></em></td><td id="tc16021" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Get the length of the biggest matching string.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16027" class="mark"></a><a name="the-string" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16031" align="left" colspan="1"><strong id='bold16029'
>the-string</strong><em id='it16030'
></em></td><td id="tc16032" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Get a copy of the last matching string. The function <code id='code16035'
>the-string</code>
returns a fresh copy of the matching each time it is called. In consequence,<br/><br/><center id='center16040'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog16038'
>(<strong id='bold28024'
>let</strong> ((l1 (the-string)) (l2 (the-string)))
   (eq? l1 l2))
   =&gt; #f
</pre>
</td></tr>
</tbody></table></center>
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16044" class="mark"></a><a name="the-substring" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16048" align="left" colspan="1"><strong id='bold16046'
>the-substring</strong><em id='it16047'
> start length</em></td><td id="tc16049" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Get a copy of a substring of the last matching string. If the <code id='code16053'
><em id='it16052'
>length</em></code>
is negative, it is subtracted to the whole match length.
Here is an example of a rule extracting a part of a match:<br/><br/><center id='center16058'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog16056'
>(<strong id='bold28025'
>regular-grammar</strong> ()
   ((: #\&quot; (* (out #\&quot;)) #\&quot;)
    (the-substring 1 (-fx (the-length) 1))))
</pre>
</td></tr>
</tbody></table></center>

Which can also be written:<br/><br/><center id='center16063'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog16061'
>(<strong id='bold28026'
>regular-grammar</strong> ()
   ((: #\&quot; (* (out #\&quot;)) #\&quot;)
    (the-substring 1 -1)))
</pre>
</td></tr>
</tbody></table></center>

</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16067" class="mark"></a><a name="the-character" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16071" align="left" colspan="1"><strong id='bold16069'
>the-character</strong><em id='it16070'
></em></td><td id="tc16072" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
<a name="g16076" class="mark"></a><a name="the-byte" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16080" align="left" colspan="1"><strong id='bold16078'
>the-byte</strong><em id='it16079'
></em></td><td id="tc16081" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Returns the first character of a match (respectively, the first byte).
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16087" class="mark"></a><a name="the-byte-ref" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16091" align="left" colspan="1"><strong id='bold16089'
>the-byte-ref</strong><em id='it16090'
> n</em></td><td id="tc16092" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Returns the <code id='code16096'
><em id='it16095'
>n</em></code>-th bytes of the matching string.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16100" class="mark"></a><a name="the-symbol" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16104" align="left" colspan="1"><strong id='bold16102'
>the-symbol</strong><em id='it16103'
></em></td><td id="tc16105" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
<a name="g16109" class="mark"></a><a name="the-downcase-symbol" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16113" align="left" colspan="1"><strong id='bold16111'
>the-downcase-symbol</strong><em id='it16112'
></em></td><td id="tc16114" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
<a name="g16118" class="mark"></a><a name="the-upcase-symbol" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16122" align="left" colspan="1"><strong id='bold16120'
>the-upcase-symbol</strong><em id='it16121'
></em></td><td id="tc16123" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
<a name="g16127" class="mark"></a><a name="the-subsymbol" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16131" align="left" colspan="1"><strong id='bold16129'
>the-subsymbol</strong><em id='it16130'
> start length</em></td><td id="tc16132" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Convert the last matching string into a symbol. The function 
<code id='code16135'
>the-subsymbol</code> obeys the same rules as <code id='code16136'
>the-substring</code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16140" class="mark"></a><a name="the-keyword" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16144" align="left" colspan="1"><strong id='bold16142'
>the-keyword</strong><em id='it16143'
></em></td><td id="tc16145" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
<a name="g16149" class="mark"></a><a name="the-downcase-keyword" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16153" align="left" colspan="1"><strong id='bold16151'
>the-downcase-keyword</strong><em id='it16152'
></em></td><td id="tc16154" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
<a name="g16158" class="mark"></a><a name="the-upcase-keyword" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16162" align="left" colspan="1"><strong id='bold16160'
>the-upcase-keyword</strong><em id='it16161'
></em></td><td id="tc16163" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Convert the last matching string into a keyword.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16169" class="mark"></a><a name="the-fixnum" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16173" align="left" colspan="1"><strong id='bold16171'
>the-fixnum</strong><em id='it16172'
></em></td><td id="tc16174" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
The conversion of the last matching string to fixnum.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16180" class="mark"></a><a name="the-flonum" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16184" align="left" colspan="1"><strong id='bold16182'
>the-flonum</strong><em id='it16183'
></em></td><td id="tc16185" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
The conversion of the last matching string to flonum.
</td></tr>
</tbody></table><br/> 
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16191" class="mark"></a><a name="the-failure" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16195" align="left" colspan="1"><strong id='bold16193'
>the-failure</strong><em id='it16194'
></em></td><td id="tc16196" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Returns the first char that the grammar can't match or the end of file
object.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16202" class="mark"></a><a name="ignore" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16206" align="left" colspan="1"><strong id='bold16204'
>ignore</strong><em id='it16205'
></em></td><td id="tc16207" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Ignore the parsing, keep reading. It's better to use <code id='code16210'
>(ignore)</code>
rather than an expression like <code id='code16215'
>(read/rp <code id='code16212'
><em id='it16211'
>grammar</em></code> <code id='code16214'
><em id='it16213'
>port</em></code>)</code>
in semantics actions since the <code id='code16216'
>(ignore)</code> call will be done in a
tail recursive way. For instance,
 
<center id='center16229'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog16227'
>(<strong id='bold28027'
>let</strong> ((g (<strong id='bold28028'
>regular-grammar</strong> ()
            (<font color="red">&quot;)&quot;</font> 
             '())
            (<font color="red">&quot;(&quot;</font> 
             (<strong id='bold28031'
>let*</strong> ((car (ignore))
                    (cdr (ignore)))
                (cons car cdr)))
            ((+ (out <font color="red">&quot;()&quot;</font>))
             (the-string))))
      (p (open-input-string <font color="red">&quot;(foo(bar(gee)))&quot;</font>)))
   (read/rp g p))
   =&gt; (<font color="red">&quot;foo&quot;</font> (<font color="red">&quot;bar&quot;</font> (<font color="red">&quot;gee&quot;</font>)))
</pre>
</td></tr>
</tbody></table></center>
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16233" class="mark"></a><a name="rgc-context" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16237" align="left" colspan="1"><strong id='bold16235'
>rgc-context</strong><em id='it16236'
> [context]</em></td><td id="tc16238" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
If no <code id='code16242'
><em id='it16241'
>context</em></code> is provide, this procedure reset the reader context
state. That is the reader is in no context. With one argument, <code id='code16243'
>context</code>
set the reader in the context <code id='code16245'
><em id='it16244'
>context</em></code>. For instance,<br/><br/><center id='center16254'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog16252'
>(<strong id='bold28037'
>let</strong> ((g (<strong id='bold28038'
>regular-grammar</strong> ()
            ((context foo <font color="red">&quot;foo&quot;</font>) (print 'foo-bis))
            (<font color="red">&quot;foo&quot;</font> (rgc-context 'foo) (print 'foo) (ignore))
            (else 'done)))
      (p (open-input-string <font color="red">&quot;foofoo&quot;</font>)))
   (read/rp g p))
   -| foo
      foo-bis
</pre>
</td></tr>
</tbody></table></center>

Note that RGC context are preserved across different uses of <code id='code16255'
>read/rp</code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g16259" class="mark"></a><a name="the-context" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc16263" align="left" colspan="1"><strong id='bold16261'
>the-context</strong><em id='it16262'
></em></td><td id="tc16264" align="right" colspan="1">bigloo rgc procedure</td></tr>
</tbody></table>
Returns the value of the current Rgc context.
</td></tr>
</tbody></table><br/>
<br/><br/></div><br>
<!-- Options and user definitions -->
<a name="Options-and-user-definitions"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">11.4 Options and user definitions</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Options-and-user-definitions" class="mark"></a>
Options act as parameters that are transmitted to the parser on the call
to <code id='code16270'
>read/rp</code>. Local defines are user functions inserted in the produced
parser, at the same level as the pre-defined <code id='code16271'
>ignore</code> function.<br/><br/>Here is an example of grammar using both<br/><br/><center id='center16281'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog16279'
>(<font color="#6959cf"><strong id='bold28042'
>define</strong></font> <font color="#6959cf"><strong id='bold28044'
>gram</strong></font>
   (<strong id='bold28046'
>regular-grammar</strong> (x y)
      
      (<font color="#6959cf"><strong id='bold28047'
>define</strong></font> (<font color="#6959cf"><strong id='bold28049'
>foo</strong></font> s)
	 (cons* 'foo x s (ignore)))
      (<font color="#6959cf"><strong id='bold28051'
>define</strong></font> (<font color="#6959cf"><strong id='bold28053'
>bar</strong></font> s)
	 (cons* 'bar y s (ignore)))<br/><br/>      ((+ #\a) (foo (the-string)))
      ((+ #\b) (bar (the-string)))
      (else '())))
</pre>
</td></tr>
</tbody></table></center>

This grammar uses two options <code id='code16283'
><em id='it16282'
>x</em></code> and <code id='code16285'
><em id='it16284'
>y</em></code>. Hence when invokes it
takes two additional values such as:<br/><br/><center id='center16291'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog16289'
>(with-input-from-string <font color="red">&quot;aabb&quot;</font>
   (<strong id='bold28056'
>lambda</strong> ()
      (read/rp gram (current-input-port) 'option-x 'option-y)))
   =&gt; (foo option-x aa bar option-y bb)
</pre>
</td></tr>
</tbody></table></center>
<br/><br/></div><br>
<!-- Examples of regular grammar -->
<a name="Examples-of-regular-grammar"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">11.5 Examples of regular grammar</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Examples-of-Regular-Grammar" class="mark"></a><a name="g16293" class="mark"></a>The reader who wants to find a real example should read the code of
Bigloo's reader. But here are small examples<br/><br/><!-- Word count -->
<a name="Word-count"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">11.5.1 Word count</font>
</h3></td></tr></table>
</div><div class="subsection">
The first example presents a grammar that simulates the Unix program <code id='code16296'
>wc</code>.
<center id='center16306'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog16304'
>(<strong id='bold28057'
>let</strong> ((*char* 0)
      (*word* 0)
      (*line* 0))
   (<strong id='bold28058'
>regular-grammar</strong> ()
      ((+ #\Newline)
       (<strong id='bold28059'
>set!</strong> *char* (+ *char* (the-length)))
       (<strong id='bold28060'
>set!</strong> *line* (+ *line* (the-length)))
       (ignore))
      ((+ (in #\space #\tab))
       (<strong id='bold28061'
>set!</strong> *char* (+ *char* (the-length)))
       (ignore))
      ((+ (out #\newline #\space #\tab))
       (<strong id='bold28062'
>set!</strong> *char* (+ *char* (the-length)))
       (<strong id='bold28063'
>set!</strong> *word* (+ 1 *word*))
       (ignore))))
</pre>
</td></tr>
</tbody></table></center>

</div>
<!-- Roman numbers -->
<a name="Roman-numbers"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">11.5.2 Roman numbers</font>
</h3></td></tr></table>
</div><div class="subsection">
The second example presents a grammar that reads Arabic and Roman number.
<center id='center16328'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog16326'
>(<strong id='bold28064'
>let</strong> ((par-open 0))
   (<strong id='bold28065'
>regular-grammar</strong> ((arabic (in (<font color="red">&quot;09&quot;</font>)))
                     (roman  (uncase (in <font color="red">&quot;ivxlcdm&quot;</font>))))
      ((+ (in <font color="red">#&quot; \t\n&quot;</font>))
       (ignore))
      ((+ arabic)
       (string-&gt;integer (the-string)))
      ((+ roman)
       (roman-&gt;arabic (the-string)))
      (#\(
       (<strong id='bold28069'
>let</strong> ((open-key par-open))
          (<strong id='bold28070'
>set!</strong> par-open (+ 1 par-open))
          (context 'pair)
          (<strong id='bold28071'
>let</strong> loop-pair ((walk (ignore))) 
             (<strong id='bold28072'
>cond</strong>
                ((= open-key par-open)
                 '())
                (else
                 (cons walk (loop-pair (ignore))))))))
      (#\)
       (<strong id='bold28073'
>set!</strong> par-open (- par-open 1))
       (<strong id='bold28074'
>if</strong> (&lt; par-open 0)
           (<strong id='bold28075'
>begin</strong>
              (<strong id='bold28076'
>set!</strong> par-open 0)
              (ignore))
           #f))
      ((in <font color="red">&quot;+-*\\&quot;</font>)
       (string-&gt;symbol (the-string)))
      (else
       (<strong id='bold28078'
>let</strong> ((char (the-failure)))
          (<strong id='bold28079'
>if</strong> (eof-object? char)
              char
              (<font color="red"><strong id='bold28080'
>error</strong></font> <font color="red">&quot;grammar-roman&quot;</font> <font color="red">&quot;Illegal char&quot;</font> char))))))
</pre>
</td></tr>
</tbody></table></center>


</div>
</div><br>
</div></td>
</tr></table><div class="skribe-ending">
<hr> 
<p class="ending" id='paragraph28089'
><font size="-1">
This <span class="sc">Html</span> page has been produced by 
<a href="http://www.inria.fr/mimosa/fp/Skribe" class="http">Skribe</a>.
<br/>
Last update <em id='it28087'
>Tue Jun  2 11:43:27 2009</em>.</font></p></div>
</body>
</html>