2006-06-08 02:05:03 +04:00
|
|
|
/*
|
2009-06-28 21:10:40 +04:00
|
|
|
* Copyright 2006-2009 Haiku, Inc. All Rights Reserved.
|
2006-06-08 02:05:03 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
|
|
|
|
* Stephan Aßmus <superstippi@gmx.de>
|
|
|
|
*/
|
|
|
|
#ifndef EXPRESSION_PARSER_H
|
|
|
|
#define EXPRESSION_PARSER_H
|
|
|
|
|
2008-11-04 23:47:41 +03:00
|
|
|
|
2006-06-08 02:05:03 +04:00
|
|
|
#include <String.h>
|
|
|
|
|
2008-11-04 23:47:41 +03:00
|
|
|
|
2006-06-08 02:05:03 +04:00
|
|
|
class Tokenizer;
|
|
|
|
|
|
|
|
class ParseException {
|
|
|
|
public:
|
|
|
|
ParseException(const char* message, int32 position)
|
|
|
|
: message(message),
|
|
|
|
position(position)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ParseException(const ParseException& other)
|
|
|
|
: message(other.message),
|
|
|
|
position(other.position)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BString message;
|
|
|
|
int32 position;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Function;
|
|
|
|
struct Token;
|
2008-11-04 23:47:41 +03:00
|
|
|
class MAPM;
|
2006-06-08 02:05:03 +04:00
|
|
|
|
|
|
|
class ExpressionParser {
|
|
|
|
public:
|
|
|
|
ExpressionParser();
|
|
|
|
~ExpressionParser();
|
|
|
|
|
2009-06-28 21:10:40 +04:00
|
|
|
void SetSupportHexInput(bool enabled);
|
|
|
|
|
2008-11-04 23:47:41 +03:00
|
|
|
BString Evaluate(const char* expressionString);
|
2009-06-28 21:10:40 +04:00
|
|
|
int64 EvaluateToInt64(const char* expressionString);
|
|
|
|
double EvaluateToDouble(const char* expressionString);
|
2006-06-08 02:05:03 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2008-11-04 23:47:41 +03:00
|
|
|
MAPM _ParseBinary();
|
|
|
|
MAPM _ParseSum();
|
|
|
|
MAPM _ParseProduct();
|
|
|
|
MAPM _ParsePower();
|
|
|
|
MAPM _ParseUnary();
|
|
|
|
void _InitArguments(MAPM values[],
|
|
|
|
int32 argumentCount);
|
|
|
|
MAPM _ParseFunction(const Token& token);
|
|
|
|
MAPM _ParseAtom();
|
2011-08-26 14:31:29 +04:00
|
|
|
MAPM _ParseFactorial(MAPM value);
|
2006-06-08 02:05:03 +04:00
|
|
|
|
|
|
|
void _EatToken(int32 type);
|
|
|
|
|
|
|
|
Tokenizer* fTokenizer;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EXPRESSION_PARSER_H
|