aboutsummaryrefslogtreecommitdiff
path: root/source/app.d
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-14 23:21:51 +0200
committerAdrian Kummerlaender2017-04-14 23:21:51 +0200
commitc6d2b259a4f253403929f6f1104395a6a71b1be6 (patch)
tree6d4cdfa4ab50fbe0fa982db601d772c67e4dda20 /source/app.d
parent963ace2e5ba0337130e5f343d7ab97a30b4547ae (diff)
downloadslang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar
slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.gz
slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.bz2
slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.lz
slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.xz
slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.tar.zst
slang-c6d2b259a4f253403929f6f1104395a6a71b1be6.zip
Convert structure to _dub_ build system
Diffstat (limited to 'source/app.d')
-rw-r--r--source/app.d57
1 files changed, 57 insertions, 0 deletions
diff --git a/source/app.d b/source/app.d
new file mode 100644
index 0000000..7d25f7f
--- /dev/null
+++ b/source/app.d
@@ -0,0 +1,57 @@
+import std.stdio;
+import std.string;
+import std.variant;
+
+import std.container.util : make;
+
+import base.stack;
+
+import definition = base.definition;
+import primitives = primitives.eval;
+
+Stack!Token resolve(Token token) {
+ try {
+ if ( primitives.evaluate(token) ) {
+ return primitives.result;
+ } else {
+ return token.visit!(
+ (int value) => Stack!Token(Token(value)),
+ (bool value) => Stack!Token(Token(value)),
+ (string word ) => definition.get(word)
+ );
+ }
+ }
+ catch (Exception ex) {
+ writeln("Error: ", ex.msg);
+ return Stack!Token();
+ }
+}
+
+void process(string value) {
+ auto buffer = make!(Stack!Token)(toToken(value));
+
+ do {
+ Token current = buffer.pop;
+
+ if ( !definition.handle(current) ) {
+ Stack!Token resolved = resolve(current);
+
+ if ( !resolved.empty ) {
+ if ( resolved.front == current ) {
+ stack.push(current);
+ } else {
+ buffer.insertFront(resolved[]);
+ }
+ }
+ }
+ }
+ while ( !buffer.empty );
+}
+
+void main() {
+ while ( !stdin.eof ) {
+ foreach ( token; stdin.readln.split ) {
+ process(token);
+ }
+ }
+}