mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
[poincare] Fix parser
This commit is contained in:
@@ -105,6 +105,23 @@
|
||||
#include <poincare/vertical_offset_layout_node.h>
|
||||
#else
|
||||
|
||||
#include <poincare/addition.h>
|
||||
#include <poincare/matrix_complex.h>
|
||||
#include <poincare/multiplication.h>
|
||||
#include <poincare/power.h>
|
||||
#include <poincare/subtraction.h>
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/infinity.h>
|
||||
#include <poincare/integer.h>
|
||||
#include <poincare/opposite.h>
|
||||
#include <poincare/decimal.h>
|
||||
#include <poincare/rational.h>
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/float.h>
|
||||
#include <poincare/parenthesis.h>
|
||||
#include <poincare/division.h>
|
||||
#include <poincare/undefined.h>
|
||||
|
||||
#include <poincare/print_float.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -74,7 +74,10 @@ class Addition : public NAryExpression {
|
||||
public:
|
||||
Addition(const AdditionNode * n) : NAryExpression(n) {}
|
||||
Addition() : NAryExpression(TreePool::sharedPool()->createTreeNode<AdditionNode>()) {}
|
||||
|
||||
Addition(Expression e1, Expression e2) : Addition() {
|
||||
addChildAtIndexInPlace(e2, 0, 0);
|
||||
addChildAtIndexInPlace(e1, 0, numberOfChildren());
|
||||
}
|
||||
// Expression
|
||||
Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
X3,
|
||||
Y3 = 29
|
||||
};
|
||||
Symbol(const char name) : Expression(TreePool::sharedPool()->createTreeNode<SymbolNode>()) {
|
||||
Symbol(const char name = 0) : Expression(TreePool::sharedPool()->createTreeNode<SymbolNode>()) {
|
||||
node()->setName(name);
|
||||
}
|
||||
Symbol(const SymbolNode * node) : Expression(node) {}
|
||||
|
||||
@@ -105,10 +105,13 @@ X2 { poincare_expression_yylval.character = Symbol::SpecialSymbols::X2; return S
|
||||
Y2 { poincare_expression_yylval.character = Symbol::SpecialSymbols::Y2; return SYMBOL; }
|
||||
X3 { poincare_expression_yylval.character = Symbol::SpecialSymbols::X3; return SYMBOL; }
|
||||
Y3 { poincare_expression_yylval.character = Symbol::SpecialSymbols::Y3; return SYMBOL; }
|
||||
/*
|
||||
acos { poincare_expression_yylval.expression = new ArcCosine(); return FUNCTION; }
|
||||
acosh { poincare_expression_yylval.expression = new HyperbolicArcCosine(); return FUNCTION; }
|
||||
abs { poincare_expression_yylval.expression = new AbsoluteValue(); return FUNCTION; }
|
||||
*/
|
||||
ans { poincare_expression_yylval.character = Symbol::SpecialSymbols::Ans; return SYMBOL; }
|
||||
/*
|
||||
arg { poincare_expression_yylval.expression = new ComplexArgument(); return FUNCTION; }
|
||||
asin { poincare_expression_yylval.expression = new ArcSine(); return FUNCTION; }
|
||||
asinh { poincare_expression_yylval.expression = new HyperbolicArcSine(); return FUNCTION; }
|
||||
@@ -151,11 +154,12 @@ tan { poincare_expression_yylval.expression = new Tangent(); return FUNCTION; }
|
||||
tanh { poincare_expression_yylval.expression = new HyperbolicTangent(); return FUNCTION; }
|
||||
trace { poincare_expression_yylval.expression = new MatrixTrace(); return FUNCTION; }
|
||||
transpose { poincare_expression_yylval.expression = new MatrixTranspose(); return FUNCTION; }
|
||||
undef { poincare_expression_yylval.expression = new Undefined(); return UNDEFINED; }
|
||||
inf { poincare_expression_yylval.expression = new Undefined(); return UNDEFINED; }
|
||||
*/
|
||||
undef { poincare_expression_yylval.expression = Undefined(); return UNDEFINED; }
|
||||
inf { poincare_expression_yylval.expression = Undefined(); return UNDEFINED; }
|
||||
\x8a { poincare_expression_yylval.character = yytext[0]; return SYMBOL; }
|
||||
\x8d { return EE; }
|
||||
\x91 { poincare_expression_yylval.expression = new SquareRoot(); return FUNCTION; }
|
||||
/*\x91 { poincare_expression_yylval.expression = new SquareRoot(); return FUNCTION; }*/
|
||||
\x8c { poincare_expression_yylval.character = yytext[0]; return SYMBOL; }
|
||||
\x8f { poincare_expression_yylval.character = yytext[0]; return SYMBOL; }
|
||||
\x90 { return STO; }
|
||||
@@ -177,7 +181,10 @@ inf { poincare_expression_yylval.expression = new Undefined(); return UNDEFINED;
|
||||
\, { return COMMA; }
|
||||
\. { return DOT; }
|
||||
\_ { return UNDERSCORE; }
|
||||
/*
|
||||
\x97 { poincare_expression_yylval.expression = new EmptyExpression(); return EMPTY; }
|
||||
*/
|
||||
|
||||
[ ]+ /* Ignore whitespaces */
|
||||
. { return UNDEFINED_SYMBOL; }
|
||||
|
||||
|
||||
@@ -7,6 +7,18 @@
|
||||
|
||||
%{
|
||||
#include <poincare.h>
|
||||
|
||||
struct YYSTYPE {
|
||||
Poincare::Expression expression;
|
||||
Poincare::Symbol symbol;
|
||||
struct {
|
||||
char * address;
|
||||
int length;
|
||||
} string;
|
||||
char character;
|
||||
};
|
||||
|
||||
|
||||
/* The lexer manipulates tokens defined by the parser, so we need the following
|
||||
* inclusion order. */
|
||||
#include "expression_parser.hpp"
|
||||
@@ -20,8 +32,9 @@ void poincare_expression_yyerror(Poincare::Expression * expressionOutput, char c
|
||||
* instead we do provide regular memcpy. Let's instruct Bison to use it. */
|
||||
#define YYCOPY(To, From, Count) memcpy(To, From, (Count)*sizeof(*(From)))
|
||||
|
||||
%}
|
||||
|
||||
#if 0
|
||||
//TODO move comments
|
||||
|
||||
/* All symbols (both terminals and non-terminals) may have a value associated
|
||||
* with them. In our case, it's going to be either an Expression (for example,
|
||||
@@ -48,6 +61,10 @@ void poincare_expression_yyerror(Poincare::Expression * expressionOutput, char c
|
||||
} string;
|
||||
char character;
|
||||
}
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
|
||||
/* The INTEGER token uses the "string" part of the union to store its value */
|
||||
%token <string> DIGITS
|
||||
@@ -129,9 +146,9 @@ void poincare_expression_yyerror(Poincare::Expression * expressionOutput, char c
|
||||
%type <expression> exp;
|
||||
%type <expression> number;
|
||||
%type <symbol> symb;
|
||||
%type <listData> lstData;
|
||||
/* TODO %type <listData> lstData; */
|
||||
/* MATRICES_ARE_DEFINED */
|
||||
%type <matrixData> mtxData;
|
||||
/* TODO %type <matrixData> mtxData; */
|
||||
|
||||
/* FIXME: no destructors, Expressions are GCed */
|
||||
/* During error recovery, some symbols need to be discarded. We need to tell
|
||||
@@ -180,7 +197,7 @@ mtxData: LEFT_BRACKET lstData RIGHT_BRACKET { $$ = new Poincare::MatrixData($2,
|
||||
* of the exponent digits is above 4 (0.00...-256 times-...01E1256=1E1000 is
|
||||
* accepted and 1000-...256times...-0E10000 = 1E10256, 10256 does not overflow
|
||||
* an int32_t). */
|
||||
number : DIGITS { $$ = Poincare::Rational(Poincare::Integer($1.address, false)); }
|
||||
number : DIGITS { $$ = Poincare::Rational(Poincare::Integer($1.address, $1.length, false)); }
|
||||
|
||||
/*
|
||||
| DOT DIGITS { $$ = Poincare::Decimal(Poincare::Decimal::mantissa(nullptr, 0, $2.address, $2.length, false), Poincare::Decimal::exponent(nullptr, 0, $2.address, $2.length, nullptr, 0, false)); }
|
||||
@@ -220,7 +237,7 @@ $4->detachOperands(); delete $4; $7->detachOperands(); delete $7; arguments->det
|
||||
;
|
||||
|
||||
bang : term { $$ = $1; }
|
||||
| term BANG { $$ = Poincare::Factorial($1); }
|
||||
/* | term BANG { $$ = Poincare::Factorial($1); }*/
|
||||
;
|
||||
|
||||
factor : bang { $$ = $1; }
|
||||
@@ -237,7 +254,7 @@ exp : pow { $$ = $1; }
|
||||
| exp MULTIPLY exp { $$ = Poincare::Multiplication($1,$3); }
|
||||
| exp MINUS exp { $$ = Poincare::Subtraction($1,$3); }
|
||||
| MINUS exp %prec UNARY_MINUS { $$ = Poincare::Opposite($2); }
|
||||
| exp PLUS exp { $$ = Poincare::Addition($1;$3); }
|
||||
| exp PLUS exp { $$ = Poincare::Addition($1,$3); }
|
||||
;
|
||||
|
||||
final_exp : exp { $$ = $1; }
|
||||
|
||||
Reference in New Issue
Block a user