1 /* 2 * Copyright 2006 Haiku, Inc. All Rights Reserved. 3 * Copyright 1997, 1998 R3 Software Ltd. All Rights Reserved. 4 * Distributed under the terms of the MIT License. 5 * 6 * Authors: 7 * Timothy Wayper <timmy@wunderbear.com> 8 * Stephan Aßmus <superstippi@gmx.de> 9 */ 10 11 #include <stdio.h> 12 13 #include "CalcApplication.h" 14 #include "ExpressionParser.h" 15 16 int 17 main(int argc, char* argv[]) 18 { 19 if (argc == 1) { 20 // run GUI 21 CalcApplication* app = new CalcApplication(); 22 23 app->Run(); 24 delete app; 25 } else { 26 // evaluate expression from command line 27 BString expression; 28 int32 i = 1; 29 while (i < argc) { 30 expression << argv[i]; 31 i++; 32 } 33 34 try { 35 ExpressionParser parser; 36 printf("%f\n", parser.Evaluate(expression.String())); 37 } catch (ParseException e) { 38 printf("%s at %ld\n", e.message.String(), e.position + 1); 39 return 1; 40 } 41 } 42 43 return 0; 44 } 45