1 /* 2 * Copyright 2006-2009 Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <bonefish@cs.tu-berlin.de> 7 * Stephan Aßmus <superstippi@gmx.de> 8 */ 9 #ifndef EXPRESSION_PARSER_H 10 #define EXPRESSION_PARSER_H 11 12 13 #include <String.h> 14 15 16 class Tokenizer; 17 18 class ParseException { 19 public: 20 ParseException(const char* message, int32 position) 21 : message(message), 22 position(position) 23 { 24 } 25 26 ParseException(const ParseException& other) 27 : message(other.message), 28 position(other.position) 29 { 30 } 31 32 BString message; 33 int32 position; 34 }; 35 36 struct Function; 37 struct Token; 38 class MAPM; 39 40 class ExpressionParser { 41 public: 42 ExpressionParser(); 43 ~ExpressionParser(); 44 45 void SetSupportHexInput(bool enabled); 46 47 BString Evaluate(const char* expressionString); 48 int64 EvaluateToInt64(const char* expressionString); 49 double EvaluateToDouble(const char* expressionString); 50 51 private: 52 53 MAPM _ParseBinary(); 54 MAPM _ParseSum(); 55 MAPM _ParseProduct(); 56 MAPM _ParsePower(); 57 MAPM _ParseUnary(); 58 void _InitArguments(MAPM values[], 59 int32 argumentCount); 60 MAPM _ParseFunction(const Token& token); 61 MAPM _ParseAtom(); 62 63 void _EatToken(int32 type); 64 65 Tokenizer* fTokenizer; 66 }; 67 68 #endif // EXPRESSION_PARSER_H 69