[poincare] EmptyExpression now exist and can be parsed.

Change-Id: I226026fc866c556d9bf4f57c3622f71136dc841c
This commit is contained in:
Léa Saviot
2018-01-09 15:44:16 +01:00
parent 59c957b5fb
commit 5ec88dff8e
8 changed files with 68 additions and 2 deletions

View File

@@ -24,7 +24,8 @@ enum Charset : char {
GreaterEqual = (char)146,
MultiplicationSign = (char)147,
MiddleDot = (char)148,
AlmostEqual = (char)149
AlmostEqual = (char)149,
Empty = (char)150 // This char is used to be parsed into EmptyExpression.
};
}

View File

@@ -26,6 +26,7 @@ objs += $(addprefix poincare/src/,\
division_remainder.o\
division.o\
dynamic_hierarchy.o\
empty_expression.o\
expression_layout_cursor.o\
expression_lexer.o\
expression_parser.o\

View File

@@ -22,6 +22,7 @@
#include <poincare/division.h>
#include <poincare/division_quotient.h>
#include <poincare/division_remainder.h>
#include <poincare/empty_expression.h>
#include <poincare/expression.h>
#include <poincare/expression_layout.h>
#include <poincare/expression_layout_array.h>

View File

@@ -0,0 +1,29 @@
#ifndef POINCARE_EMPTY_EXPRESSION_H
#define POINCARE_EMPTY_EXPRESSION_H
#include <poincare/static_hierarchy.h>
#include <poincare/complex.h>
namespace Poincare {
/* An empty expression awaits completion by the user. */
class EmptyExpression : public StaticHierarchy<0> {
public:
Type type() const override {
return Type::EmptyExpression;
}
Expression * clone() const override;
int writeTextInBuffer(char * buffer, int bufferSize) const override;private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
/* Evaluation */
Expression * privateApproximate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
Expression * privateApproximate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
template<typename T> Complex<T> * templatedApproximate(Context& context, AngleUnit angleUnit) const;
};
}
#endif

View File

@@ -74,6 +74,7 @@ class Expression {
friend class Trigonometry;
friend class ApproximationEngine;
friend class SimplificationEngine;
friend class EmptyExpression;
public:
enum class Type : uint8_t {
@@ -136,6 +137,7 @@ public:
MatrixTranspose,
PredictionInterval,
SimplificationRoot,
EmptyExpression
};
enum class FloatDisplayMode {
Decimal = 0,

View File

@@ -0,0 +1,28 @@
#include <poincare/empty_expression.h>
#include <poincare/layout_engine.h>
#include <poincare/src/layout/empty_visible_layout.h>
#include <ion/charset.h>
extern "C" {
#include <math.h>
}
namespace Poincare {
Expression * EmptyExpression::clone() const {
return new EmptyExpression();
}
int EmptyExpression::writeTextInBuffer(char * buffer, int bufferSize) const {
return LayoutEngine::writeOneCharInBuffer(buffer, bufferSize, Ion::Charset::Empty);
}
ExpressionLayout * EmptyExpression::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
return new EmptyVisibleLayout();
}
template<typename T> Complex<T> * EmptyExpression::templatedApproximate(Context& context, AngleUnit angleUnit) const {
return new Complex<T>(Complex<T>::Float(NAN));
}
}

View File

@@ -156,6 +156,7 @@ inf { poincare_expression_yylval.expression = new Undefined(); return UNDEFINED;
\, { return COMMA; }
\. { return DOT; }
\_ { return UNDERSCORE; }
\x96 { poincare_expression_yylval.expression = new EmptyExpression(); return EMPTY; }
[ ]+ /* Ignore whitespaces */
. { return UNDEFINED_SYMBOL; }

View File

@@ -51,6 +51,7 @@ void poincare_expression_yyerror(Poincare::Expression ** expressionOutput, char
%token <character> SYMBOL
%token <function> FUNCTION
%token <expression> UNDEFINED
%token <expression> EMPTY
/* Operator tokens */
%token PLUS
@@ -114,6 +115,7 @@ void poincare_expression_yyerror(Poincare::Expression ** expressionOutput, char
%nonassoc ICOMPLEX
%nonassoc UNDEFINED
%nonassoc SYMBOL
%nonassoc EMPTY
/* The "exp" symbol uses the "expression" part of the union. */
%type <expression> final_exp;
@@ -129,7 +131,7 @@ void poincare_expression_yyerror(Poincare::Expression ** expressionOutput, char
* have some heap-allocated data that need to be discarded. */
%destructor { delete $$; } FUNCTION
%destructor { delete $$; } UNDEFINED final_exp exp number
%destructor { delete $$; } UNDEFINED final_exp exp number EMPTY
%destructor { delete $$; } lstData
/* MATRICES_ARE_DEFINED */
%destructor { delete $$; } mtxData
@@ -180,6 +182,7 @@ symb:
* "exp MINUS exp". */
exp:
UNDEFINED { $$ = $1; }
| EMPTY { $$ = $1; }
| exp BANG { $$ = new Poincare::Factorial($1, false); }
| number { $$ = $1; }
| symb { $$ = $1; }