inweb-bootstrap/docs/inweb/M-tid.html
2021-02-04 17:56:57 +00:00

135 lines
8.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>The InC Dialect</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="en-gb">
<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>
<body class="commentary-font">
<nav role="navigation">
<h1><a href="../index.html">
<img src="../docs-assets/Octagram.png" width=72 height=72">
</a></h1>
<ul><li><a href="index.html"><span class="selectedlink">inweb</span></a></li>
</ul><h2>Foundation Module</h2><ul>
<li><a href="../foundation-module/index.html">foundation</a></li>
<li><a href="../foundation-test/index.html">foundation-test</a></li>
</ul><h2>Example Webs</h2><ul>
<li><a href="../goldbach/index.html">goldbach</a></li>
<li><a href="../twinprimes/twinprimes.html">twinprimes</a></li>
<li><a href="../eastertide/index.html">eastertide</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=18> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="../../../inform/docs/index.html">inform</a></li>
<li><a href="../../../intest/docs/index.html">intest</a></li>
</ul>
</nav>
<main role="main">
<!--Weave of 'The InC Dialect' generated by Inweb-->
<div class="breadcrumbs">
<ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="index.html">inweb</a></li><li><a href="index.html#M">Manual</a></li><li><b>The InC Dialect</b></li></ul></div>
<p class="purpose">A modest extension of C used by the Inform project.</p>
<ul class="toc"><li><a href="M-tid.html#SP1">&#167;1. The InC language</a></li></ul><hr class="tocbar">
<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. The InC language. </b>InC is only a little extended from regular C. All of the Inform tools are
written in InC, as is the <span class="extract"><span class="extract-syntax">foundation</span></span> module of utility routines built in
to Inweb. It's probably not sensible to use InC in a web which does not
import <span class="extract"><span class="extract-syntax">foundation</span></span>, and it's certainly not possible to import <span class="extract"><span class="extract-syntax">foundation</span></span>
on a web not written in InC. So the two go together.
</p>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>Though this is really a feature of Inweb rather than InC, and is also
true of regular C webs, functions, definitions and typedef structs need not
be declared before use. In this way, the need for header files can be
avoided altogether.
</p>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>Each section of an InC web can, optionally, begin:
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax"> </span><span class="identifier-syntax">[Namespace::]</span><span class="plain-syntax"> The Title of This Section.</span>
</pre>
<p class="commentary">rather than, as normal,
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax"> The Title of This Section.</span>
</pre>
<p class="commentary">That declares that all functions in this section must be have a name which
begins with <span class="extract"><span class="extract-syntax">Namespace::</span></span>. For example,
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">Namespace::initialise</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax"> ....</span>
<span class="plain-syntax"> }</span>
</pre>
<p class="commentary">Inweb will not allow a function with the wrong namespace (or with none) to
be declared in the section. This rudimentary feature enables the different
sections of the web to behave like packages or modules in languages which
support rather more compartmentalisation than standard C.
</p>
<p class="commentary">The tangler converts these identifiers to regular C identifiers by converting
the <span class="extract"><span class="extract-syntax">::</span></span> to <span class="extract"><span class="extract-syntax">__</span></span>, so in a debugger, the above function would look like
<span class="extract"><span class="extract-syntax">Namespace__initialise</span></span>.
</p>
<p class="commentary">Namespaces can be "nested", in the sense that, for example, we could have:
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax"> </span><span class="identifier-syntax">[Errors::Fatal::]</span><span class="plain-syntax"> Handling fatal errors.</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>The <span class="extract"><span class="extract-syntax">foundation</span></span> module contains a suite of utility functions for handling
strings and streams of text. These are unified in a structure called
<span class="extract"><span class="extract-syntax">text_stream</span></span>, so that strings in InC webs are almost all values of type
<span class="extract"><span class="extract-syntax">text_stream *</span></span>. InC provides one convenient feature for this: the notation
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax"> text_stream *excuse = I"The compiler is not feeling well today.";</span>
</pre>
<p class="commentary">creates a string literal of this type. (This is analogous to ANSI C's little
used syntax for "long strings", which is <span class="extract"><span class="extract-syntax">L"like so"</span></span>.)
</p>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>The <span class="extract"><span class="extract-syntax">words</span></span> module, a component of the Inform compiler which is not
included in Inweb, defines natural-language grammars in a notation called
Preform. Inweb contains support for writing these directly into code; any
paragraph whose code section makes use of this feature is automatically
tagged <span class="extract"><span class="extract-syntax">^"Preform"</span></span>. This is not the place to document what Preform
notation means, but for example:
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax"> &lt;declaration&gt; ::=</span>
<span class="plain-syntax"> declare &lt;dominion&gt; independent ==&gt; { R[1], - }</span>
<span class="plain-syntax"> &lt;dominion&gt; ::=</span>
<span class="plain-syntax"> canada |</span>
<span class="plain-syntax"> india |</span>
<span class="plain-syntax"> malaya</span>
</pre>
<nav role="progress"><div class="progresscontainer">
<ul class="progressbar"><li class="progressprev"><a href="M-spl.html">&#10094;</a></li><li class="progresscurrentchapter">M</li><li class="progresssection"><a href="M-iti.html">iti</a></li><li class="progresssection"><a href="M-wtaw.html">wtaw</a></li><li class="progresssection"><a href="M-htwaw.html">htwaw</a></li><li class="progresssection"><a href="M-mwiw.html">mwiw</a></li><li class="progresssection"><a href="M-awwp.html">awwp</a></li><li class="progresssection"><a href="M-spl.html">spl</a></li><li class="progresscurrent">tid</li><li class="progresssection"><a href="M-rc.html">rc</a></li><li class="progresschapter"><a href="P-htpw.html">P</a></li><li class="progresschapter"><a href="1-bsc.html">1</a></li><li class="progresschapter"><a href="2-tr.html">2</a></li><li class="progresschapter"><a href="3-ta.html">3</a></li><li class="progresschapter"><a href="4-pl.html">4</a></li><li class="progresschapter"><a href="5-wt.html">5</a></li><li class="progresschapter"><a href="6-mkf.html">6</a></li><li class="progressnext"><a href="M-rc.html">&#10095;</a></li></ul></div>
</nav><!--End of weave-->
</main>
</body>
</html>