2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,15 +1,24 @@
Create an interpreter for a [[wp:Markov algorithm|Markov Algorithm]]. Rules have the syntax:
;Task:
Create an interpreter for a [[wp:Markov algorithm|Markov Algorithm]].
Rules have the syntax:
<ruleset> ::= ((<comment> | <rule>) <newline>+)*
<comment> ::= # {<any character>}
<rule> ::= <pattern> <whitespace> -> <whitespace> [.] <replacement>
<whitespace> ::= (<tab> | <space>) [<whitespace>]
There is one rule per line. If there is a . present before the <replacement>, then this is a terminating rule in which case the interpreter must halt execution. A ruleset consists of a sequence of rules, with optional comments.
There is one rule per line.
=Rulesets=
If there is a &nbsp; <b>.</b> &nbsp; (period) &nbsp; present before the &nbsp; '''<replacement>''', &nbsp; then this is a terminating rule in which case the interpreter must halt execution.
A ruleset consists of a sequence of rules, with optional comments.
<big><big> Rulesets </big></big>
Use the following tests on entries:
==Ruleset 1==
;Ruleset 1:
<pre>
# This rules file is extracted from Wikipedia:
# http://en.wikipedia.org/wiki/Markov_Algorithm
@ -21,11 +30,12 @@ the shop -> my brother
a never used -> .terminating rule
</pre>
Sample text of:
: <code>I bought a B of As from T S.</code>
: <code> I bought a B of As from T S. </code>
Should generate the output:
: <code>I bought a bag of apples from my brother.</code>
: <code> I bought a bag of apples from my brother. </code>
==Ruleset 2==
;Ruleset 2:
A test of the terminating rule
<pre>
# Slightly modified from the rules on Wikipedia
@ -40,9 +50,11 @@ Sample text of:
Should generate:
: <code>I bought a bag of apples from T shop.</code>
==Ruleset 3==
;Ruleset 3:
This tests for correct substitution order and may trap simple regexp based replacement routines if special regexp characters are not escaped.
<pre># BNF Syntax testing rules
<pre>
# BNF Syntax testing rules
A -> apple
WWWW -> with
Bgage -> ->.*
@ -52,14 +64,16 @@ W -> WW
S -> .shop
T -> the
the shop -> my brother
a never used -> .terminating rule</pre>
a never used -> .terminating rule
</pre>
Sample text of:
: <code>I bought a B of As W my Bgage from T S.</code>
Should generate:
: <code>I bought a bag of apples with my money from T shop.</code>
==Ruleset 4==
This tests for correct order of scanning of rules, and may trap replacement routines that scan in the wrong order. It implements a general unary multiplication engine. (Note that the input expression must be placed within underscores in this implementation.)
;Ruleset 4:
This tests for correct order of scanning of rules, and may trap replacement routines that scan in the wrong order. &nbsp; It implements a general unary multiplication engine. &nbsp; (Note that the input expression must be placed within underscores in this implementation.)
<pre>
### Unary Multiplication Engine, for testing Markov Algorithm implementations
### By Donal Fellows.
@ -91,15 +105,16 @@ _1 -> 1
_+_ ->
</pre>
Sample text of:
: <code>_1111*11111_</code>
: <code> _1111*11111_ </code>
should generate the output:
: <code>11111111111111111111</code>
: <code> 11111111111111111111 </code>
==Ruleset 5==
;Ruleset 5:
A simple [http://en.wikipedia.org/wiki/Turing_machine Turing machine],
implementing a three-state [http://en.wikipedia.org/wiki/Busy_beaver busy beaver].
The tape consists of 0s and 1s, the states are A, B, C and H (for Halt), and the head position is indicated by writing the state letter before the character where the head is.
The tape consists of '''0'''s and '''1'''s, &nbsp; the states are '''A''', '''B''', '''C''' and '''H''' (for '''H'''alt), and the head position is indicated by writing the state letter before the character where the head is.
All parts of the initial tape the machine operates on have to be given in the input.
Besides demonstrating that the Markov algorithm is Turing-complete, it also made me catch a bug in the C++ implementation which wasn't caught by the first four rulesets.
@ -124,8 +139,7 @@ B1 -> 1B
1C1 -> H11
</pre>
This ruleset should turn
: <code>000000A000000</code>
: <code> 000000A000000 </code>
into
: <code>00011H1111000</code>
=Examples=
: <code> 00011H1111000 </code>
<br><br>