Execute HQ9+: Difference between revisions

Content added Content deleted
Line 302: Line 302:
-export([main/1]).
-export([main/1]).


%% bottle helper routine
hello() ->
io:format("Hello world!~n", []).

prog(Prog) ->
io:format("~s~n", [Prog]).

bottle(0) ->
bottle(0) ->
io:format("No more bottles of beer ");
io:format("No more bottles of beer ");
Line 316: Line 311:
bottle(N) when N > 0 ->
bottle(N) when N > 0 ->
io:format("~w bottles of beer ", [N]).
io:format("~w bottles of beer ", [N]).

%% Implementation of instructions
beer(0) ->
beer(0) ->
bottle(0), io:format("on the wall~n"),
bottle(0), io:format("on the wall~n"),
Line 327: Line 323:
bottle(N-1), io:format("on the wall~n~n"),
bottle(N-1), io:format("on the wall~n~n"),
beer(N-1).
beer(N-1).

hello() ->
io:format("Hello world!~n", []).

prog(Prog) ->
io:format("~s~n", [Prog]).


inc(Acc) ->
inc(Acc) ->
Acc+1.
Acc+1.

%% Interpreter
execute(Instruction, Prog, Acc) ->
execute(Instruction, Prog, Acc) ->
case Instruction of
case Instruction of