%3.
palindrome --> [].
palindrome --> [_X].
palindrome --> [X], palindrome, [X].

%Note that the actual translation obtained may depend on your Prolog system. 
%The following predicate is called palindrome1 to avoid name collisions with the DCG defined above.
palindrome1(A, A).
palindrome1([_|A], A).
palindrome1([C|A], D) :-
	palindrome1(A, B),
	B=[C|D].

%4.
exp --> [begin], exp, [end].
exp --> [skip].
exp --> [if], b_exp, exp.
exp --> id, [':='], num.
b_exp --> id, [<], id.
b_exp --> id, [=], id.
id --> [id(X)], {atom(X)}.
num --> [val(N)], {number(N)}.

%The second part of this assignment is left as an exercise since it is similar to lab 3.

%5
%Parse parenthesis.  Recognize whether the argument is a list of left
%'(' and right parenthesis ')'  matching each other.

%A first attempt might look as follows. Note that only the two first rule doesn't work with, e.g., (()()).
paren1 --> [].
paren1 --> ['('], paren1, [')'].
paren1 --> paren1, paren1.

%But now the problem is that the resulting grammar is left-recursive. We can fix this as follows.

paren --> ['('], parens, [')'].

parens --> paren, parens.
parens --> [].


%6.

abc --> a(N),b(N),c(N).

a(0) --> [].
a(s(N)) --> [a], a(N).

b(0) --> [].
b(s(N)) --> [b], b(N).

c(0) --> [].
c(s(N)) --> [c], c(N).


