diff options
Diffstat (limited to 'source/app.d')
-rw-r--r-- | source/app.d | 50 |
1 files changed, 4 insertions, 46 deletions
diff --git a/source/app.d b/source/app.d index 35b2d88..4e7b546 100644 --- a/source/app.d +++ b/source/app.d @@ -1,54 +1,12 @@ -import std.stdio; -import std.string; -import std.variant; +import std.string : split; +import std.stdio : stdin, readln, writeln; -import std.container.util : make; - -import base.stack; - -import definition = base.definition; -import primitives = primitives.eval; - -Stack!Token evaluate(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; - Stack!Token result = evaluate(current); - - if ( !result.empty ) { - if ( result.front == current ) { - stack.push(current); - } else { - buffer.push(result); - } - } - } - while ( !buffer.empty ); -} +static import machine; void main() { while ( !stdin.eof ) { foreach ( token; stdin.readln.split ) { - process(token); + machine.process(token); } } } |