summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
Diffstat (limited to 'prolog')
-rw-r--r--prolog/problems/algol/algol_3/common.py (renamed from prolog/problems/denotational_semantics/algol_3/common.py)46
-rw-r--r--prolog/problems/algol/algol_3/en.py (renamed from prolog/problems/denotational_semantics/algol_3/en.py)0
-rw-r--r--prolog/problems/algol/algol_for_3/common.py (renamed from prolog/problems/denotational_semantics/algol_for_3/common.py)16
-rw-r--r--prolog/problems/algol/algol_for_3/en.py (renamed from prolog/problems/denotational_semantics/algol_for_3/en.py)0
-rw-r--r--prolog/problems/algol/algol_if_3/common.py (renamed from prolog/problems/denotational_semantics/algol_if_3/common.py)14
-rw-r--r--prolog/problems/algol/algol_if_3/en.py (renamed from prolog/problems/denotational_semantics/algol_if_3/en.py)0
-rw-r--r--prolog/problems/algol/common.py2
-rw-r--r--prolog/problems/algol/en.py2
-rw-r--r--prolog/problems/denotational_semantics/en.py2
-rw-r--r--prolog/problems/denotational_semantics/prog_8puzzle_2/common.py16
-rw-r--r--prolog/problems/denotational_semantics/prog_8puzzle_2/en.py13
-rw-r--r--prolog/problems/denotational_semantics/prog_8puzzle_3/common.py4
-rw-r--r--prolog/problems/denotational_semantics/prog_8puzzle_3/en.py31
-rw-r--r--prolog/problems/denotational_semantics/prog_listswap_2/common.py18
-rw-r--r--prolog/problems/denotational_semantics/prog_listswap_2/en.py12
-rw-r--r--prolog/problems/denotational_semantics/prog_listswap_3/common.py4
-rw-r--r--prolog/problems/denotational_semantics/prog_listswap_3/en.py29
-rw-r--r--prolog/problems/denotational_semantics/sl.py2
18 files changed, 149 insertions, 62 deletions
diff --git a/prolog/problems/denotational_semantics/algol_3/common.py b/prolog/problems/algol/algol_3/common.py
index 8138484..415e1e5 100644
--- a/prolog/problems/denotational_semantics/algol_3/common.py
+++ b/prolog/problems/algol/algol_3/common.py
@@ -1,5 +1,5 @@
id = 176
-number = 83
+number = 10
visible = False
facts = None
@@ -10,8 +10,8 @@ algol(fun(S0,S,apply176([printout=[]|S0],S,Minstructs))) -->
instructs176(Minstr) --> instr176(Minstr).
instructs176(fun(S0,S,
(apply176(S0,S1,Minstr),
- apply176(S1,S,Minstructs))))
- -->
+ apply176(S1,S,Minstructs))))
+ -->
instr176(Minstr), instructs176(Minstructs).
instr176(Massign) --> assign176(Massign).
@@ -26,9 +26,9 @@ instr176(fun(S0,S,
-->
[while], cond176(Mcond), [do,begin], instructs176(Minstructs), [end].
-assign176(fun(S0,[X = Value|S1],
+assign176(fun(S0,[X = Value|S1],
(apply176(S0,Value,Mexpr),
- del(X = _,S0,S1))))
+ del(X = _,S0,S1))))
-->
var176(X), [:=], expr176(Mexpr).
@@ -47,32 +47,32 @@ expr176(fun(S,Value,eval(Expr,S,Value))) -->
apply176(In, Out, fun(In, Out, Goals)) :-
call(Goals).
-loop176( State0, Mcond, _, State0) :-
+loop176(State0, Mcond, _, State0) :-
apply176( State0, false, Mcond), !.
-loop176( S0, Mcond, MBody, S) :-
+loop176(S0, Mcond, MBody, S) :-
copy_term( MBody, MBodyCopy),
apply176( S0, S1, MBody),
loop176( S1, Mcond, MBodyCopy, S).
-eval176( N, _, N) :-
+eval176(N, _, N) :-
number176( N), !.
-eval176( X, State, Val) :- % A program variable
- atom( X), !,
- memb( X = Val, State).
-eval176( E1 + E2, State, Val) :- !,
- eval176( E1, State, V1),
- eval176( E2, State, V2),
+eval176(X, State, Val) :- % A program variable
+ atom(X), !,
+ memb(X = Val, State).
+eval176(E1 + E2, State, Val) :- !,
+ eval176(E1, State, V1),
+ eval176(E2, State, V2),
Val is V1 + V2.
-eval176( E1 - E2, State, Val) :- !,
- eval176( E1, State, V1),
- eval176( E2, State, V2),
+eval176(E1 - E2, State, Val) :- !,
+ eval176(E1, State, V1),
+ eval176(E2, State, V2),
Val is V1 - V2.
-eval176( E1 * E2, State, Val) :- !,
- eval176( E1, State, V1),
- eval176( E2, State, V2),
+eval176(E1 * E2, State, Val) :- !,
+ eval176(E1, State, V1),
+ eval176(E2, State, V2),
Val is V1 * V2.
-eval176( E1 / E2, State, Val) :- !,
- eval176( E1, State, V1),
- eval176( E2, State, V2),
+eval176(E1 / E2, State, Val) :- !,
+ eval176(E1, State, V1),
+ eval176(E2, State, V2),
Val is V1 / V2.
'''
diff --git a/prolog/problems/denotational_semantics/algol_3/en.py b/prolog/problems/algol/algol_3/en.py
index 3b91a47..3b91a47 100644
--- a/prolog/problems/denotational_semantics/algol_3/en.py
+++ b/prolog/problems/algol/algol_3/en.py
diff --git a/prolog/problems/denotational_semantics/algol_for_3/common.py b/prolog/problems/algol/algol_for_3/common.py
index 1107308..654d478 100644
--- a/prolog/problems/denotational_semantics/algol_for_3/common.py
+++ b/prolog/problems/algol/algol_for_3/common.py
@@ -1,5 +1,5 @@
id = 178
-number = 85
+number = 30
visible = False
facts = None
@@ -10,8 +10,8 @@ algol_for(fun(S0,S,apply178([printout=[]|S0],S,Minstructs))) -->
instructs178(Minstr) --> instr178(Minstr).
instructs178(fun(S0,S,
(apply178(S0,S1,Minstr),
- apply178(S1,S,Minstructs))))
- -->
+ apply178(S1,S,Minstructs))))
+ -->
instr178(Minstr), instructs178(Minstructs).
instr178(Massign) --> assign178(Massign).
@@ -31,9 +31,9 @@ instr178(fun(S0, S,
-->
[for], assign178(Minit), [&], cond178(Mcond), [&], assign178(Mstep), [do, begin], instructs178(Mbody), [end].
-assign178(fun(S0,[X = Value|S1],
+assign178(fun(S0,[X = Value|S1],
(apply178(S0,Value,Mexpr),
- del(X = _,S0,S1))))
+ del(X = _,S0,S1))))
-->
var178(X), [:=], expr178(Mexpr).
@@ -54,7 +54,7 @@ apply178(In, Out, fun(In, Out, Goals)) :-
loop178( State0, Mcond, _, State0) :-
apply178( State0, false, Mcond), !.
-loop178( S0, Mcond, MBody, S) :-
+loop178( S0, Mcond, MBody, S) :-
copy_term( MBody, MBodyCopy),
apply178( S0, S1, MBody),
loop178( S1, Mcond, MBodyCopy, S).
@@ -71,8 +71,8 @@ for178(S0, Mcond, Mstep, Mbody, S) :-
eval178( N, _, N) :-
number178( N), !.
eval178( X, State, Val) :- % A program variable
- atom( X), !,
- memb( X = Val, State).
+ atom( X), !,
+ memb( X = Val, State).
eval178( E1 + E2, State, Val) :- !,
eval178( E1, State, V1),
eval178( E2, State, V2),
diff --git a/prolog/problems/denotational_semantics/algol_for_3/en.py b/prolog/problems/algol/algol_for_3/en.py
index 2f46d36..2f46d36 100644
--- a/prolog/problems/denotational_semantics/algol_for_3/en.py
+++ b/prolog/problems/algol/algol_for_3/en.py
diff --git a/prolog/problems/denotational_semantics/algol_if_3/common.py b/prolog/problems/algol/algol_if_3/common.py
index d98d2d2..6678743 100644
--- a/prolog/problems/denotational_semantics/algol_if_3/common.py
+++ b/prolog/problems/algol/algol_if_3/common.py
@@ -1,5 +1,5 @@
id = 177
-number = 84
+number = 20
visible = False
facts = None
@@ -10,8 +10,8 @@ algol_if(fun(S0,S,apply177([printout=[]|S0],S,Minstructs))) -->
instructs177(Minstr) --> instr177(Minstr).
instructs177(fun(S0,S,
(apply177(S0,S1,Minstr),
- apply177(S1,S,Minstructs))))
- -->
+ apply177(S1,S,Minstructs))))
+ -->
instr177(Minstr), instructs177(Minstructs).
instr177(Massign) --> assign177(Massign).
@@ -33,9 +33,9 @@ instr177(fun(S0, S,
-->
[if], cond177(Mcond), [then], instructs177(MinstructsA), [else], instructs177(MinstructsB), [end].
-assign177(fun(S0,[X = Value|S1],
+assign177(fun(S0,[X = Value|S1],
(apply177(S0,Value,Mexpr),
- del(X = _,S0,S1))))
+ del(X = _,S0,S1))))
-->
var177(X), [:=], expr177(Mexpr).
@@ -64,8 +64,8 @@ loop177( S0, Mcond, MBody, S) :-
eval177( N, _, N) :-
number177( N), !.
eval177( X, State, Val) :- % A program variable
- atom( X), !,
- memb( X = Val, State).
+ atom( X), !,
+ memb( X = Val, State).
eval177( E1 + E2, State, Val) :- !,
eval177( E1, State, V1),
eval177( E2, State, V2),
diff --git a/prolog/problems/denotational_semantics/algol_if_3/en.py b/prolog/problems/algol/algol_if_3/en.py
index bd5b732..bd5b732 100644
--- a/prolog/problems/denotational_semantics/algol_if_3/en.py
+++ b/prolog/problems/algol/algol_if_3/en.py
diff --git a/prolog/problems/algol/common.py b/prolog/problems/algol/common.py
new file mode 100644
index 0000000..2885432
--- /dev/null
+++ b/prolog/problems/algol/common.py
@@ -0,0 +1,2 @@
+id = 1001
+number = 12
diff --git a/prolog/problems/algol/en.py b/prolog/problems/algol/en.py
new file mode 100644
index 0000000..340eb4a
--- /dev/null
+++ b/prolog/problems/algol/en.py
@@ -0,0 +1,2 @@
+name = 'Mini-ALGOL'
+description = 'Syntax and semantics for a simple imperative programming language.'
diff --git a/prolog/problems/denotational_semantics/en.py b/prolog/problems/denotational_semantics/en.py
index 418b1e7..a245e15 100644
--- a/prolog/problems/denotational_semantics/en.py
+++ b/prolog/problems/denotational_semantics/en.py
@@ -1,2 +1,2 @@
name = 'Denotational semantics'
-description = 'Adding meaning to grammars, writing a simple compiler for Algol-like programming language.'
+description = 'Adding meaning to grammars for list-processing languages.'
diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py b/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py
index 71875d4..c5b69da 100644
--- a/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py
+++ b/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py
@@ -1,6 +1,6 @@
id = 172
-number = 81
-visible = False
+number = 30
+visible = True
facts = None
solution = '''\
@@ -14,3 +14,15 @@ instr172 --> [right].
instr172 --> [up].
instr172 --> [down].
'''
+
+initial = '''\
+prog_8puzzle --> [begin], instructs, [end].
+
+instructs --> instr.
+instructs --> instr, instructs.
+
+instr --> [left].
+instr --> [right].
+instr --> [up].
+instr --> [down].
+'''
diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_2/en.py b/prolog/problems/denotational_semantics/prog_8puzzle_2/en.py
index 7969ba4..a91e22e 100644
--- a/prolog/problems/denotational_semantics/prog_8puzzle_2/en.py
+++ b/prolog/problems/denotational_semantics/prog_8puzzle_2/en.py
@@ -2,8 +2,17 @@ name = 'prog_8puzzle/2'
slug = '8-puzzle-solving language'
description = '''\
-<p>Write a DCG for solving 8-puzzles. The first symbol in every word is <code>[begin]</code>, followed by any sequence of "instruction" symbols from the set {<code>left</code>, <code>right</code>, <code>up</code>, <code>down</code>}, and finally <code>[end]</code>. The starting symbol should be named <code>prog_8puzzle</code>.</p>
+<p>
+Write a DCG for solving 8-puzzles. The first symbol in every word is
+<code>[begin]</code>, followed by any sequence of "instruction" symbols from
+the set {<code>left</code>, <code>right</code>, <code>up</code>,
+<code>down</code>}, and finally <code>[end]</code>. The starting symbol should
+be named <code>prog_8puzzle</code>.
+</p>
-<p>Example words: <code>[begin,left,down,right,end]</code>, <code>[begin,down,end]</code>.</p>'''
+<p>
+Example words: <code>[begin,left,down,right,end]</code>, <code>[begin,down,end]</code>.
+</p>
+'''
hint = {}
diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py b/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
index 13debcf..0e0d048 100644
--- a/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
+++ b/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
@@ -1,6 +1,6 @@
id = 173
-number = 82
-visible = False
+number = 40
+visible = True
facts = 'denotational_semantics_aux__predicates'
solution = '''\
diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_3/en.py b/prolog/problems/denotational_semantics/prog_8puzzle_3/en.py
index 51aa81a..7a94c74 100644
--- a/prolog/problems/denotational_semantics/prog_8puzzle_3/en.py
+++ b/prolog/problems/denotational_semantics/prog_8puzzle_3/en.py
@@ -2,17 +2,38 @@ name = 'prog_8puzzle/3'
slug = '8-puzzle-solving language with semantics'
description = '''\
-<p>Write a DCG for solving 8-puzzles. The syntax for this language should be the same as in the previous exercise: the first symbol in every word is <code>[begin]</code>, followed by any sequence of "instruction" symbols from the set {<code>left</code>, <code>right</code>, <code>up</code>, <code>down</code>}, and finally <code>[end]</code>. The starting symbol should be named <code>prog_8puzzle</code>.</p>
+<p>
+Write a DCG for solving 8-puzzles. The syntax for this language should be the
+same as in the previous exercise: the first symbol in every word is
+<code>[begin]</code>, followed by any sequence of "instruction" symbols from
+the set {<code>left</code>, <code>right</code>, <code>up</code>,
+<code>down</code>}, and finally <code>[end]</code>. The starting symbol should
+be named <code>prog_8puzzle</code>.
+</p>
-<p>The meaning of a word (program) in this language has the form <code>In-->Out</code>, mapping from input to output states. Each state is a (permuted) list of numbers from 0 to 8, where 0 stands for the empty square and other numbers for the corresponding tiles. The first three numbers in the list correspond to the top row of the 8-puzzle, the next three numbers to the middle row, and the last three numbers to the last row. The meaning of instructions <code>left</code>, <code>right</code>, <code>up</code> and <code>down</code> is to move the blank tile in the given direction.</p>
+<p>
+The meaning of a word (program) in this language has the form
+<code>In-->Out</code>, mapping from input to output states. Each state is a
+(permuted) list of numbers from 0 to 8, where 0 stands for the empty square and
+other numbers for the corresponding tiles. The first three numbers in the list
+correspond to the top row of the 8-puzzle, the next three numbers to the middle
+row, and the last three numbers to the last row. The meaning of instructions
+<code>left</code>, <code>right</code>, <code>up</code> and <code>down</code> is
+to move the blank tile in the given direction.
+</p>
<pre>
?- prog_8puzzle([0,1,2,3,4,5,6,7,8]-->Out, [begin,down,right,end], []).
Out = [3,1,2,4,0,5,6,7,8].
</pre>
-<p>Helper predicates (already defined):<br />
-&nbsp;&nbsp;<code>findblank(List,I)</code> returns the 1-based index <code>I</code> of the element 0 in <code>List</code><br />
-&nbsp;&nbsp;<code>swap(List,I,J,NewList)</code> creates <code>NewList</code> by swapping elements <code>I</code> and <code>J</code> in <code>List</code></p>'''
+<p>
+Helper predicates (already defined):
+</p>
+<ul>
+<li><code>findblank(List,I)</code> returns the 1-based index <code>I</code> of the element 0 in <code>List</code></li>
+<li><code>swap(List,I,J,NewList)</code> creates <code>NewList</code> by swapping elements <code>I</code> and <code>J</code> in <code>List</code></li>
+</ul>
+'''
hint = {}
diff --git a/prolog/problems/denotational_semantics/prog_listswap_2/common.py b/prolog/problems/denotational_semantics/prog_listswap_2/common.py
index e08337d..b3da01f 100644
--- a/prolog/problems/denotational_semantics/prog_listswap_2/common.py
+++ b/prolog/problems/denotational_semantics/prog_listswap_2/common.py
@@ -1,10 +1,10 @@
id = 175
-number = 79
-visible = False
+number = 10
+visible = True
facts = None
solution = '''\
-program --> [begin], instructs175, [end].
+prog_listswap --> [begin], instructs175, [end].
instructs175 --> instr175.
instructs175 --> instr175, instructs175.
@@ -13,3 +13,15 @@ instr175 --> [left].
instr175 --> [right].
instr175 --> [swap].
'''
+
+# nothing to do in this exercise
+initial = '''\
+prog_listswap --> [begin], instructs, [end].
+
+instructs --> instr.
+instructs --> instr, instructs.
+
+instr --> [left].
+instr --> [right].
+instr --> [swap].
+'''
diff --git a/prolog/problems/denotational_semantics/prog_listswap_2/en.py b/prolog/problems/denotational_semantics/prog_listswap_2/en.py
index ad0e9b1..89907bd 100644
--- a/prolog/problems/denotational_semantics/prog_listswap_2/en.py
+++ b/prolog/problems/denotational_semantics/prog_listswap_2/en.py
@@ -2,9 +2,17 @@ name = 'prog_listswap/2'
slug = 'list-manipulation language'
description = '''\
-<p>Write a DCG for manipulating list elements. The first symbol in every word is <code>[begin]</code>, followed by any sequence of "instruction" symbols from the set {<code>left</code>, <code>right</code>, <code>swap</code>}, and finally <code>[end]</code>. The starting symbol should be named <code>prog_listswap</code>.</p>
+<p>
+Write a DCG for manipulating list elements. The first symbol in every word is
+<code>[begin]</code>, followed by any sequence of "instruction" symbols from
+the set {<code>left</code>, <code>right</code>, <code>swap</code>}, and finally
+<code>[end]</code>. The starting symbol should be named
+<code>prog_listswap</code>.
+</p>
-<p>Example words: <code>[begin,right,swap,end]</code>, <code>[begin,right,left,end]</code>.</p>
+<p>
+Example words: <code>[begin,right,swap,end]</code>, <code>[begin,right,left,end]</code>.
+</p>
'''
hint = {}
diff --git a/prolog/problems/denotational_semantics/prog_listswap_3/common.py b/prolog/problems/denotational_semantics/prog_listswap_3/common.py
index dfa7c86..3ad93e8 100644
--- a/prolog/problems/denotational_semantics/prog_listswap_3/common.py
+++ b/prolog/problems/denotational_semantics/prog_listswap_3/common.py
@@ -1,6 +1,6 @@
id = 174
-number = 80
-visible = False
+number = 20
+visible = True
facts = 'denotational_semantics_aux__predicates'
solution = '''\
diff --git a/prolog/problems/denotational_semantics/prog_listswap_3/en.py b/prolog/problems/denotational_semantics/prog_listswap_3/en.py
index b8e9769..e275335 100644
--- a/prolog/problems/denotational_semantics/prog_listswap_3/en.py
+++ b/prolog/problems/denotational_semantics/prog_listswap_3/en.py
@@ -2,16 +2,37 @@ name = 'prog_listswap/3'
slug = 'list-manipulation language with semantics'
description = '''\
-<p>Write a DCG for manipulating list elements. The first symbol in every word is <code>[begin]</code>, followed by any sequence of "instruction" symbols from the set {<code>left</code>, <code>right</code>, <code>swap</code>}, and finally <code>[end]</code>. The starting symbol should be named <code>prog_listswap</code>.</p>
+<p>
+Write a DCG for manipulating list elements. The first symbol in every word is
+<code>[begin]</code>, followed by any sequence of "instruction" symbols from
+the set {<code>left</code>, <code>right</code>, <code>swap</code>}, and finally
+<code>[end]</code>. The starting symbol should be named
+<code>prog_listswap</code>.
+</p>
-<p>The meaning of a word (program) in this language has the form <code>In-->Out</code>, mapping from input to output lists. Besides the list contents, internal states also hold the current cursor position. The <code>left</code> and <code>right</code> instructions move the cursor one step in the given direction, while the <code>swap</code> instruction swaps the element under the cursor with its left neighbor (and fails if cursor is currently pointing to the first element of the list).</p>
+<p>
+The meaning of a word (program) in this language has the form
+<code>In-->Out</code>, mapping from input to output lists. Besides the list
+contents, internal states also hold the current cursor position. The
+<code>left</code> and <code>right</code> instructions move the cursor one step
+in the given direction, while the <code>swap</code> instruction swaps the
+element under the cursor with its left neighbor (and fails if cursor is
+currently pointing to the first element of the list).
+</p>
<pre>
?- prog_listswap([1,2,3,4]-->Out, [begin,right,swap,end], []).
Out = [2,1,3,4].
</pre>
-<p>Helper predicate (already defined):<br />
-&nbsp;&nbsp;<code>swap(List,I,NewList)</code> creates <code>NewList</code> by swapping the <code>I</code>th element with its left neighbor in <code>List</code></p>'''
+<p>
+Helper predicates (already defined):
+</p>
+<ul>
+<li><code>swap(List,I,NewList)</code> creates <code>NewList</code> by
+swapping the <code>I</code>th element with its left neighbor in
+<code>List</code></li>
+</ul>
+'''
hint = {}
diff --git a/prolog/problems/denotational_semantics/sl.py b/prolog/problems/denotational_semantics/sl.py
index d0e8f1e..6a7f823 100644
--- a/prolog/problems/denotational_semantics/sl.py
+++ b/prolog/problems/denotational_semantics/sl.py
@@ -1,2 +1,2 @@
name = 'Denotacijske semantike'
-description = 'Dodajanje pomena gramatikam, pisanje preprostega prevajalnika za programski jezik algolskega tipa.'
+description = 'Dodajanje pomena gramatikam jezikov za delo s seznami.'