mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Parse Pi
Change-Id: I7dbfa92d1c7aaf1c9d479fd1b907c444b292097e
This commit is contained in:
@@ -30,7 +30,7 @@ static constexpr EventData s_dataForEvent[] = {
|
||||
TL(), TL(), U(), U(), U(), U(),
|
||||
TL(), TL(), TL(), TL(), TL(), TL(),
|
||||
T("exp()"), T("ln()"), T("log()"), T("i"), T(","), T("^"),
|
||||
T("sin()"), T("cos()"), T("tan()"), T("p"), T("sqrt()"), T("^2"),
|
||||
T("sin()"), T("cos()"), T("tan()"), T("Pi"), T("sqrt()"), T("^2"),
|
||||
T("7"), T("8"), T("9"), T("("), T(")"), U(),
|
||||
T("4"), T("5"), T("6"), T("*"), T("/"), U(),
|
||||
T("1"), T("2"), T("3"), T("+"), T("-"), U(),
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
private:
|
||||
int symbolIndex(const Symbol * symbol) const;
|
||||
Expression * m_expressions[k_maxNumberOfScalarExpressions];
|
||||
Float m_pi;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
class Symbol : public LeafExpression {
|
||||
public:
|
||||
enum SpecialSymbols : char {
|
||||
Ans = '^'
|
||||
Ans = '^',
|
||||
Pi = '*'
|
||||
};
|
||||
Symbol(char name);
|
||||
ExpressionLayout * createLayout() const override;
|
||||
|
||||
@@ -81,7 +81,7 @@ E { return EE; }
|
||||
[A-Zxnt] { poincare_expression_yylval.character = yytext[0]; return SYMBOL; }
|
||||
abs { poincare_expression_yylval.expression = new AbsoluteValue(); return FUNCTION; }
|
||||
diff { poincare_expression_yylval.expression = new Derivative(); return FUNCTION; }
|
||||
ans { poincare_expression_yylval.character = Symbol::Ans; return SYMBOL; }
|
||||
ans { poincare_expression_yylval.character = Symbol::SpecialSymbols::Ans; return SYMBOL; }
|
||||
exp { poincare_expression_yylval.expression = new Exponential(); return FUNCTION; }
|
||||
sin { poincare_expression_yylval.expression = new Sine(); return FUNCTION; }
|
||||
cos { poincare_expression_yylval.expression = new Cosine(); return FUNCTION; }
|
||||
@@ -91,6 +91,7 @@ log { poincare_expression_yylval.expression = new Logarithm(); return FUNCTION;
|
||||
root { poincare_expression_yylval.expression = new NthRoot(); return FUNCTION; }
|
||||
sum { poincare_expression_yylval.expression = new Sum(); return FUNCTION; }
|
||||
product { poincare_expression_yylval.expression = new Product(); return FUNCTION; }
|
||||
Pi { poincare_expression_yylval.character = Symbol::SpecialSymbols::Pi; return SYMBOL; }
|
||||
\+ { return PLUS; }
|
||||
\- { return MINUS; }
|
||||
\* { return MULTIPLY; }
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <poincare/global_context.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
GlobalContext::GlobalContext()
|
||||
GlobalContext::GlobalContext() :
|
||||
m_pi(Float(M_PI))
|
||||
{
|
||||
for (int i = 0; i < k_maxNumberOfScalarExpressions; i++) {
|
||||
m_expressions[i] = nullptr;
|
||||
@@ -19,6 +21,9 @@ int GlobalContext::symbolIndex(const Symbol * symbol) const {
|
||||
}
|
||||
|
||||
const Expression * GlobalContext::expressionForSymbol(const Symbol * symbol) {
|
||||
if (symbol->name() == Symbol::SpecialSymbols::Pi) {
|
||||
return &m_pi;
|
||||
}
|
||||
int index = symbolIndex(symbol);
|
||||
if (index < 0 || index >= k_maxNumberOfScalarExpressions) {
|
||||
return nullptr;
|
||||
|
||||
@@ -35,6 +35,9 @@ ExpressionLayout * Symbol::createLayout() const {
|
||||
if (m_name == SpecialSymbols::Ans) {
|
||||
return new StringLayout("ans", 4);
|
||||
}
|
||||
if (m_name == SpecialSymbols::Pi) {
|
||||
return new StringLayout("Pi", 4);
|
||||
}
|
||||
return new StringLayout(&m_name, 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user