From: hama Date: Sun, 20 Jul 2014 22:04:33 +0000 (+0200) Subject: dayly work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=baf3e0adb08743957a5b08761c2b16f81061355b;p=reqt dayly work --- diff --git a/rplexpr/rplasclasses.cpp b/rplexpr/rplasclasses.cpp index 246b241..2dc394e 100644 --- a/rplexpr/rplasclasses.cpp +++ b/rplexpr/rplasclasses.cpp @@ -147,8 +147,7 @@ void RplSymbolSpace::dump(FILE* fp, int indent, const char* header) var->dump(fp, indent); } fprintf(fp, "%s== Body:%s\n", tabs, m_body == NULL ? " " : ""); - if (m_body != NULL) - m_body->dump(fp, indent); + RplASNode1::dumpStatements(fp, indent, m_body); } /** diff --git a/rplexpr/rplastree.cpp b/rplexpr/rplastree.cpp index a496d41..5172b22 100644 --- a/rplexpr/rplastree.cpp +++ b/rplexpr/rplastree.cpp @@ -698,14 +698,13 @@ RplASNamedValue::RplASNamedValue(const QString& name) : /** * @brief Constructor. * - * @param itemType the node type, e.g. AST_VAR_DEFINITION * @param dataType the data type (class) * @param name the name of the variable * @param attributes the attributes of the variable */ -RplASNamedValue::RplASNamedValue(RplASItemType itemType, RplASClass* dataType, +RplASNamedValue::RplASNamedValue(RplASClass* dataType, const QString& name, int attributes) : - RplASNode1(itemType), + RplASNode1(AST_NAMED_VALUE), m_name(name), m_attributes(attributes), m_dataType(dataType) @@ -748,18 +747,17 @@ void RplASNamedValue::dump(FILE* fp, int indent) /** @class RplVarDefinition rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements variable definition for the Abstract Syntax Tree. + * + * m_child: next statement
+ * m_child2: named value (name + default value expression) + * m_child3: initial value or NULL */ /** * @brief Constructor. - * - * @param type the data type - * @param name the name of the variable - * @param attributes the attributes of the variable */ -RplASVarDefinition::RplASVarDefinition(RplASClass* type, const QString& name, - int attributes) : - RplASNamedValue(AST_VAR_DEFINITION, type, name, attributes), +RplASVarDefinition::RplASVarDefinition() : + RplASNode3(AST_VAR_DEFINITION), RplASStatement() { } @@ -773,17 +771,19 @@ RplASVarDefinition::RplASVarDefinition(RplASClass* type, const QString& name, void RplASVarDefinition::dump(FILE* fp, int indent) { DEFINE_TABS(indent); - QByteArray name = m_name.toUtf8(); - QByteArray className = m_dataType == NULL ? "?" : m_dataType->name().toUtf8(); + RplASNamedValue* namedValue = dynamic_cast(m_child2); + QByteArray name = namedValue->name().toUtf8(); char buffer[256]; - fprintf(fp, "%svarDef %s (%s) id: %d succ: %d attr: 0x%x %s\n", - tabs, name.constData(), className.constData(), - m_id, m_successor == NULL ? 0 : m_successor->id(), m_attributes, + fprintf(fp, "%svarDef %s id: %d namedValue: %d value: %d succ: %d %s\n", + tabs, name.constData(), m_id, + m_child2 == NULL ? 0 : m_child2->id(), + m_child3 == NULL ? 0 : m_child3->id(), + m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer)); - if (m_child != NULL) - m_child->dump(fp, indent + 1); - if (m_successor != NULL) - m_successor->dump(fp, indent); + if (m_child2 != NULL) + m_child2->dump(fp, indent + 1); + if (m_child3 != NULL) + m_child3->dump(fp, indent + 1); } /** @@ -805,14 +805,17 @@ void RplASVarDefinition::calc(RplASVariant&) /** @class RplASExprStatement rplastree.hpp "rplexpr/rplastree.hpp" * - * @brief Implements an statement consisting of an expression + * @brief Implements an statement consisting of an expression. + * + * m_child: next statement
+ * m_child2: expression */ /** * @brief Constructor. */ RplASExprStatement::RplASExprStatement() : - RplASNode1(AST_EXPR_STATEMENT), + RplASNode2(AST_EXPR_STATEMENT), RplASStatement() { } @@ -845,14 +848,12 @@ void RplASExprStatement::dump(FILE* fp, int indent) { DEFINE_TABS(indent); char buffer[256]; - fprintf(fp, "%sExpr id: %d succ: %d expr: %d %s\n", tabs, m_id, - m_successor == NULL ? 0 : m_successor->id(), + fprintf(fp, "%sExpr id: %d expr: %d succ: %d %s\n", tabs, m_id, + m_child2 == NULL ? 0 : m_child2->id(), m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer)); - if (m_child != NULL) - m_child->dump(fp, indent + 1); - if (m_successor != NULL) - m_successor->dump(fp, indent); + if (m_child2 != NULL) + m_child2->dump(fp, indent + 1); } /** @class RplASNode1 rplastree.hpp "rplexpr/rplastree.hpp" @@ -897,6 +898,22 @@ void RplASNode1::setChild(RplASItem* child) m_child = child; } +/** + * @brief Writes the internals of a statement list into a file. + * + * @param fp file to write + * @param indent the indent level of the statement list + * @param chain the chain of statements to dump + */ +void RplASNode1::dumpStatements(FILE* fp, int indent, RplASItem* statements) +{ + RplASNode1* chain = dynamic_cast(statements); + while (chain != NULL){ + chain->dump(fp, indent); + chain = dynamic_cast(chain->m_child); + } +} + /** @class RplASNode2 rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a inner node of the abstract syntax tree with two childs. @@ -1072,6 +1089,52 @@ void RplASNode5::setChild5(RplASItem* child5) m_child5 = child5; } +/** @class RplASNode6 rplastree.hpp "rplexpr/rplastree.hpp" + * + * @brief Implements a inner node of the abstract syntax tree with 4 childs. + * + * This class is an abstract class. + */ + +/** + * @brief RplASNode6::RplASNode6 + * @param type + */ +RplASNode6::RplASNode6(RplASItemType type) : + RplASNode5(type), + m_child6(NULL) +{ +} + +/** + * @brief Destructor. + */ +RplASNode6::~RplASNode6() +{ + delete m_child6; + m_child6 = NULL; +} + +/** + * @brief Returns the child5. + * + * @return the child 5 + */ +RplASItem* RplASNode6::child6() const +{ + return m_child6; +} + +/** + * @brief Sets the child5. + * + * @param child5 the new child3 + */ +void RplASNode6::setChild6(RplASItem* child6) +{ + m_child6 = child6; +} + /** @class RplASUnaryOp rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a unary operation. @@ -1108,60 +1171,33 @@ void RplASUnaryOp::dump(FILE* fp, int indent) { DEFINE_TABS(indent); char buffer[256]; - fprintf(fp, "%sUnary %d op: %s (%d) Child: %d %s\n", tabs, + fprintf(fp, "%sUnary %d op: %s (%d) expr: %d %s\n", tabs, m_id, RplLexer::m_active->nameOfOp(m_operator).constData(), m_operator, m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer) ); if (m_child != NULL) - m_child->dump(fp, indent); + m_child->dump(fp, indent + 1); } /** @class RplASStatement rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a base class for all statements. + * + * @note statements are always RplASNode1 and m_child is used + * for the successors (next statement). */ /** * @brief RplASStatement::RplASStatement * @param op */ -RplASStatement::RplASStatement() : - m_successor(NULL) +RplASStatement::RplASStatement() { } -/** - * @brief Destructor - */ -RplASStatement::~RplASStatement() -{ - delete m_successor; - m_successor = NULL; -} -/** - * @brief Returns the next statement. - * @return the next statement of a statement list - */ -RplASItem* RplASStatement::successor() const -{ - return m_successor; -} - -/** - * @brief Sets the next statement. - * - * @param successor the successor in the statement list - */ -void RplASStatement::setSuccessor(RplASItem* successor) -{ - m_successor = successor; -} - - - /** @class RplASCondition rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a condition. @@ -1238,37 +1274,38 @@ void RplASCondition::dump(FILE* fp, int indent) * The if statement has a condition, a then-part and an optional else-part. * If the condition is evaluated to true, the then-part will be executed. * Otherwise the else-part if it exists. + * + * m_child: next statement
+ * m_child2: condition
+ * m_child3: then part
+ * m_child4: else part or NULL
*/ RplASIf::RplASIf() : - RplASNode3(AST_IF) + RplASNode4(AST_IF) { } /** * @brief Executes the statement. * - * Meaning of the childs: - * m_child: condition - * m_child2: if-part - * m_child3: else-part */ void RplASIf::execute() { - RplASCondition* condition = dynamic_cast(m_child); + RplASCondition* condition = dynamic_cast(m_child2); if (condition == NULL) - throw RplASException(m_child == NULL ? m_position : m_child->position(), + throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), "if statement: not a condition"); RplASStatement* body = NULL; if(condition->calcAsBool()){ - body = dynamic_cast(m_child2); + body = dynamic_cast(m_child3); if (body == NULL) throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), "if statement: then-part is not a statement"); - } else if (m_child2 != NULL){ - body = dynamic_cast(m_child3); + } else if (m_child4 != NULL){ + body = dynamic_cast(m_child4); if (body == NULL) - throw RplASException(m_child3->position(), + throw RplASException(m_child4->position(), "if statement: else-part is not a statement"); } body->execute(); @@ -1284,14 +1321,18 @@ void RplASIf::dump(FILE* fp, int indent) { DEFINE_TABS(indent); char buffer[256]; - fprintf(fp, "%sIf id: %d condition: %d then: %d else: %d %s\n", tabs, - m_id, m_child->id(), m_child2->id(), + fprintf(fp, "%sIf id: %d condition: %d then: %d else: %d succ: %d%s\n", tabs, + m_id, + m_child2 == NULL ? 0 : m_child2->id(), m_child3 == NULL ? 0 : m_child3->id(), + m_child4 == NULL ? 0 : m_child4->id(), + m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer)); - m_child->dump(fp, indent + 1); m_child2->dump(fp, indent + 1); if (m_child3 != NULL) m_child3->dump(fp, indent + 1); + if (m_child4 != NULL) + m_child4->dump(fp, indent + 1); } /** @class RplASFor rplastree.hpp "rplexpr/rplastree.hpp" @@ -1303,6 +1344,11 @@ void RplASIf::dump(FILE* fp, int indent) * The initialization will be called first. * Then the condition will be tested. If true the body will be executed * and then the forwarding statement. + * + * m_child: next statement
+ * m_child2: body
+ * m_child3: iterator variable
+ * m_child4: container variable
*/ /** @@ -1311,7 +1357,7 @@ void RplASIf::dump(FILE* fp, int indent) * @param variable NULL or the iterator variable */ RplASForIterated::RplASForIterated(RplASNamedValue* variable) : - RplASNode3(AST_ITERATED_FOR), + RplASNode4(AST_ITERATED_FOR), RplASStatement() { m_child2 = variable; @@ -1320,11 +1366,6 @@ RplASForIterated::RplASForIterated(RplASNamedValue* variable) : /** * @brief Executes the statement. * - * Meaning of the childs: - * m_child: initialization - * m_child2: condition - * m_child3: forwarding statement - * m_child4: body */ void RplASForIterated::execute() { @@ -1340,18 +1381,18 @@ void RplASForIterated::dump(FILE* fp, int indent) { DEFINE_TABS(indent); char buffer[256]; - fprintf(fp, "%sforIt id: %d var: %d set: %d body: %d %s\n", tabs, + fprintf(fp, "%sforIt id: %d var: %d set: %d body: %d succ: %d %s\n", tabs, m_id, - m_child2 == NULL ? 0 : m_child2->id(), m_child3 == NULL ? 0 : m_child3->id(), + m_child4 == NULL ? 0 : m_child4->id(), + m_child2 == NULL ? 0 : m_child2->id(), m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer)); - if (m_child2 != NULL) - m_child2->dump(fp, indent + 1); if (m_child3 != NULL) m_child3->dump(fp, indent + 1); - if (m_child != NULL) - m_child->dump(fp, indent + 1); + if (m_child4 != NULL) + m_child4->dump(fp, indent + 1); + dumpStatements(fp, indent + 1, m_child2); } /** @class RplASForCounted rplastree.hpp "rplexpr/rplastree.hpp" @@ -1363,6 +1404,14 @@ void RplASForIterated::dump(FILE* fp, int indent) * * The start and end value will be calculated. * The body will be executed so many times given by the start and end value. + * + * m_child: next statement
+ * m_child2: body
+ * m_child3: variable or NULL
+ * m_child4: start value or NULL
+ * m_child5: end value
+ * m_child6: step value or NULL
+ * */ /** @@ -1371,34 +1420,28 @@ void RplASForIterated::dump(FILE* fp, int indent) * @param variable NULL or the counter variable */ RplASForCounted::RplASForCounted(RplASNamedValue* variable) : - RplASNode5(AST_ITERATED_FOR), + RplASNode6(AST_ITERATED_FOR), RplASStatement() { - m_child2 = variable; + m_child3 = variable; } /** * @brief Executes the statement. * - * Meaning of the childs: - * m_child: body - * m_child2: variable - * m_child3: start value - * m_child4: end value - * m_child5: step value */ void RplASForCounted::execute() { - RplASStatement* body = dynamic_cast(m_child); + RplASStatement* body = dynamic_cast(m_child2); if (body == NULL) - throw RplASException(m_child == NULL ? m_position : m_child->position(), + throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), "forc statement: body is not a statement"); int start = 1; int step = 1; int end = 0; RplASNamedValue* var = NULL; - if (m_child2 != NULL){ - var = dynamic_cast(m_child2); + if (m_child3 != NULL){ + var = dynamic_cast(m_child3); } for(int ii = start; ii <= end; ii += step){ body->execute(); @@ -1415,24 +1458,24 @@ void RplASForCounted::dump(FILE* fp, int indent) { DEFINE_TABS(indent); char buffer[256]; - fprintf(fp, "%sforc id: %d var: %d from: %d to: %d step: %d body: %d %s\n", + fprintf(fp, "%sforC id: %d var: %d from: %d to: %d step: %d body: %d succ: %d %s\n", tabs, m_id, - m_child2 == NULL ? 0 : m_child2->id(), m_child3 == NULL ? 0 : m_child3->id(), m_child4 == NULL ? 0 : m_child4->id(), m_child5 == NULL ? 0 : m_child5->id(), + m_child6 == NULL ? 0 : m_child6->id(), + m_child2 == NULL ? 0 : m_child2->id(), m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer)); - if (m_child2 != NULL) - m_child2->dump(fp, indent + 1); if (m_child3 != NULL) m_child3->dump(fp, indent + 1); if (m_child4 != NULL) m_child4->dump(fp, indent + 1); if (m_child5 != NULL) m_child5->dump(fp, indent + 1); - if (m_child != NULL) - m_child->dump(fp, indent + 1); + if (m_child6 != NULL) + m_child6->dump(fp, indent + 1); + dumpStatements(fp, indent + 1, m_child2); } /** @class RplASWhile rplastree.hpp "rplexpr/rplastree.hpp" @@ -1441,10 +1484,14 @@ void RplASForCounted::dump(FILE* fp, int indent) * * The while statement has an a condition and a body. * The body will be executed while the condition returns true. + * + * m_child: next statement
+ * m_child2: condition
+ * m_child3: body
*/ RplASWhile::RplASWhile() : - RplASNode2(AST_WHILE), + RplASNode3(AST_WHILE), RplASStatement() { } @@ -1453,14 +1500,12 @@ RplASWhile::RplASWhile() : * @brief Executes the statement. * * Meaning of the childs: - * m_child: body - * m_child2: condition */ void RplASWhile::execute() { - RplASStatement* body = dynamic_cast(m_child); + RplASStatement* body = dynamic_cast(m_child3); if (body == NULL) - throw RplASException(m_child == NULL ? m_position : m_child->position(), + throw RplASException(m_child3 == NULL ? m_position : m_child3->position(), "while statement: body is not a statement"); RplASCondition* condition = dynamic_cast(m_child2); if (condition == NULL) @@ -1481,14 +1526,14 @@ void RplASWhile::dump(FILE* fp, int indent) { DEFINE_TABS(indent); char buffer[256]; - fprintf(fp, "%swhile id: %d condition: %d body: %d %s\n", tabs, m_id, + fprintf(fp, "%swhile id: %d condition: %d body: %d succ: %d %s\n", tabs, m_id, m_child2 == NULL ? 0 : m_child2->id(), + m_child3 == NULL ? 0 : m_child3->id(), m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer)); if (m_child2 != NULL) m_child2->dump(fp, indent + 1); - if (m_child != NULL) - m_child->dump(fp, indent + 1); + dumpStatements(fp, indent + 1, m_child3); } /** @class RplASRepeat rplastree.hpp "rplexpr/rplastree.hpp" @@ -1497,10 +1542,14 @@ void RplASWhile::dump(FILE* fp, int indent) * * The while statement has an a condition and a body. * The body will be executed while the condition returns true. + * + * m_child: next statement
+ * m_child2: condition
+ * m_child3: body
*/ RplASRepeat::RplASRepeat() : - RplASNode2(AST_REPEAT), + RplASNode3(AST_REPEAT), RplASStatement() { } @@ -1514,14 +1563,14 @@ RplASRepeat::RplASRepeat() : */ void RplASRepeat::execute() { - RplASStatement* body = dynamic_cast(m_child); + RplASStatement* body = dynamic_cast(m_child3); if (body == NULL) - throw RplASException(m_child == NULL ? m_position : m_child->position(), - "while statement: body is not a statement"); + throw RplASException(m_child3 == NULL ? m_position : m_child3->position(), + "repeat statement: body is not a statement"); RplASCondition* condition = dynamic_cast(m_child2); if (condition == NULL) throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), - "for statement: not a condition"); + "repeat statement: not a condition"); do { body->execute(); } while(condition->calcAsBool()); @@ -1537,14 +1586,14 @@ void RplASRepeat::dump(FILE* fp, int indent) { DEFINE_TABS(indent); char buffer[256]; - fprintf(fp, "%srepeat id: %d condition: %d body: %d %s\n", tabs, m_id, + fprintf(fp, "%srepeat id: %d condition: %d body: %d succ: %d %s\n", tabs, m_id, m_child2 == NULL ? 0 : m_child2->id(), + m_child3 == NULL ? 0 : m_child3->id(), m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer)); - if (m_child != NULL) - m_child->dump(fp, indent + 1); if (m_child2 != NULL) m_child2->dump(fp, indent + 1); + dumpStatements(fp, indent + 1, m_child3); } /** @class RplASClass rplastree.hpp "rplexpr/rplastree.hpp" @@ -1801,6 +1850,13 @@ void RplASTree::dump(const char* filename, int flags, const char* header) } } +/** @class RplASMethodCall rplastree.hpp "rplexpr/rplastree.hpp" + * + * @brief Implements a method or function call for the Abstract Syntax Tree. + * + * m_child: next statement
+ * m_child2: argument list
+ */ /** * @brief Constructor. */ @@ -1826,7 +1882,7 @@ void RplASMethodCall::dump(FILE* fp, int indent) { DEFINE_TABS(indent); char buffer[256]; - fprintf(fp, "%sCall %d instance: %d args: %d %s\n", tabs, m_id, + fprintf(fp, "%scall %d instance: %d args: %d %s\n", tabs, m_id, m_child == NULL ? 0 : m_child->id(), m_child2 == NULL ? 0 : m_child2->id(), positionStr(buffer, sizeof buffer)); @@ -1867,6 +1923,13 @@ RplASArgument* RplASMethodCall::arg1() const return dynamic_cast(m_child2); } +/** @class RplASException rplastree.hpp "rplexpr/rplastree.hpp" + * + * @brief Implements a call of a method or function. + * + * m_child: ???
+ * m_child2: argument list (or NULL) + */ /** * @brief Sets the argument list. * @@ -1972,6 +2035,9 @@ void RplASMethod::dump(FILE* fp, int indent) /** @class RplASArgument rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an argument of a method for the Abstract Syntax Tree. + * + * m_child: next argument
+ * m_child2: expression */ /** * @brief constructor @@ -1981,4 +2047,35 @@ RplASArgument::RplASArgument() : { } +/** + * @brief Writes the internals of the instance into a file. + * + * @param fp target file + * @param no current number of the argument: 1..N + * @param indent nesting level + * @param tabs a string with tabs (count: indent) + */ +void RplASArgument::dumpOne(FILE* fp, int no, int indent, char tabs[]) +{ + int succ = child() == NULL ? 0 : child()->id(); + fprintf(fp, "%sArg %d id: %d expr: %d succ: %d\n", tabs, no, m_id, + child2()->id(), succ); + child2()->dump(fp, indent + 1); +} +/** + * @brief Writes the internals of the instance into a file. + * + * @param fp target file + * @param indent nesting level + */ +void RplASArgument::dump(FILE* fp, int indent) +{ + DEFINE_TABS(indent); + RplASArgument* current = this; + int no = 0; + do { + dumpOne(fp, ++no, indent, tabs); + current = static_cast(current->child()); + } while (this != NULL); +} diff --git a/rplexpr/rplastree.hpp b/rplexpr/rplastree.hpp index 776bf85..d19339f 100644 --- a/rplexpr/rplastree.hpp +++ b/rplexpr/rplastree.hpp @@ -177,6 +177,8 @@ public: public: RplASItem* child() const; void setChild(RplASItem* child); +public: + static void dumpStatements(FILE* fp, int indent, RplASItem* statements); protected: RplASItem* m_child; }; @@ -231,6 +233,18 @@ public: protected: RplASItem* m_child5; }; +class RplASNode6 : public RplASNode5 +{ +public: + RplASNode6(RplASItemType type); + virtual ~RplASNode6(); +public: + RplASItem*child6() const; + void setChild6(RplASItem* child5); +protected: + RplASItem* m_child6; +}; + typedef QList RplASListOfVariants; typedef QMap RplASMapOfVariants; @@ -278,7 +292,7 @@ public: public: RplASNamedValue(const QString& name); - RplASNamedValue(RplASItemType itemType, RplASClass* dataType, + RplASNamedValue(RplASClass* dataType, const QString& name, int attributes); public: QString name() const; @@ -295,28 +309,22 @@ class RplASStatement { public: RplASStatement(); - virtual ~RplASStatement(); public: virtual void execute() = 0; - RplASItem* successor() const; - void setSuccessor(RplASItem* successor); -protected: - RplASItem* m_successor; }; -class RplASVarDefinition : public RplASNamedValue, public RplASStatement +class RplASVarDefinition : public RplASNode3, public RplASStatement { public: - RplASVarDefinition(RplASClass* type, const QString& name, - int attributes = A_NONE); + RplASVarDefinition(); public: virtual void execute(); virtual void calc(RplASVariant& value); void dump(FILE* fp, int indent); }; -class RplASExprStatement : public RplASNode1, public RplASStatement +class RplASExprStatement : public RplASNode2, public RplASStatement { public: RplASExprStatement(); @@ -359,7 +367,7 @@ public: void dump(FILE* fp, int indent); }; -class RplASIf : public RplASNode3, public RplASStatement +class RplASIf : public RplASNode4, public RplASStatement { public: RplASIf(); @@ -368,7 +376,7 @@ public: virtual void dump(FILE* fp, int indent); }; -class RplASForIterated : public RplASNode3, public RplASStatement +class RplASForIterated : public RplASNode4, public RplASStatement { public: RplASForIterated(RplASNamedValue* variable); @@ -377,7 +385,7 @@ public: virtual void dump(FILE* fp, int indent); }; -class RplASForCounted : public RplASNode5, public RplASStatement +class RplASForCounted : public RplASNode6, public RplASStatement { public: RplASForCounted(RplASNamedValue* variable); @@ -386,7 +394,7 @@ public: virtual void dump(FILE* fp, int indent); }; -class RplASWhile : public RplASNode2, public RplASStatement +class RplASWhile : public RplASNode3, public RplASStatement { public: RplASWhile(); @@ -395,7 +403,7 @@ public: virtual void dump(FILE* fp, int indent); }; -class RplASRepeat : public RplASNode2, public RplASStatement +class RplASRepeat : public RplASNode3, public RplASStatement { public: RplASRepeat(); @@ -408,6 +416,10 @@ class RplASArgument : public RplASNode2 { public: RplASArgument(); +public: + void dump(FILE* fp, int indent); +protected: + void dumpOne(FILE* fp, int no, int indent, char tabs[]); }; class RplASMethod; @@ -428,8 +440,6 @@ public: void setArg1(RplASArgument* arg1); private: RplASMethod* m_method; - // body is child - // arg1 is child2 }; class RplParameter : RplASItem diff --git a/rplexpr/rplmfparser.cpp b/rplexpr/rplmfparser.cpp index 23239a8..3124b72 100644 --- a/rplexpr/rplmfparser.cpp +++ b/rplexpr/rplmfparser.cpp @@ -12,7 +12,7 @@ enum MFLocations{ L_PARSE_OPERAND_RPARENTH = 2001, - L_PARSE_OPERAND_RPARENTH_FUNC, + L_PARSE_FREE1, L_TERM_WRONG_STRING, L_TERM_WRONG_NUMBER, L_PARSE_OPERAND_WRONG = 2005, @@ -41,7 +41,8 @@ enum MFLocations{ L_PARSE_MAP_NO_COMMA, L_PARSE_OPERAND_NOT_OPERAND = 2030, L_PARSE_BODY_NO_START, - L_PARSE_OPERAND_NO_BRACKET + L_PARSE_OPERAND_NO_BRACKET, + L_PARSE_ARGS_NO_COMMA_OR_PARENT }; /** @class RplMFParser rpllexer.hpp "rplexpr/rplmfparser.hpp" @@ -82,14 +83,14 @@ RplASItem* RplMFParser::parseIf() RplASItem* condition = parseExpr(0); if (! m_lexer.currentToken()->isKeyword(K_THEN)) syntaxError(L_PARSE_IF_NO_THEN, "'then' expected"); - rc->setChild(condition); + rc->setChild2(condition); RplASItem* body = parseBody(K_ELSE, K_FI); - rc->setChild2(body); + rc->setChild3(body); if (! m_lexer.currentToken()->isKeyword(K_ELSE, K_FI)) syntaxError(L_PARSE_IF_NO_ELSE, "'else' or 'fi' expected"); if ( m_lexer.currentToken()->isKeyword(K_ELSE)){ RplASItem* body = parseBody(K_FI); - rc->setChild3(body); + rc->setChild4(body); } if (! m_lexer.currentToken()->isKeyword(K_FI)) syntaxError(L_PARSE_IF_NO_FI, "'fi' expected"); @@ -110,7 +111,7 @@ RplASItem* RplMFParser::parseWhile() syntaxError(L_PARSE_WHILE_NO_DO, "'do' expected"); rc->setChild2(condition); RplASItem* body = parseBody(K_OD); - rc->setChild(body); + rc->setChild3(body); if (! m_lexer.currentToken()->isKeyword(K_OD)) syntaxError(L_PARSE_WHILE_NO_OD, "'od' expected"); m_lexer.nextNonSpaceToken(); @@ -126,7 +127,7 @@ RplASItem* RplMFParser::parseRepeat() rc->setPosition(m_lexer.currentPosition()); RplASItem* body = parseBody(K_UNTIL); - rc->setChild(body); + rc->setChild3(body); if (! m_lexer.currentToken()->isKeyword(K_UNTIL)) syntaxError(L_PARSE_REPEAT_NO_UNTIL, "'until' expected"); @@ -165,26 +166,28 @@ RplASItem* RplMFParser::parseFor() RplASForIterated* node = new RplASForIterated(var); rc = node; node->setPosition(startPosition); + node->setChild3(var); RplASItem* iterable = parseExpr(0); - node->setChild3(iterable); + node->setChild4(iterable); } else { RplASForCounted* node = new RplASForCounted(var); rc = node; node->setPosition(startPosition); + node->setChild3(var); if (token->isKeyword(K_FROM)){ - node->setChild3(parseExpr(0)); + node->setChild4(parseExpr(0)); } if (! m_lexer.currentToken()->isKeyword(K_TO)){ syntaxError(L_PARSE_FOR_NO_TO, "'to' expected"); } - node->setChild4(parseExpr(0)); + node->setChild5(parseExpr(0)); if (m_lexer.currentToken()->isKeyword(K_STEP)){ - node->setChild5(parseExpr(0)); + node->setChild6(parseExpr(0)); } } if (! m_lexer.currentToken()->isKeyword(K_DO)) syntaxError(L_PARSE_FOR_NO_TO, "'to' expected"); - rc->setChild(parseBody(K_OD)); + rc->setChild2(parseBody(K_OD)); m_lexer.nextNonSpaceToken(); return rc; } @@ -231,14 +234,18 @@ RplASItem* RplMFParser::parseVarDefinition(Keyword attribute) token = m_lexer.nextNonSpaceToken(); if (! token->isTokenType(TOKEN_ID)) syntaxError(L_DEFINITION_MISSING_ID, "variable name expected"); - RplASNamedValue* rc = new RplASVarDefinition(clazz, token->toString(), attr); + // freed in the destructor of the nodes: + RplASNamedValue* namedValue = new RplASNamedValue(clazz, token->toString(), attr); + namedValue->setPosition(m_lexer.currentPosition()); + RplASVarDefinition* rc = new RplASVarDefinition(); rc->setPosition(m_lexer.currentPosition()); + rc->setChild2(namedValue); token = m_lexer.nextNonSpaceToken(); if (! token->isOperator(O_ASSIGN, O_SEMICOLON)) syntaxError(L_DEFINITION_NO_OP, "'=' or ';' expected"); if (token->id() == O_ASSIGN){ RplASItem* value = parseExpr(0); - rc->setChild(value); + rc->setChild3(value); token = m_lexer.currentToken(); } if (! token->isOperator(O_SEMICOLON)){ @@ -263,8 +270,8 @@ RplASVariant* RplMFParser::createFormula(RplASNode1* parent) RplASExprStatement* expr = dynamic_cast (parseExprStatement(false)); if (expr != NULL){ - // chaining per m_successor is for freeing while destruction: - expr->setSuccessor(parent->child()); + // chaining per m_child (= next statement) is for freeing while destruction: + expr->setChild(parent->child()); parent->setChild(expr); // freed in the destructor of varList (~RplASVariant()): variant = new RplASVariant(); @@ -540,23 +547,21 @@ RplASItem* RplMFParser::parseOperand(int level) } else { if (token->id() == O_LPARENTH){ RplASMethodCall* call = new RplASMethodCall(); - call->setPosition(m_lexer.currentPosition()); + call->setPosition(startPosition); + rc = call; - RplASArgument* args = parseArguments(); - call->setArg1(args); token = m_lexer.nextNonSpaceToken(); if (! token->isOperator(O_RPARENT)){ - QByteArray pos = startPosition->toString().toUtf8(); - // this call never comes back (exception!) - syntaxError(L_PARSE_OPERAND_RPARENTH_FUNC, - "')' expected. '(' is at %s", pos.constData()); + m_lexer.undoLastToken(); + RplASArgument* args = parseArguments(); + call->setArg1(args); } } else { RplASNamedValue* var = new RplASNamedValue(name); var->setPosition(startPosition); rc = var; if (token->id() == O_LBRACKET){ - RplASItem indexExpr = parseExpr(0); + RplASItem* indexExpr = parseExpr(0); if (! m_lexer.currentToken()->isOperator(O_RBRACKET)) syntaxError(L_PARSE_OPERAND_NO_BRACKET, "']' expected"); var->setChild(indexExpr); @@ -585,6 +590,8 @@ RplASItem* RplMFParser::parseOperand(int level) } if (readNext) m_lexer.nextNonSpaceToken(); +// if (m_lexer.currentToken()->isOperator(O_DOT)) + return rc; } @@ -676,7 +683,7 @@ RplASItem* RplMFParser::parseExprStatement(bool eatSemicolon) if (item != NULL){ statement = new RplASExprStatement(); statement->setPosition(item->position()); - statement->setChild(item); + statement->setChild2(item); } if (eatSemicolon && m_lexer.currentToken()->isOperator(O_SEMICOLON)) m_lexer.nextNonSpaceToken(); @@ -700,7 +707,7 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, RplToken* token = m_lexer.nextNonSpaceToken(); RplASItem* item = NULL; RplASItem* body = NULL; - RplASStatement* lastStatement = NULL; + RplASNode1* lastStatement = NULL; bool again = true; const RplSourcePosition* lastPos = NULL; do { @@ -780,9 +787,9 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, if (body == NULL){ body = item; } else { - lastStatement->setSuccessor(item); + lastStatement->setChild(item); } - lastStatement = dynamic_cast(item); + lastStatement = dynamic_cast(item); if (lastStatement == NULL) error(L_PARSE_BODY_WRONG_ITEM, "wrong item type: %d", item == NULL ? 0 : item->nodeType()); @@ -886,12 +893,25 @@ void RplMFParser::parse() } /** - * @brief Parses an argument list. + * @brief Parses an argument list in a method call. * - * @return the first element of the argument list + * @pre the token '(' is read + * @post the token behind the ')' is read + * @return the first element of the argument list */ RplASArgument* RplMFParser::parseArguments() { - return NULL; + RplASArgument* first = NULL; + bool again = false; + do { + RplASItem* expr = parseExpr(0); + if (! m_lexer.currentToken()->isOperator(O_COMMA, O_RPARENT)) + syntaxError(L_PARSE_ARGS_NO_COMMA_OR_PARENT, "',' or ')' expected"); + again = m_lexer.currentToken()->isOperator(O_COMMA); + m_lexer.nextNonSpaceToken(); + RplASArgument* current = new RplASArgument(); + current->setPosition(expr->position()); + } while (again); + return first; } diff --git a/test/rplmfparser/baseTest.txt b/test/rplmfparser/baseTest.txt index e989f86..4f2fbfd 100644 --- a/test/rplmfparser/baseTest.txt +++ b/test/rplmfparser/baseTest.txt @@ -3,7 +3,7 @@ == Classes: == Variables: == Body: -Expr id: 6 succ: 0 expr: 2 :1:1 +Expr id: 6 expr: 2 succ: 0 :1:1 BinOp id: 2 op: + (26) left: 1 right: 4 :1:1 const id: 1 value: 2 :0:0 BinOp id: 4 op: * (30) left: 3 right: 5 :1:3 diff --git a/test/rplmfparser/defTest.txt b/test/rplmfparser/defTest.txt index 7824546..b766452 100644 --- a/test/rplmfparser/defTest.txt +++ b/test/rplmfparser/defTest.txt @@ -3,8 +3,11 @@ Int i = 3; const lazy Str s = 'Hi'; const List l; == Classes: == Variables: == Body: -varDef i (Int) id: 1 succ: 3 attr: 0x0 :1:4 - const id: 2 value: 3 :1:8 -varDef s (Str) id: 3 succ: 5 attr: 0x10 :1:26 - const id: 4 value: 'Hi' :1:30 -varDef l (List) id: 5 succ: 0 attr: 0x2 :1:47 +varDef i id: 2 namedValue: 1 value: 3 succ: 5 :1:4 + namedValue i id: 1 attr: 0x0 :1:4 + const id: 3 value: 3 :1:8 +varDef s id: 5 namedValue: 4 value: 6 succ: 8 :1:26 + namedValue s id: 4 attr: 0x10 :1:26 + const id: 6 value: 'Hi' :1:30 +varDef l id: 8 namedValue: 7 value: 0 succ: 0 :1:47 + namedValue l id: 7 attr: 0x2 :1:47 diff --git a/test/rplmfparser/forC1.txt b/test/rplmfparser/forC1.txt index 0ce61c6..7f59d50 100644 --- a/test/rplmfparser/forC1.txt +++ b/test/rplmfparser/forC1.txt @@ -6,14 +6,15 @@ od == Classes: == Variables: == Body: -varDef a (Int) id: 1 succ: 3 attr: 0x0 :1:4 -forc id: 3 var: 2 from: 4 to: 5 step: 6 body: 11 :1:7 - namedValue b id: 2 attr: 0x0 :2:4 - const id: 4 value: 10 :2:11 - const id: 5 value: 1 :2:17 - Unary 6 op: - (27) Child: 7 :2:24 - const id: 7 value: 2 :2:25 - Expr id: 11 succ: 0 expr: 9 :3:2 - BinOp id: 9 op: += (6) left: 8 right: 10 :3:2 - namedValue a id: 8 attr: 0x0 :3:2 - const id: 10 value: 1 :3:5 +varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +forC id: 4 var: 3 from: 5 to: 6 step: 7 body: 12 succ: 0 :1:7 + namedValue b id: 3 attr: 0x0 :2:4 + const id: 5 value: 10 :2:11 + const id: 6 value: 1 :2:17 + Unary 7 op: - (27) expr: 8 :2:24 + const id: 8 value: 2 :2:25 + Expr id: 12 expr: 10 succ: 0 :3:2 + BinOp id: 10 op: += (6) left: 9 right: 11 :3:2 + namedValue a id: 9 attr: 0x0 :3:2 + const id: 11 value: 1 :3:5 diff --git a/test/rplmfparser/forC2.txt b/test/rplmfparser/forC2.txt index 877a107..a3a4940 100644 --- a/test/rplmfparser/forC2.txt +++ b/test/rplmfparser/forC2.txt @@ -3,10 +3,11 @@ Int a; for to 10 do a += 1 od == Classes: == Variables: == Body: -varDef a (Int) id: 1 succ: 2 attr: 0x0 :1:4 -forc id: 2 var: 0 from: 0 to: 3 step: 0 body: 7 :1:7 - const id: 3 value: 10 :1:14 - Expr id: 7 succ: 0 expr: 5 :1:22 - BinOp id: 5 op: += (6) left: 4 right: 6 :1:22 - namedValue a id: 4 attr: 0x0 :1:22 - const id: 6 value: 1 :1:25 +varDef a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +forC id: 3 var: 0 from: 0 to: 4 step: 0 body: 8 succ: 0 :1:7 + const id: 4 value: 10 :1:14 + Expr id: 8 expr: 6 succ: 0 :1:22 + BinOp id: 6 op: += (6) left: 5 right: 7 :1:22 + namedValue a id: 5 attr: 0x0 :1:22 + const id: 7 value: 1 :1:25 diff --git a/test/rplmfparser/forIt1.txt b/test/rplmfparser/forIt1.txt index a28c1ba..83e2e95 100644 --- a/test/rplmfparser/forIt1.txt +++ b/test/rplmfparser/forIt1.txt @@ -6,11 +6,12 @@ od == Classes: == Variables: == Body: -varDef a (Map) id: 1 succ: 3 attr: 0x0 :1:4 -forIt id: 3 var: 2 set: 4 body: 8 :1:7 - namedValue x id: 2 attr: 0x0 :2:4 - namedValue a id: 4 attr: 0x0 - Expr id: 8 succ: 0 expr: 6 :3:2 - BinOp id: 6 op: += (6) left: 5 right: 7 :3:2 - namedValue a id: 5 attr: 0x0 :3:2 - const id: 7 value: 1 :3:5 +varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +forIt id: 4 var: 3 set: 5 body: 9 succ: 0 :1:7 + namedValue x id: 3 attr: 0x0 :2:4 + namedValue a id: 5 attr: 0x0 + Expr id: 9 expr: 7 succ: 0 :3:2 + BinOp id: 7 op: += (6) left: 6 right: 8 :3:2 + namedValue a id: 6 attr: 0x0 :3:2 + const id: 8 value: 1 :3:5 diff --git a/test/rplmfparser/ifTest1.txt b/test/rplmfparser/ifTest1.txt index ed95634..55b6cc2 100644 --- a/test/rplmfparser/ifTest1.txt +++ b/test/rplmfparser/ifTest1.txt @@ -9,27 +9,29 @@ fi == Classes: == Variables: == Body: -varDef a (Int) id: 1 succ: 2 attr: 0x0 :1:4 -varDef b (Int) id: 2 succ: 8 attr: 0x0 :2:4 -Expr id: 8 succ: 9 expr: 4 :3:2 - BinOp id: 4 op: = (5) left: 3 right: 6 :3:2 - namedValue a id: 3 attr: 0x0 :3:2 - BinOp id: 6 op: = (5) left: 5 right: 7 :3:6 - namedValue b id: 5 attr: 0x0 :3:6 - const id: 7 value: 2 :3:8 -If id: 9 condition: 11 then: 18 else: 24 :3:11 - BinOp id: 11 op: < (21) left: 10 right: 12 :4:6 - const id: 10 value: 11 :4:3 - const id: 12 value: 12 :4:8 - Expr id: 18 succ: 0 expr: 14 :5:7 - BinOp id: 14 op: = (5) left: 13 right: 16 :5:7 - namedValue a id: 13 attr: 0x0 :5:7 - BinOp id: 16 op: * (30) left: 15 right: 17 :5:12 - const id: 15 value: 13 :5:9 - const id: 17 value: 14 :5:14 - Expr id: 24 succ: 0 expr: 20 :6:7 - BinOp id: 20 op: = (5) left: 19 right: 22 :6:7 - namedValue a id: 19 attr: 0x0 :6:7 - BinOp id: 22 op: / (28) left: 21 right: 23 :6:12 - const id: 21 value: 15 :6:9 - const id: 23 value: 16 :6:14 +varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +varDef b id: 4 namedValue: 3 value: 0 succ: 10 :2:4 + namedValue b id: 3 attr: 0x0 :2:4 +Expr id: 10 expr: 6 succ: 11 :3:2 + BinOp id: 6 op: = (5) left: 5 right: 8 :3:2 + namedValue a id: 5 attr: 0x0 :3:2 + BinOp id: 8 op: = (5) left: 7 right: 9 :3:6 + namedValue b id: 7 attr: 0x0 :3:6 + const id: 9 value: 2 :3:8 +If id: 11 condition: 13 then: 20 else: 26 succ: 0:3:11 + BinOp id: 13 op: < (21) left: 12 right: 14 :4:6 + const id: 12 value: 11 :4:3 + const id: 14 value: 12 :4:8 + Expr id: 20 expr: 16 succ: 0 :5:7 + BinOp id: 16 op: = (5) left: 15 right: 18 :5:7 + namedValue a id: 15 attr: 0x0 :5:7 + BinOp id: 18 op: * (30) left: 17 right: 19 :5:12 + const id: 17 value: 13 :5:9 + const id: 19 value: 14 :5:14 + Expr id: 26 expr: 22 succ: 0 :6:7 + BinOp id: 22 op: = (5) left: 21 right: 24 :6:7 + namedValue a id: 21 attr: 0x0 :6:7 + BinOp id: 24 op: / (28) left: 23 right: 25 :6:12 + const id: 23 value: 15 :6:9 + const id: 25 value: 16 :6:14 diff --git a/test/rplmfparser/ifTest2.txt b/test/rplmfparser/ifTest2.txt index 1393a56..47f173c 100644 --- a/test/rplmfparser/ifTest2.txt +++ b/test/rplmfparser/ifTest2.txt @@ -6,12 +6,13 @@ fi == Classes: == Variables: == Body: -varDef x (Str) id: 1 succ: 2 attr: 0x0 :1:4 -If id: 2 condition: 4 then: 9 else: 0 :1:7 - BinOp id: 4 op: < (21) left: 3 right: 5 :2:5 - const id: 3 value: 7 :2:3 - const id: 5 value: 6 :2:7 - Expr id: 9 succ: 0 expr: 7 :3:7 - BinOp id: 7 op: = (5) left: 6 right: 8 :3:7 - namedValue x id: 6 attr: 0x0 :3:7 - const id: 8 value: '123' :3:9 +varDef x id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue x id: 1 attr: 0x0 :1:4 +If id: 3 condition: 5 then: 10 else: 0 succ: 0:1:7 + BinOp id: 5 op: < (21) left: 4 right: 6 :2:5 + const id: 4 value: 7 :2:3 + const id: 6 value: 6 :2:7 + Expr id: 10 expr: 8 succ: 0 :3:7 + BinOp id: 8 op: = (5) left: 7 right: 9 :3:7 + namedValue x id: 7 attr: 0x0 :3:7 + const id: 9 value: '123' :3:9 diff --git a/test/rplmfparser/list1.txt b/test/rplmfparser/list1.txt index 2b6cc66..b35935c 100644 --- a/test/rplmfparser/list1.txt +++ b/test/rplmfparser/list1.txt @@ -3,6 +3,7 @@ List b = []; == Classes: == Variables: == Body: -varDef b (List) id: 1 succ: 0 attr: 0x0 :1:5 - listConst id: 2 :1:9 +varDef b id: 2 namedValue: 1 value: 3 succ: 0 :1:5 + namedValue b id: 1 attr: 0x0 :1:5 + listConst id: 3 :1:9 [] diff --git a/test/rplmfparser/list2.txt b/test/rplmfparser/list2.txt index cc1885d..ec5cbe5 100644 --- a/test/rplmfparser/list2.txt +++ b/test/rplmfparser/list2.txt @@ -3,9 +3,11 @@ List a = [2+3, 3.14, 7, 'hi', a]; List b = []; == Classes: == Variables: == Body: -varDef a (List) id: 1 succ: 9 attr: 0x0 :1:5 - listConst id: 2 :1:9 - [,3.140000,7,'hi',] -varDef b (List) id: 9 succ: 0 attr: 0x0 :1:39 - listConst id: 10 :1:43 +varDef a id: 2 namedValue: 1 value: 3 succ: 11 :1:5 + namedValue a id: 1 attr: 0x0 :1:5 + listConst id: 3 :1:9 + [,3.140000,7,'hi',] +varDef b id: 11 namedValue: 10 value: 12 succ: 0 :1:39 + namedValue b id: 10 attr: 0x0 :1:39 + listConst id: 12 :1:43 [] diff --git a/test/rplmfparser/map1.txt b/test/rplmfparser/map1.txt index c0ac61a..25c1359 100644 --- a/test/rplmfparser/map1.txt +++ b/test/rplmfparser/map1.txt @@ -3,6 +3,7 @@ Map a = {}; == Classes: == Variables: == Body: -varDef a (Map) id: 1 succ: 0 attr: 0x0 :1:4 - mapConst id: 2 :1:8 +varDef a id: 2 namedValue: 1 value: 3 succ: 0 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + mapConst id: 3 :1:8 {} diff --git a/test/rplmfparser/map2.txt b/test/rplmfparser/map2.txt index 1e24831..6272b8b 100644 --- a/test/rplmfparser/map2.txt +++ b/test/rplmfparser/map2.txt @@ -4,9 +4,11 @@ Map b = {}; == Classes: == Variables: == Body: -varDef a (Map) id: 1 succ: 9 attr: 0x0 :1:4 - mapConst id: 2 :1:8 - {'a':,'bcd':3.140000,'ccc':7,'hi':} -varDef b (Map) id: 9 succ: 0 attr: 0x0 :2:4 - mapConst id: 10 :2:8 +varDef a id: 2 namedValue: 1 value: 3 succ: 11 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + mapConst id: 3 :1:8 + {'a':,'bcd':3.140000,'ccc':7,'hi':} +varDef b id: 11 namedValue: 10 value: 12 succ: 0 :2:4 + namedValue b id: 10 attr: 0x0 :2:4 + mapConst id: 12 :2:8 {} diff --git a/test/rplmfparser/opTest1.txt b/test/rplmfparser/opTest1.txt index 2315f66..446622d 100644 --- a/test/rplmfparser/opTest1.txt +++ b/test/rplmfparser/opTest1.txt @@ -8,35 +8,37 @@ a=b=(a+(b-2)*3) == Classes: == Variables: == Body: -varDef a (Int) id: 1 succ: 3 attr: 0x0 :1:4 - const id: 2 value: 1 :1:8 -varDef b (Int) id: 3 succ: 7 attr: 0x0 :2:4 - const id: 4 value: 100 :2:8 -Expr id: 7 succ: 10 expr: 5 :2:13 - Unary 5 op: -- (41) Child: 6 :2:13 - namedValue a id: 6 attr: 0x0 :3:3 -Expr id: 10 succ: 20 expr: 9 - Unary 9 op: ++ (40) Child: 8 - namedValue b id: 8 attr: 0x0 :4:1 -Expr id: 20 succ: 32 expr: 13 :5:3 - BinOp id: 13 op: * (30) left: 12 right: 16 :5:3 - Unary 12 op: -- (41) Child: 11 - namedValue a id: 11 attr: 0x0 :5:1 - BinOp id: 16 op: ** (31) left: 14 right: 18 :5:7 - Unary 14 op: ++ (40) Child: 15 :5:4 - namedValue b id: 15 attr: 0x0 :5:7 - BinOp id: 18 op: - (27) left: 17 right: 19 :5:11 - const id: 17 value: 8 :5:10 - const id: 19 value: 3 :5:12 -Expr id: 32 succ: 0 expr: 22 :6:1 - BinOp id: 22 op: = (5) left: 21 right: 24 :6:1 - namedValue a id: 21 attr: 0x0 :6:1 - BinOp id: 24 op: = (5) left: 23 right: 26 :6:3 - namedValue b id: 23 attr: 0x0 :6:3 - BinOp id: 26 op: + (26) left: 25 right: 30 :6:6 - namedValue a id: 25 attr: 0x0 :6:6 - BinOp id: 30 op: * (30) left: 28 right: 31 :6:12 - BinOp id: 28 op: - (27) left: 27 right: 29 :6:9 - namedValue b id: 27 attr: 0x0 :6:9 - const id: 29 value: 2 :6:10 - const id: 31 value: 3 :6:13 +varDef a id: 2 namedValue: 1 value: 3 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + const id: 3 value: 1 :1:8 +varDef b id: 5 namedValue: 4 value: 6 succ: 9 :2:4 + namedValue b id: 4 attr: 0x0 :2:4 + const id: 6 value: 100 :2:8 +Expr id: 9 expr: 7 succ: 12 :2:13 + Unary 7 op: -- (41) expr: 8 :2:13 + namedValue a id: 8 attr: 0x0 :3:3 +Expr id: 12 expr: 11 succ: 22 + Unary 11 op: ++ (40) expr: 10 + namedValue b id: 10 attr: 0x0 :4:1 +Expr id: 22 expr: 15 succ: 34 :5:3 + BinOp id: 15 op: * (30) left: 14 right: 18 :5:3 + Unary 14 op: -- (41) expr: 13 + namedValue a id: 13 attr: 0x0 :5:1 + BinOp id: 18 op: ** (31) left: 16 right: 20 :5:7 + Unary 16 op: ++ (40) expr: 17 :5:4 + namedValue b id: 17 attr: 0x0 :5:7 + BinOp id: 20 op: - (27) left: 19 right: 21 :5:11 + const id: 19 value: 8 :5:10 + const id: 21 value: 3 :5:12 +Expr id: 34 expr: 24 succ: 0 :6:1 + BinOp id: 24 op: = (5) left: 23 right: 26 :6:1 + namedValue a id: 23 attr: 0x0 :6:1 + BinOp id: 26 op: = (5) left: 25 right: 28 :6:3 + namedValue b id: 25 attr: 0x0 :6:3 + BinOp id: 28 op: + (26) left: 27 right: 32 :6:6 + namedValue a id: 27 attr: 0x0 :6:6 + BinOp id: 32 op: * (30) left: 30 right: 33 :6:12 + BinOp id: 30 op: - (27) left: 29 right: 31 :6:9 + namedValue b id: 29 attr: 0x0 :6:9 + const id: 31 value: 2 :6:10 + const id: 33 value: 3 :6:13 diff --git a/test/rplmfparser/repeatTest.txt b/test/rplmfparser/repeatTest.txt index 546eb1e..93b5f5a 100644 --- a/test/rplmfparser/repeatTest.txt +++ b/test/rplmfparser/repeatTest.txt @@ -6,13 +6,14 @@ until a != 2 * 3; == Classes: == Variables: == Body: -varDef a (Int) id: 1 succ: 2 attr: 0x0 :1:4 -repeat id: 2 condition: 7 body: 5 :1:7 - Expr id: 5 succ: 0 expr: 4 - Unary 4 op: ++ (40) Child: 3 - namedValue a id: 3 attr: 0x0 :3:1 - BinOp id: 7 op: != (20) left: 6 right: 9 :4:8 - namedValue a id: 6 attr: 0x0 :4:8 - BinOp id: 9 op: * (30) left: 8 right: 10 :4:13 - const id: 8 value: 2 :4:11 - const id: 10 value: 3 :4:15 +varDef a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +repeat id: 3 condition: 8 body: 6 succ: 0 :1:7 + BinOp id: 8 op: != (20) left: 7 right: 10 :4:8 + namedValue a id: 7 attr: 0x0 :4:8 + BinOp id: 10 op: * (30) left: 9 right: 11 :4:13 + const id: 9 value: 2 :4:11 + const id: 11 value: 3 :4:15 + Expr id: 6 expr: 5 succ: 0 + Unary 5 op: ++ (40) expr: 4 + namedValue a id: 4 attr: 0x0 :3:1 diff --git a/test/rplmfparser/whileTest.txt b/test/rplmfparser/whileTest.txt index bddc933..410991b 100644 --- a/test/rplmfparser/whileTest.txt +++ b/test/rplmfparser/whileTest.txt @@ -6,13 +6,14 @@ od == Classes: == Variables: == Body: -varDef a (Int) id: 1 succ: 3 attr: 0x0 :1:4 - const id: 2 value: 20 :1:8 -while id: 3 condition: 5 body: 10 :1:12 - BinOp id: 5 op: < (21) left: 4 right: 6 :2:8 - const id: 4 value: 3 :2:6 - const id: 6 value: 5 :2:10 - Expr id: 10 succ: 0 expr: 8 :3:3 - BinOp id: 8 op: = (5) left: 7 right: 9 :3:3 - namedValue a id: 7 attr: 0x0 :3:3 - const id: 9 value: 7 :3:5 +varDef a id: 2 namedValue: 1 value: 3 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + const id: 3 value: 20 :1:8 +while id: 4 condition: 6 body: 11 succ: 0 :1:12 + BinOp id: 6 op: < (21) left: 5 right: 7 :2:8 + const id: 5 value: 3 :2:6 + const id: 7 value: 5 :2:10 + Expr id: 11 expr: 9 succ: 0 :3:3 + BinOp id: 9 op: = (5) left: 8 right: 10 :3:3 + namedValue a id: 8 attr: 0x0 :3:3 + const id: 10 value: 7 :3:5 diff --git a/unittests/rplmfparser_test.cpp b/unittests/rplmfparser_test.cpp index d183689..5a85d80 100644 --- a/unittests/rplmfparser_test.cpp +++ b/unittests/rplmfparser_test.cpp @@ -131,8 +131,16 @@ public: parser.parse(); checkAST("map2.txt", __LINE__); } + void methodCallTest(){ + setSource("max(4**(5),3.14*8));"); + //setSource("rand();\nsin(a);\nmax(1+2*3,4**(5-4));"); + RplMFParser parser(m_source, m_tree); + parser.parse(); + checkAST("methc1.txt", __LINE__); + } virtual void doIt(void) { + methodCallTest(); mapTest(); forItTest(); forCTest();