improved indentation and whitespace for markdown code blocks
All code blocks in markdown have been intended by at least 4 spaces. We add `--tab-stop=8` to all `pandoc(1)` executions in order to set a better tab stop indentation, especially for tab intended code blocks. Changed `bin/pandoc-wrapper.sh` VERSION from "1.5.3 2024-03-26" to "1.6 2024-03-31". Fixed `1991/brnstnd/sorta.README.md` so that the sorta code is code blocks. Removed unneeded paragraph group in copyright in `inc/footer.default.html`. Fixed excess whitespace after list Author on entry `index.html` page. Changed `bin/output-index-author.sh` VERSION from "1.5.2 2024-03-26" to "1.6 2024-03-31". Performed `make www` to perform the above and test under macOS. TODO: Fix the problem of the initial line of code being extra intended. TODO: Fix excess whitespace around code that is inline.
This commit is contained in:
1 parent
b84c27ce02
commit
a996f8d2b8
734 files changed
+16723
-16963
No files matched your search
+59
-60
@@ -1,7 +1,7 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
make all
|
||||
make all
|
||||
```
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ make all
|
||||
The current status of this entry is:
|
||||
|
||||
```
|
||||
STATUS: doesn't work with some compilers - please provide alternative code or fix for more compilers
|
||||
STATUS: doesn't work with some compilers - please provide alternative code or fix for more compilers
|
||||
```
|
||||
|
||||
For more detailed information see [1996 august bugs](../../bugs.html#1996_august).
|
||||
@@ -19,8 +19,8 @@ For more detailed information see [1996 august bugs](../../bugs.html#1996_august
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
cat august.c test.oc | ./august > test.oo
|
||||
./august < test.oo
|
||||
cat august.c test.oc | ./august > test.oo
|
||||
./august < test.oo
|
||||
```
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ The above should print a `!` followed by a newline.
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
./try.sh
|
||||
./try.sh
|
||||
```
|
||||
|
||||
|
||||
@@ -44,33 +44,33 @@ This entry can feed on itself. If you C pre-process the source,
|
||||
you can compile the interpreter:
|
||||
|
||||
```sh
|
||||
make august.oc
|
||||
make august.oc
|
||||
```
|
||||
|
||||
We can now compile the interpreter as follows:
|
||||
|
||||
```sh
|
||||
cat august.c august.oc | ./august > august.oo
|
||||
cat august.c august.oc | ./august > august.oo
|
||||
```
|
||||
|
||||
and use the compiled interpreter to execute some previously
|
||||
compiled code:
|
||||
|
||||
```sh
|
||||
cat august.oo test.oo | ./august
|
||||
cat august.oo test.oo | ./august
|
||||
```
|
||||
|
||||
And we can have the compiled interpreter interpret itself which
|
||||
in turn compiles the test program:
|
||||
|
||||
```sh
|
||||
cat august.oo august.oo fac.oo | ./august
|
||||
cat august.oo august.oo fac.oo | ./august
|
||||
```
|
||||
|
||||
And if you have lots of spare time, you can recurse one level deeper:
|
||||
|
||||
```sh
|
||||
cat august.oo august.oo august.oo fac.oo | ./august
|
||||
cat august.oo august.oo august.oo fac.oo | ./august
|
||||
```
|
||||
|
||||
We (the judges) recommend that you spend some time studying this
|
||||
@@ -108,25 +108,25 @@ Assume that the interpreter has been compiled (source in [august.c](august.c)
|
||||
and binary in august) and that we have this in a file named `test.oc`:
|
||||
|
||||
```c
|
||||
main() { putchar('!'); putchar('\n'); exit(0); }
|
||||
main() { putchar('!'); putchar('\n'); exit(0); }
|
||||
```
|
||||
|
||||
We can then compile by
|
||||
|
||||
```sh
|
||||
cat august.c test.oc | ./august > test.oo
|
||||
cat august.c test.oc | ./august > test.oo
|
||||
```
|
||||
|
||||
And run the compiled program by
|
||||
|
||||
```sh
|
||||
./august < test.oo
|
||||
./august < test.oo
|
||||
```
|
||||
|
||||
Or even simpler:
|
||||
|
||||
```sh
|
||||
cat august.c test.oc | ./august | ./august
|
||||
cat august.c test.oc | ./august | ./august
|
||||
```
|
||||
|
||||
A larger example is included [fac.oc](fac.oc).
|
||||
@@ -142,26 +142,26 @@ command from the Makefile, but add the `-E` flag and change 60000 to 40000,
|
||||
i.e.:
|
||||
|
||||
```sh
|
||||
cc -E -DZ=40000 .... august.c > august.oc
|
||||
cc -E -DZ=40000 .... august.c > august.oc
|
||||
```
|
||||
|
||||
If `august.oc` contain some junk line starting with a `#` (most likely
|
||||
it does) then remove it like:
|
||||
|
||||
```sh
|
||||
sed -i'' '/^#/d' august.oc
|
||||
sed -i'' '/^#/d' august.oc
|
||||
```
|
||||
|
||||
OK, we can now compile the interpreter:
|
||||
|
||||
```sh
|
||||
cat august.c august.oc | ./august > august.oo
|
||||
cat august.c august.oc | ./august > august.oo
|
||||
```
|
||||
|
||||
And we can run it:
|
||||
|
||||
```sh
|
||||
cat august.oo test.oo | ./august
|
||||
cat august.oo test.oo | ./august
|
||||
```
|
||||
|
||||
Here we have the interpreter interpreting another interpreter that runs
|
||||
@@ -169,13 +169,13 @@ the program. Did you think that was too fast? Just throw in another
|
||||
level of interpretation:
|
||||
|
||||
```sh
|
||||
cat august.oo august.oo test.oo | ./august
|
||||
cat august.oo august.oo test.oo | ./august
|
||||
```
|
||||
|
||||
And another...
|
||||
|
||||
```sh
|
||||
cat august.oo august.oo august.oo test.oo | ./august
|
||||
cat august.oo august.oo august.oo test.oo | ./august
|
||||
```
|
||||
|
||||
---
|
||||
@@ -214,62 +214,61 @@ Below is a description of the OC grammar.
|
||||
Terminals are in quotes, `()` is used for bracketing.
|
||||
|
||||
```
|
||||
program: decl*
|
||||
program: decl*
|
||||
|
||||
decl: vardecl
|
||||
fundecl
|
||||
decl: vardecl
|
||||
fundecl
|
||||
|
||||
vardecl: type NAME ;
|
||||
type NAME "[" INT "]" ;
|
||||
vardecl: type NAME ;
|
||||
type NAME "[" INT "]" ;
|
||||
|
||||
fundecl: type NAME "(" args ")" "{" body "}"
|
||||
fundecl: type NAME "(" args ")" "{" body "}"
|
||||
|
||||
args: /*empty*/
|
||||
( arg "," )* arg
|
||||
args: /*empty*/
|
||||
( arg "," )* arg
|
||||
|
||||
arg: type NAME
|
||||
arg: type NAME
|
||||
|
||||
body: vardecl* stmt*
|
||||
body: vardecl* stmt*
|
||||
|
||||
stmt: ifstmt
|
||||
whilestmt
|
||||
dowhilestmt
|
||||
"return" expr ";"
|
||||
expr ";"
|
||||
"{" stmt* "}"
|
||||
";"
|
||||
stmt: ifstmt
|
||||
whilestmt
|
||||
dowhilestmt
|
||||
"return" expr ";"
|
||||
expr ";"
|
||||
"{" stmt* "}"
|
||||
";"
|
||||
|
||||
ifstmt: "if" "(" expr ")" stmt
|
||||
"if" "(" expr ")" stmt "else" stmt
|
||||
ifstmt: "if" "(" expr ")" stmt
|
||||
"if" "(" expr ")" stmt "else" stmt
|
||||
|
||||
whilestmt: "while" "(" expr ")" stmt
|
||||
whilestmt: "while" "(" expr ")" stmt
|
||||
|
||||
dowhilestmt: "do" stmt "while" "(" expr ")" ";"
|
||||
dowhilestmt: "do" stmt "while" "(" expr ")" ";"
|
||||
|
||||
expr: expr binop expr
|
||||
unop expr
|
||||
expr "[" expr "]"
|
||||
"(" expr ")"
|
||||
expr "(" exprs ")"
|
||||
NAME
|
||||
INT
|
||||
CHAR
|
||||
STRING
|
||||
expr: expr binop expr
|
||||
unop expr
|
||||
expr "[" expr "]"
|
||||
"(" expr ")"
|
||||
expr "(" exprs ")"
|
||||
NAME
|
||||
INT
|
||||
CHAR
|
||||
STRING
|
||||
|
||||
exprs: /*empty*/
|
||||
(expr ",")* expr
|
||||
exprs: /*empty*/
|
||||
(expr ",")* expr
|
||||
|
||||
binop: "+" | "-" | "*" | "/" | "%" |
|
||||
"=" |
|
||||
"<" | "==" | "!="
|
||||
binop: "+" | "-" | "*" | "/" | "%" |
|
||||
"=" |
|
||||
"<" | "==" | "!="
|
||||
|
||||
unop: "!" | "-" | "*"
|
||||
unop: "!" | "-" | "*"
|
||||
|
||||
type: "int" stars
|
||||
"char" stars
|
||||
|
||||
stars: "*"*
|
||||
type: "int" stars
|
||||
"char" stars
|
||||
|
||||
stars: "*"*
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
+60
-62
@@ -132,8 +132,7 @@
|
||||
<h2 id="author"><a name="author"></a>Author:</h2>
|
||||
<ul>
|
||||
<li>Name: <a href="../../authors.html#Lennart_Augustsson">Lennart Augustsson</a><br>
|
||||
Location: <a href="../../location.html#SE">SE</a> - <em>Kingdom of Sweden</em> (<em>Sweden</em>)
|
||||
<br><br></li>
|
||||
Location: <a href="../../location.html#SE">SE</a> - <em>Kingdom of Sweden</em> (<em>Sweden</em>)</li>
|
||||
</ul>
|
||||
|
||||
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
|
||||
@@ -142,34 +141,34 @@ Location: <a href="../../location.html#SE">SE</a> - <em>Kingdom of Sweden</em> (
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">make</span> all</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> all</span></code></pre></div>
|
||||
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
|
||||
<p>The current status of this entry is:</p>
|
||||
<pre><code>STATUS: doesn't work with some compilers - please provide alternative code or fix for more compilers</code></pre>
|
||||
<pre><code> STATUS: doesn't work with some compilers - please provide alternative code or fix for more compilers</code></pre>
|
||||
<p>For more detailed information see <a href="../../bugs.html#1996_august">1996 august bugs</a>.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.c test.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="op">></span> test.oo</span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="ex">./august</span> <span class="op"><</span> test.oo</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.c test.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="op">></span> test.oo</span>
|
||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">./august</span> <span class="op"><</span> test.oo</span></code></pre></div>
|
||||
<p>NOTE: some compilers will compile this code into infinite loops! If the above
|
||||
cat line (or one of the ones later in the try section) does not execute in a
|
||||
very short amount of time, then you may need to fix your compiler or use gcc.</p>
|
||||
<p>The above should print a <code>!</code> followed by a newline.</p>
|
||||
<h2 id="try">Try:</h2>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./try.sh</span></span></code></pre></div>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>This entry can feed on itself. If you C pre-process the source,
|
||||
you can compile the interpreter:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">make</span> august.oc</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> august.oc</span></code></pre></div>
|
||||
<p>We can now compile the interpreter as follows:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.c august.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="op">></span> august.oo</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.c august.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="op">></span> august.oo</span></code></pre></div>
|
||||
<p>and use the compiled interpreter to execute some previously
|
||||
compiled code:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.oo test.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.oo test.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<p>And we can have the compiled interpreter interpret itself which
|
||||
in turn compiles the test program:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.oo august.oo fac.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.oo august.oo fac.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<p>And if you have lots of spare time, you can recurse one level deeper:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.oo august.oo august.oo fac.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.oo august.oo august.oo fac.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<p>We (the judges) recommend that you spend some time studying this
|
||||
entry as it surely will make the ‘best of the IOCCC’ list. It was
|
||||
very well received by those who attended the IOCCC BOF.</p>
|
||||
@@ -195,13 +194,13 @@ of operators, and control constructs.</p>
|
||||
can go wrong. But this is what seasoned C programmers are used to.</p>
|
||||
<p>Assume that the interpreter has been compiled (source in <a href="august.c">august.c</a>
|
||||
and binary in august) and that we have this in a file named <code>test.oc</code>:</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>main<span class="op">()</span> <span class="op">{</span> putchar<span class="op">(</span><span class="ch">'!'</span><span class="op">);</span> putchar<span class="op">(</span><span class="ch">'</span><span class="sc">\n</span><span class="ch">'</span><span class="op">);</span> exit<span class="op">(</span><span class="dv">0</span><span class="op">);</span> <span class="op">}</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> main<span class="op">()</span> <span class="op">{</span> putchar<span class="op">(</span><span class="ch">'!'</span><span class="op">);</span> putchar<span class="op">(</span><span class="ch">'</span><span class="sc">\n</span><span class="ch">'</span><span class="op">);</span> exit<span class="op">(</span><span class="dv">0</span><span class="op">);</span> <span class="op">}</span></span></code></pre></div>
|
||||
<p>We can then compile by</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.c test.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="op">></span> test.oo</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.c test.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="op">></span> test.oo</span></code></pre></div>
|
||||
<p>And run the compiled program by</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./august</span> <span class="op"><</span> test.oo</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./august</span> <span class="op"><</span> test.oo</span></code></pre></div>
|
||||
<p>Or even simpler:</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.c test.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.c test.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<p>A larger example is included <a href="fac.oc">fac.oc</a>.</p>
|
||||
<p>The compiler for OC is naturally written in OC (where did you think the byte
|
||||
code came from?). It is in the file <a href="parse.oc">parse.oc</a>.</p>
|
||||
@@ -211,20 +210,20 @@ preprocessor (hey, what do you expect from a program that is this small), so we
|
||||
need to use an external one. To pre-process <a href="august.c">august.c</a> use the
|
||||
command from the Makefile, but add the <code>-E</code> flag and change 60000 to 40000,
|
||||
i.e.:</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cc</span> <span class="at">-E</span> <span class="at">-DZ</span><span class="op">=</span>40000 .... august.c <span class="op">></span> august.oc</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cc</span> <span class="at">-E</span> <span class="at">-DZ</span><span class="op">=</span>40000 .... august.c <span class="op">></span> august.oc</span></code></pre></div>
|
||||
<p>If <code>august.oc</code> contain some junk line starting with a <code>#</code> (most likely
|
||||
it does) then remove it like:</p>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sed</span> <span class="at">-i</span><span class="st">''</span> <span class="st">'/^#/d'</span> august.oc</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb15"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sed</span> <span class="at">-i</span><span class="st">''</span> <span class="st">'/^#/d'</span> august.oc</span></code></pre></div>
|
||||
<p>OK, we can now compile the interpreter:</p>
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.c august.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="op">></span> august.oo</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.c august.oc <span class="kw">|</span> <span class="ex">./august</span> <span class="op">></span> august.oo</span></code></pre></div>
|
||||
<p>And we can run it:</p>
|
||||
<div class="sourceCode" id="cb17"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.oo test.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb17"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.oo test.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<p>Here we have the interpreter interpreting another interpreter that runs
|
||||
the program. Did you think that was too fast? Just throw in another
|
||||
level of interpretation:</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.oo august.oo test.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.oo august.oo test.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<p>And another…</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> august.oo august.oo august.oo test.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> august.oo august.oo august.oo test.oo <span class="kw">|</span> <span class="ex">./august</span></span></code></pre></div>
|
||||
<hr />
|
||||
<p>Fitting the byte code for the compiler into the initial comment
|
||||
was a challenge. I had to strip the compiler/interpreter of
|
||||
@@ -251,62 +250,61 @@ defined. <code>getchar()</code> and <code>putchar()</code> are predefined functi
|
||||
<p>Below is a description of the OC grammar.</p>
|
||||
<h3 id="oc-grammar">OC grammar</h3>
|
||||
<p>Terminals are in quotes, <code>()</code> is used for bracketing.</p>
|
||||
<pre><code>program: decl*
|
||||
<pre><code> program: decl*
|
||||
|
||||
decl: vardecl
|
||||
fundecl
|
||||
decl: vardecl
|
||||
fundecl
|
||||
|
||||
vardecl: type NAME ;
|
||||
type NAME "[" INT "]" ;
|
||||
vardecl: type NAME ;
|
||||
type NAME "[" INT "]" ;
|
||||
|
||||
fundecl: type NAME "(" args ")" "{" body "}"
|
||||
fundecl: type NAME "(" args ")" "{" body "}"
|
||||
|
||||
args: /*empty*/
|
||||
( arg "," )* arg
|
||||
args: /*empty*/
|
||||
( arg "," )* arg
|
||||
|
||||
arg: type NAME
|
||||
arg: type NAME
|
||||
|
||||
body: vardecl* stmt*
|
||||
body: vardecl* stmt*
|
||||
|
||||
stmt: ifstmt
|
||||
whilestmt
|
||||
dowhilestmt
|
||||
"return" expr ";"
|
||||
expr ";"
|
||||
"{" stmt* "}"
|
||||
";"
|
||||
stmt: ifstmt
|
||||
whilestmt
|
||||
dowhilestmt
|
||||
"return" expr ";"
|
||||
expr ";"
|
||||
"{" stmt* "}"
|
||||
";"
|
||||
|
||||
ifstmt: "if" "(" expr ")" stmt
|
||||
"if" "(" expr ")" stmt "else" stmt
|
||||
ifstmt: "if" "(" expr ")" stmt
|
||||
"if" "(" expr ")" stmt "else" stmt
|
||||
|
||||
whilestmt: "while" "(" expr ")" stmt
|
||||
whilestmt: "while" "(" expr ")" stmt
|
||||
|
||||
dowhilestmt: "do" stmt "while" "(" expr ")" ";"
|
||||
dowhilestmt: "do" stmt "while" "(" expr ")" ";"
|
||||
|
||||
expr: expr binop expr
|
||||
unop expr
|
||||
expr "[" expr "]"
|
||||
"(" expr ")"
|
||||
expr "(" exprs ")"
|
||||
NAME
|
||||
INT
|
||||
CHAR
|
||||
STRING
|
||||
expr: expr binop expr
|
||||
unop expr
|
||||
expr "[" expr "]"
|
||||
"(" expr ")"
|
||||
expr "(" exprs ")"
|
||||
NAME
|
||||
INT
|
||||
CHAR
|
||||
STRING
|
||||
|
||||
exprs: /*empty*/
|
||||
(expr ",")* expr
|
||||
exprs: /*empty*/
|
||||
(expr ",")* expr
|
||||
|
||||
binop: "+" | "-" | "*" | "/" | "%" |
|
||||
"=" |
|
||||
"<" | "==" | "!="
|
||||
binop: "+" | "-" | "*" | "/" | "%" |
|
||||
"=" |
|
||||
"<" | "==" | "!="
|
||||
|
||||
unop: "!" | "-" | "*"
|
||||
unop: "!" | "-" | "*"
|
||||
|
||||
type: "int" stars
|
||||
"char" stars
|
||||
type: "int" stars
|
||||
"char" stars
|
||||
|
||||
stars: "*"*
|
||||
</code></pre>
|
||||
stars: "*"*</code></pre>
|
||||
<hr />
|
||||
<p>Well, that is enough ranting for now.</p>
|
||||
<!--
|
||||
|
||||
Reference in new issue
Block a user