[Poincare] Expression::parse

This commit is contained in:
Romain Goyet
2015-09-07 18:24:44 +02:00
parent 5bd47a7a98
commit a26ef6194f
3 changed files with 15 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ typedef void (Expression::*ExpressionAction)(void);
class Expression {
public:
static Expression * parse(char * string);
void recursiveDraw();
void recursiveLayout();
KDRect m_frame;

View File

@@ -4,7 +4,7 @@
int poincare_expression_yyparse(yyscan_t scanner, Expression ** expressionOutput);
void CreateFromString(char * string) {
Expression * Expression::parse(char * string) {
yyscan_t scanner;
YY_BUFFER_STATE buf;
poincare_expression_yylex_init(&scanner);
@@ -13,12 +13,16 @@ void CreateFromString(char * string) {
poincare_expression_yyparse(scanner, &expression);
expression->recursiveLayout();
expression->m_frame.origin = KDPOINT(0, 100);
expression->recursiveDraw();
poincare_expression_yy_delete_buffer(buf, scanner);
poincare_expression_yylex_destroy(scanner);
return expression;
}
bool Expression::identicalTo(Expression * e) {
// By default, two expression are not identical.
// This should obviously be overriden in subclasses!
return false;
}

View File

@@ -16,7 +16,11 @@ void hello() {
if (character == '.') {
input[index] = 0;
index = 0;
CreateFromString(input);
Expression * e = Expression::parse(input);
e->recursiveLayout();
e->m_frame.origin = KDPOINT(0, 100);
e->recursiveDraw();
//FIXME delete e;
} else {
if (index == 0) {
KDFillRect((KDRect){