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:
|
|
|
|
* Stephan Aßmus <superstippi@gmx.de>
|
2012-08-03 19:16:23 +04:00
|
|
|
* John Scipione <jscipione@gmail.com>
|
|
|
|
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
|
2006-06-08 02:05:03 +04:00
|
|
|
*/
|
|
|
|
#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 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;
|
2008-11-04 23:47:41 +03:00
|
|
|
class MAPM;
|
2006-06-08 02:05:03 +04:00
|
|
|
|
|
|
|
class ExpressionParser {
|
2012-12-19 06:31:43 +04:00
|
|
|
|
2006-06-08 02:05:03 +04:00
|
|
|
public:
|
|
|
|
ExpressionParser();
|
|
|
|
~ExpressionParser();
|
|
|
|
|
2012-07-31 06:35:57 +04:00
|
|
|
bool DegreeMode();
|
|
|
|
void SetDegreeMode(bool degrees);
|
|
|
|
|
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
|
|
|
|
DeskCalc: make input Locale-aware
Accepts input with separators based on user's Locale. For example,
with a European locale, "1.234,56" is valid input. With a US locale,
"1,234.56" is accepted. The grouping separator is ignored and
removed, and the decimal separator is kept.
Supports multi-byte decimal separator and grouping separators.
The keypad localization is based on the user's Language setting,
but the separators come from the Formatting. Thus if the Language
is set to English, but the Formatting is set to, for example,
German, the keypad will show '.', but when pressed it will emit
',' to match the number Formatting. Otherwise the keypad breaks
the localized formatting.
Fixes #8503
Change-Id: I0d112bdca67a4e4898e37062102343194ed47f8f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4965
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2022-03-01 03:18:53 +03:00
|
|
|
status_t SetSeparators(BString decimal, BString group);
|
|
|
|
|
2012-12-19 06:31:43 +04:00
|
|
|
private:
|
|
|
|
struct Token;
|
|
|
|
class Tokenizer;
|
|
|
|
|
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;
|
2012-07-31 06:35:57 +04:00
|
|
|
|
|
|
|
bool fDegreeMode;
|
2006-06-08 02:05:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EXPRESSION_PARSER_H
|