Sophie

Sophie

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

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>14. Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009 -- Command Line 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='center28464'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc28454" align="center" colspan="1"><font color="#ffffff"><strong id='bold28452'
>main page</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc28461" align="center" colspan="1"><table width="100%" border="0" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc28457" align="left" valign="top" colspan="1"><strong id='bold28456'
>top:</strong></td><td id="tc28458" 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='center28474'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc28468" align="center" colspan="1"><font color="#ffffff"><strong id='bold28466'
>Command Line Parsing</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc28471" align="center" colspan="1"></td></tr>
</tbody></table>
</center>
<br/><br/><center id='center28484'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc28478" align="center" colspan="1"><font color="#ffffff"><strong id='bold28476'
>Chapters</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc28481" 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="Command-Line-Parsing" class="mark"></a><a name="g17464" class="mark"></a><a name="g17466" class="mark"></a>
Bigloo supports command line argument parsing. That is, when an
application is spawn from an Unix shell, the <code id='code17468'
>main</code> function
 is called and its argument is bound to the list of the command line
arguments, See <a href="bigloo-4.html#Modules" class="inbound">Module declaration</a>. The
<code id='code17469'
>args-parse</code> form may be used to parse these.<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g17472" class="mark"></a><a name="args-parse" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc17476" align="left" colspan="1"><strong id='bold17474'
>args-parse</strong><em id='it17475'
> list rules [null-rule] [else-rule] ...</em></td><td id="tc17477" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>

The argument <code id='code17481'
><em id='it17480'
>list</em></code> is a list of strings. <code id='code17483'
><em id='it17482'
>Rules</em></code> is defined by
the following grammar:<br/><br/><center id='center17493'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog17491'
>&lt;rule&gt;      ==&gt; (<code id='code17485'
>section</code> &lt;string&gt;)
              | ((&lt;option&gt; &lt;help&gt;) &lt;s-expression&gt;)
              | ((&lt;option&gt;) &lt;s-expression&gt;)
              | ((&lt;flag&gt; &lt;var&gt; &lt;var&gt; ...) &lt;s-expression&gt;)
              | ((&lt;flag&gt; &lt;var&gt; &lt;var&gt; ... &lt;help&gt;) &lt;s-expression&gt;)
&lt;null-rule&gt; ==&gt; (<code id='code17486'
>()</code> &lt;s-expression&gt;)
&lt;else-rule&gt; ==&gt; (<code id='code17487'
>else</code> &lt;s-expression&gt;)
&lt;option&gt;    ==&gt; &lt;flag&gt;
              | &lt;string&gt;&lt;var&gt;
&lt;flag&gt;      ==&gt; &lt;string&gt;
              | (&lt;string&gt;+)
&lt;var&gt;       ==&gt; an identifier leaded by the <code id='code17488'
>?</code> character
&lt;help&gt;      ==&gt; (<code id='code17489'
>help</code> &lt;s-expression&gt;)
              | (<code id='code17490'
>help</code> &lt;string&gt; &lt;s-expression&gt;)
</pre>
</td></tr>
</tbody></table></center>

Each elements of <code id='code17495'
><em id='it17494'
>list</em></code> are match against the <code id='code17497'
><em id='it17496'
>rules</em></code>. If one
of these matches, <code id='code17498'
>args-parse</code> proceeds as follows:<br/><br/><ol class="enumerate" id='enumerate17508'
><li>The matched argument elements of <code id='code17501'
><em id='it17500'
>list</em></code> are removed from the list.
</li>
<li>The <code id='code17503'
>&lt;s-expression&gt;</code> associated to the matching rule
      is evaluated in an environment where the rule variables are bound. 
</li>
<li>The argument parsing is resumed with the rest of <code id='code17506'
><em id='it17505'
>list</em></code>.
</li>
</ol></td></tr>
</tbody></table><br/>
In addition to parsing the command line arguments, <code id='code17511'
>args-parse</code> enables
help message printing. <br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g17514" class="mark"></a><a name="args-parse-usage" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc17518" align="left" colspan="1"><strong id='bold17516'
>args-parse-usage</strong><em id='it17517'
> fmt</em></td><td id="tc17519" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
This is a procedure of one argument, an boolean. <code id='code17522'
>Args-parse-usage</code>
constructs an help message from all the option described in a <code id='code17523'
>args-parse</code>
form. <code id='code17524'
>Args-parse-usage</code> is only defined in the <code id='code17525'
>&lt;s-expression&gt;</code>
of an <code id='code17526'
>args-parse</code> form.
</td></tr>
</tbody></table><br/>
At last, if no rule matches an argument and if the <code id='code17529'
>args-parse</code> form
contains an <code id='code17530'
>else</code> rule, this is evaluated. In the <code id='code17531'
>&lt;s-expression&gt;</code>
part of that rule, a pseudo-variable <code id='code17532'
>else</code> is bound to the unmatched
argument.<br/><br/>Here is an example of argument parsing deploying all the possible rules:<br/><br/><center id='center17559'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog17557'
>(<font color="#1919af"><strong id='bold28485'
>module</strong></font> <font color="#1919af"><strong id='bold28487'
>args-example</strong></font>
   (main main))<br/><br/>(<font color="#6959cf"><strong id='bold28489'
>define</strong></font> (<font color="#6959cf"><strong id='bold28491'
>main</strong></font> argv)
   (args-parse (cdr argv)
      (section <font color="red">&quot;Help&quot;</font>)
      ((<font color="red">&quot;?&quot;</font>)
       (args-parse-usage #f))
      (((<font color="red">&quot;-h&quot;</font> <font color="red">&quot;--help&quot;</font>) (help <font color="red">&quot;?,-h,--help&quot;</font> <font color="red">&quot;This help message&quot;</font>))
       (args-parse-usage #f))
      (section <font color="red">&quot;Misc&quot;</font>)
      (((<font color="red">&quot;-v&quot;</font> <font color="red">&quot;--version&quot;</font>) (help <font color="red">&quot;Version number&quot;</font>))
       (print *version*))
      ((<font color="red">&quot;-o&quot;</font> ?file (help <font color="red">&quot;The output file&quot;</font>))
       (<strong id='bold28505'
>set!</strong> *dest* file))
      ((<font color="red">&quot;--input=?file&quot;</font> (help <font color="red">&quot;The input file&quot;</font>))
       (<strong id='bold28508'
>set!</strong> *input* file))
      (else
       (print <font color="red">&quot;Illegal argument `&quot;</font> else <font color="red">&quot;'. Usage:&quot;</font>)
       (args-parse-usage #f))))
</pre>
</td></tr>
</tbody></table></center>

Invoking the compiled <code id='code17560'
>args-example</code> module could produce:<br/><br/><center id='center17566'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccffcc"><pre class="prog" id='prog17564'
>&gt; bigloo.new args.scm
args.scm:
&gt; a.out toto        
Illegal argument `toto'. Usage:<br/><br/>Help:
   ?,-h,--help    --  This help message<br/><br/>Misc:
   -v,--version   --  Version number
   -o &lt;file&gt;      --  The output file
   --input=&lt;file&gt; --  The input file
</pre>
</td></tr>
</tbody></table></center>
<br/><br/>

</div></td>
</tr></table><div class="skribe-ending">
<hr> 
<p class="ending" id='paragraph28516'
><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='it28514'
>Tue Jun  2 11:43:27 2009</em>.</font></p></div>
</body>
</html>