1 using System;
2 using BigNumCalc;
3
4 int main()
5 {
6 try
7 {
8 Console.WriteLine("Bignum calculator.");
9 #if (WINDOWS)
10 Console.WriteLine("Enter expression, or CTRL-Z to end.");
11 #else
12 Console.WriteLine("Enter expression, or CTRL-D to end.");
13 #endif
14 Console.Out() << "The expression can contain multiprecision integers, rationals using syntax [numerator/denominator], floating point numbers, " <<
15 "arithmetic operators +, -, * and /, and parenthesized subexpressions." << endl();
16 Console.Write("> ");
17 string line = Console.ReadLine();
18 while (!Console.In().EndOfStream())
19 {
20 EvaluationStack stack;
21 try
22 {
23 ustring s = ToUtf32(line);
24 BigNumLexer lexer(s, "", 0);
25 BigNumExpressionParser.Parse(lexer, &stack);
26 UniquePtr<BigValue> result = stack.Pop();
27 Console.Out() << "= " << result->ToString() << endl();
28 }
29 catch (const Exception& ex)
30 {
31 Console.Out() << ex.Message() << endl();
32 }
33 Console.Write("> ");
34 line = Console.ReadLine();
35 }
36 }
37 catch (const Exception& ex)
38 {
39 Console.Error() << ex.ToString() << endl();
40 return 1;
41 }
42 return 0;
43 }