1 using System;
 2 using Calculator;
 3 
 4 // ====================================================================
 5 //
 6 //  Desk Calculator
 7 //  ---------------
 8 //
 9 //  Author: S. Laakko
10 //
11 //  COMMANDS:
12 //
13 //      print           - print current values of variables
14 //      <var> = <expr>  - evaluate <expr> and assign its value to <var>
15 //      <expr>          - evaluate <expr> and print its value
16 //
17 //  SYNTAX:
18 //
19 //      <expr>          ::= <term> (('+' | '-') <term>)*
20 //      <term>          ::= <factor> (('*' | '/') <factor>)*
21 //      <factor>        ::= ('+' | '-')? <primary>
22 //      <primary>       ::= <number> | <var> | '(' <expr> ')'
23 //      <number>        ::= DIGIT+ ('.' DIGIT+)?
24 //      <var>           ::= IDENTIFIER
25 //
26 // ====================================================================
27 
28 int main()
29 {
30     Console.WriteLine("desk calculator");
31 #if (WINDOWS)
32     Console.WriteLine("enter command, or CTRL-Z to end:");
33 #else
34     Console.WriteLine("enter command, or CTRL-D to end:");
35 #endif
36     Console.Write("> ");
37     auto lineResult = Console.ReadLine();
38     if (lineResult.Error())
39     {
40         Console.Out() << lineResult.GetErrorMessage() << endl();
41     }
42     else
43     {
44         string line = lineResult.Value();
45         while (!Console.In().EndOfStream())
46         {
47             auto utf32Result = ToUtf32(line);
48             if (utf32Result.Error())
49             {
50                 Console.Out() << utf32Result.GetErrorMessage() << endl();
51             }
52             else
53             {
54                 auto result = Parse(utf32Result.Value());
55                 if (result.Error())
56                 {
57                     Console.Out() << result.GetErrorMessage() << endl();
58                 }
59             }
60             Console.Write("> ");
61             lineResult = Console.ReadLine();
62             if (lineResult.Error())
63             {
64                 Console.Out() << lineResult.GetErrorMessage() << endl();
65             }
66             else
67             {
68                 line = lineResult.Value();
69             }
70         }
71     }
72     Console.WriteLine("bye!");
73     return 0;
74 }