mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
Merge changes Ic11846bc,Iaf6d678f
* changes: Updates the addition code to use attributes. Adds the power and parentheses to the parser.
This commit is contained in:
@@ -5,7 +5,7 @@ char charForKey[ION_NUMBER_OF_KEYS] = {
|
||||
'A', 'B', 'C', 'D', 'E',
|
||||
'F', 'G', 'H', 'I', 'J',
|
||||
'K', 'L', 'M', 'N', 'O',
|
||||
'7', '8', '9', 'S', 'T',
|
||||
'7', '8', '9', '(', ')',
|
||||
'4', '5', '6', '*', '/',
|
||||
'1', '2', '3', '+', '-',
|
||||
'0', '.', 'x', '7', 'X'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
SFLAGS += -Ipoincare/include
|
||||
objs += $(addprefix poincare/src/, addition.o context.o expression.o float.o integer.o fraction.o expression_lexer.o expression_parser.o product.o symbol.o)
|
||||
objs += $(addprefix poincare/src/, addition.o context.o expression.o float.o integer.o fraction.o expression_lexer.o expression_parser.o power.o product.o symbol.o)
|
||||
objs += $(addprefix poincare/src/layout/, expression_layout.o fraction_layout.o horizontal_layout.o string_layout.o)
|
||||
tests += $(addprefix poincare/test/, integer.cpp)
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ class Addition : public Expression {
|
||||
ExpressionLayout * createLayout(ExpressionLayout * parent) override;
|
||||
float approximate(Context& context) override;
|
||||
private:
|
||||
Expression * m_children[2];
|
||||
Expression * m_left;
|
||||
Expression * m_right;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
class Power : public Expression {
|
||||
public:
|
||||
Power(Expression * base, Expression * exponent);
|
||||
virtual Expression ** children();
|
||||
virtual float approximate();
|
||||
// protected:
|
||||
virtual void layout();
|
||||
~Power();
|
||||
ExpressionLayout * createLayout(ExpressionLayout * parent) override;
|
||||
float approximate(Context& context) override;
|
||||
private:
|
||||
Expression * m_children[3];
|
||||
Expression * m_base;
|
||||
Expression * m_exponent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
#include "layout/horizontal_layout.h"
|
||||
|
||||
Addition::Addition(Expression * first_operand, Expression * second_operand) {
|
||||
m_children[0] = first_operand;
|
||||
m_children[1] = second_operand;
|
||||
m_left = first_operand;
|
||||
m_right = second_operand;
|
||||
}
|
||||
|
||||
Addition::~Addition() {
|
||||
delete m_children[1];
|
||||
delete m_children[0];
|
||||
delete m_left;
|
||||
delete m_right;
|
||||
}
|
||||
|
||||
float Addition::approximate(Context& context) {
|
||||
return m_children[0]->approximate(context) + m_children[1]->approximate(context);
|
||||
return m_left->approximate(context) + m_right->approximate(context);
|
||||
}
|
||||
|
||||
ExpressionLayout * Addition::createLayout(ExpressionLayout * parent) {
|
||||
return new HorizontalLayout(parent, m_children[0], '+', m_children[1]);
|
||||
return new HorizontalLayout(parent, m_left, '+', m_right);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@
|
||||
\* { return(MULTIPLY); }
|
||||
\^ { return(POW); }
|
||||
\+ { return(PLUS); }
|
||||
\( { return(LEFT_PARENTHESIS); }
|
||||
\) { return(RIGHT_PARENTHESIS); }
|
||||
[A-Za-z]+ { yylval->string = yytext; return(SYMBOL); }
|
||||
|
||||
%%
|
||||
|
||||
@@ -63,28 +63,12 @@ void poincare_expression_yyerror(yyscan_t scanner, Expression ** expressionOutpu
|
||||
%token POW
|
||||
%token PLUS
|
||||
|
||||
%token LEFT_PARENTHESIS
|
||||
%token RIGHT_PARENTHESIS
|
||||
|
||||
/* The "exp" symbol uses the "expression" part of the union. */
|
||||
%type <expression> exp;
|
||||
|
||||
/*
|
||||
//Expression * expression;
|
||||
//CSSSelector * selector;
|
||||
%union {
|
||||
int value;
|
||||
char * string;
|
||||
}
|
||||
|
||||
%token
|
||||
|
||||
%right <string> COMBINATOR
|
||||
%token <string> IDENT
|
||||
%token HASH
|
||||
%token DOT
|
||||
|
||||
%type <selector> Expression;
|
||||
*/
|
||||
|
||||
|
||||
%%
|
||||
|
||||
Root:
|
||||
@@ -98,66 +82,12 @@ exp:
|
||||
| exp DIVIDE exp { $$ = new Fraction($1,$3); }
|
||||
| exp MULTIPLY exp { $$ = new Product($1,$3); }
|
||||
| exp PLUS exp { $$ = new Addition($1,$3); }
|
||||
/* | exp POW exp { $$ = new Power($1,$3); } */
|
||||
| exp POW exp { $$ = new Power($1,$3); }
|
||||
| LEFT_PARENTHESIS exp RIGHT_PARENTHESIS { $$ = $2 }
|
||||
;
|
||||
|
||||
/*
|
||||
|
||||
Root:
|
||||
Selector {
|
||||
*selector = $1;
|
||||
//printf("ROOT! : %p\n", $1);
|
||||
}
|
||||
|
||||
Selector:
|
||||
{
|
||||
//$$ = new CSSSelector();
|
||||
//printf("New selector at %p\n", $$);
|
||||
}
|
||||
| IDENT {
|
||||
//$$ = new CSSSelector();
|
||||
//$$->setNameRequirement(*$1);
|
||||
//delete $1;
|
||||
//printf("Create NodeSpecWithName %s at %p\n", $1, $$);
|
||||
}
|
||||
| Selector DOT IDENT {
|
||||
//$1->addClassRequirement(*$3);
|
||||
//delete $3;
|
||||
//printf("AddClassToNodeSpec %s\n", $3);
|
||||
}
|
||||
| Selector HASH IDENT {
|
||||
//$1->setIdentifierRequirement(*$3);
|
||||
//delete $3;
|
||||
//printf("AddIdToNodeSpec : %s\n", $3);
|
||||
}
|
||||
| Selector COMBINATOR Selector {
|
||||
//$3->setParentSelectorWithCombinator($1, awe_css_combinator_from_string(*$2));
|
||||
//printf("Combine with \"%s\"\n", $2->c_str());
|
||||
//delete $2;
|
||||
}
|
||||
;
|
||||
|
||||
*/
|
||||
%%
|
||||
|
||||
void poincare_expression_yyerror(yyscan_t scanner, Expression ** expressionOutput, char const *msg) {
|
||||
// Handle the error!
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
CSSSelector::Combinator awe_css_combinator_from_string(std::string string) {
|
||||
for (char& c : string) {
|
||||
switch (c) {
|
||||
case '>':
|
||||
return CSSSelector::Combinator::DIRECT;
|
||||
}
|
||||
}
|
||||
return CSSSelector::Combinator::ANY;
|
||||
}
|
||||
|
||||
void awe_css_yyerror(yyscan_t scanner, CSSSelector ** selector, char const *msg) {
|
||||
printf("ERROR %s\n",msg);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ Integer Integer::add(const Integer &other, bool inverse_other_negative) const {
|
||||
if (m_negative == other_negative) {
|
||||
return usum(other, false, m_negative);
|
||||
} else {
|
||||
/* The signs are different, this is in fact a substraction
|
||||
/* The signs are different, this is in fact a subtraction
|
||||
* s = this+other = (abs(this)-abs(other) OR abs(other)-abs(this))
|
||||
* 1/abs(this)>abs(other) : s = sign*udiff(this, other)
|
||||
* 2/abs(other)>abs(this) : s = sign*udiff(other, this)
|
||||
|
||||
@@ -1,35 +1,21 @@
|
||||
#include <poincare/power.h>
|
||||
#include <string.h>
|
||||
#include "layout/horizontal_layout.h"
|
||||
|
||||
#define BASE m_children[0]
|
||||
#define EXPONENT m_children[1]
|
||||
|
||||
Power::Power(Expression * base, Expression * exponent) {
|
||||
m_children[0] = base;
|
||||
m_children[1] = exponent;
|
||||
m_children[2] = NULL;
|
||||
Power::Power(Expression * base, Expression * exponent) :
|
||||
m_base(base),
|
||||
m_exponent(exponent) {
|
||||
}
|
||||
|
||||
Expression ** Power::children() {
|
||||
return m_children;
|
||||
Power::~Power() {
|
||||
delete m_exponent;
|
||||
delete m_base;
|
||||
}
|
||||
|
||||
void Power::layout() {
|
||||
m_frame.width = BASE->m_frame.width + EXPONENT->m_frame.width;
|
||||
m_frame.height = BASE->m_frame.height + EXPONENT->m_frame.height;
|
||||
|
||||
BASE->m_frame.origin = {
|
||||
.x = 0,
|
||||
.y = EXPONENT->m_frame.height
|
||||
};
|
||||
|
||||
EXPONENT->m_frame.origin = {
|
||||
.x = BASE->m_frame.width,
|
||||
.y = 0
|
||||
};
|
||||
float Power::approximate(Context& context) {
|
||||
// TODO: do this for real
|
||||
return 1;
|
||||
}
|
||||
|
||||
float Power::approximate() {
|
||||
// TODO: Do it..
|
||||
return 1.0f;
|
||||
ExpressionLayout * Power::createLayout(ExpressionLayout * parent) {
|
||||
return new HorizontalLayout(parent, m_base, '^', m_exponent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user