Skip to content

Commit

Permalink
NB exercises
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@705 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Nov 13, 2009
1 parent 385df7e commit cadb00e
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 1 deletion.
8 changes: 8 additions & 0 deletions topics/exercises/README.txt
@@ -0,0 +1,8 @@
while1 - a DCG parser for a fragment of While
while2 - a DCG parser for While
while3 - big step semantics for While (+ a DCG parser)
while4 - small step semantics for While (+ a DCG parser)
xml1 - a DCG parser for XML subset (elements only)
xml2 - a DCG parser for XML subset (elements and attributes)
nb1 - abstract syntax for NB
nb1 - typed NB abstract syntax
6 changes: 6 additions & 0 deletions topics/exercises/nb1/Makefile
@@ -0,0 +1,6 @@
test:
swipl -f syntax.pro -t "term(`cat input.txt`)"

prompt:
swipl -s syntax.pro

1 change: 1 addition & 0 deletions topics/exercises/nb1/input.txt
@@ -0,0 +1 @@
if(iszero(zero),true,succ(zero))
2 changes: 2 additions & 0 deletions topics/exercises/nb1/syntax.pro
@@ -1,5 +1,7 @@
% see slides #109, #113
term(true).
term(false).
term(zero).
term(succ(T)) :- term(T).
term(pred(T)) :- term(T).
term(iszero(T)) :- term(T).
Expand Down
7 changes: 7 additions & 0 deletions topics/exercises/nb2/Makefile
@@ -0,0 +1,7 @@
test:
swipl -f types.pro -t "type(`cat input1.txt`,T),write(T),nl"
swipl -f types.pro -t "type(`cat input2.txt`,T),write(T),nl"

prompt:
swipl -s types.pro

1 change: 1 addition & 0 deletions topics/exercises/nb2/input1.txt
@@ -0,0 +1 @@
if(iszero(zero),zero,succ(succ(zero)))
1 change: 1 addition & 0 deletions topics/exercises/nb2/input2.txt
@@ -0,0 +1 @@
if(iszero(zero),iszero(succ(zero)),true)
9 changes: 9 additions & 0 deletions topics/exercises/nb2/syntax.pro
@@ -0,0 +1,9 @@
% see slides #109, #113
term(true).
term(false).
term(zero).
term(succ(T)) :- term(T).
term(pred(T)) :- term(T).
term(iszero(T)) :- term(T).
term(if(T1,T2,T3)) :- term(T1), term(T2), term(T3).

27 changes: 27 additions & 0 deletions topics/exercises/nb2/types.pro
@@ -0,0 +1,27 @@
:- ['syntax.pro'].

%% see slide 126
% T-True
type(true,bool).

% T-False
type(false,bool).

% T-If
type(if(T1,T2,T3),T) :-
type(T1,bool),
type(T2,T),
type(T3,T).

% T-Zero
type(zero,nat).

% T-Succ
type(succ(T),nat) :- type(T,nat).

% T-Pred
type(pred(T),nat) :- type(T,nat).

% T-Iszero
type(iszero(T),bool) :- type(T,nat).

4 changes: 3 additions & 1 deletion topics/exercises/while3/mappings.pro
Expand Up @@ -4,6 +4,8 @@ lookup(M,X,Y) :- append(_,[(X,Y)|_],M).
% Function update in one position
update([],X,Y,[(X,Y)]).
update([(X,_)|M],X,Y,[(X,Y)|M]).
update([(X1,Y1)|M1],X2,Y2,[(X1,Y1)|M2]) :- \+ X1 = X2, update(M1,X2,Y2,M2).
update([(X1,Y1)|M1],X2,Y2,[(X1,Y1)|M2]) :-
\+ X1 = X2,
update(M1,X2,Y2,M2).


0 comments on commit cadb00e

Please sign in to comment.