Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81281 / brainfsckInterpreter / interpreterMain.pl
diff options
context:
space:
mode:
Commit5288b0429fcdac891be3bced8e21787bd452d44a (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-27 22:31:13 +0200
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-27 22:31:13 +0200
Filesb2fa00659b2ba23a5750300967197c39c42299dd /homework/81281/brainfsckInterpreter/interpreterMain.pl
IPL-5288b0429fcdac891be3bced8e21787bd452d44a.tar
IPL-5288b0429fcdac891be3bced8e21787bd452d44a.tar.gz
IPL-5288b0429fcdac891be3bced8e21787bd452d44a.zip
Parent94ea551501a130b45a795c372d49a8aede276950 (diff)
Fixed cloning the repo on Windows
1 files changed, 35 insertions, 0 deletions
-rw-r--r--homework/81281/brainfsckInterpreter/interpreterMain.pl35
diff --git a/homework/81281/brainfsckInterpreter/interpreterMain.pl b/homework/81281/brainfsckInterpreter/interpreterMain.pl
new file mode 100644
index 0000000..ff51f34
--- /dev/null
+++ b/homework/81281/brainfsckInterpreter/interpreterMain.pl
@@ -0,0 +1,35 @@
+:- use_module(library(dcg/basics)).
+:- use_module(library(readutil)).
+:- use_module(library(quintus)).
+:- [brainySource].
+
+:- set_prolog_flag(verbose, silent).
+:- initialization(main, main).
+
+main:-
+ current_prolog_flag(argv, Argv),
+ Argv = [H1|_],
+ atom_string(H1, Filename),
+ ((Filename == "", readyToReadAndInterpret("Hello, how can I help you?\nExit me by typing \"quit\"."));
+ (Filename \= "", readyToReadAndInterpret("Ready to interpret your file.\n", Filename))),
+ halt.
+main:-
+ halt(1).
+
+readyToReadAndInterpret(Message):-
+ write(Message),
+ startCycleTillQuit.
+
+readyToReadAndInterpret(Message, File):-
+ write(Message),
+ open(File, read, RFile),
+ read_stream_to_codes(RFile, BFSource),
+ close(RFile),
+ interpret(BFSource).
+
+startCycleTillQuit:-
+ nl,
+ current_stream(0, read, Stream),
+ read_line_to_codes(Stream, BFProgram),
+ ((string_codes("quit", BFProgram), write("Bye!"), nl);
+ (interpret(BFProgram), startCycleTillQuit)).