return m_id;
}
+/**
+ * @brief Resets the static id counter.
+ */
+void RplASItem::reset()
+{
+ m_nextId = 1;
+}
+
/** @class RplASExpr rplastree.hpp "rplexpr/rplastree.hpp"
*
{
delete m_child;
m_child = NULL;
+}
+/**
+ * @brief Returns the child.
+ *
+ * @return the child of the instance
+ */
+RplASItem*RplASNode1::child() const
+{
+
}
/**
* @brief Sets the child.
DEFINE_TABS(indent);
const QByteArray& opName = RplLexer::m_active->nameOfOp(m_operator);
char buffer[256];
- fprintf(fp, "%sBinOp %d op: %s (%d) left: %d right: %d %s\n", tabs, m_id,
+ fprintf(fp, "%sBinOp id: %d op: %s (%d) left: %d right: %d %s\n",
+ tabs, m_id,
opName.constData(), m_operator,
m_child == NULL ? 0 : m_child->id(),
m_child2 == NULL ? 0 : m_child2->id(),
m_position->utf8(buffer, sizeof buffer));
- if (m_child != NULL)
+ if (indent < 32 && m_child != NULL)
m_child->dump(fp, indent + 1);
- if (m_child2 != NULL)
+ if (indent < 32 && m_child2 != NULL)
m_child2->dump(fp, indent + 1);
}
* @param header NULL or the headline
*/
virtual void dump(FILE* fp, int indent) = 0;
+public:
+ static void reset();
protected:
unsigned int m_id:16;
RplASItemType m_nodeType:8;
RplASNode1(RplASItemType type);
virtual ~RplASNode1();
public:
+ RplASItem* child() const;
void setChild(RplASItem* child);
protected:
RplASItem* m_child;
&& ! m_lexer.isRightAssociative(opId))){
op->setChild(top);
top = op;
- } else{
+ } else if (prio > lastPrio){
RplASBinaryOp* top2 = dynamic_cast<RplASBinaryOp*>(op);
op->setChild(top2->child2());
top2->setChild2(op);
+ } else {
+ // right assoc:
+ RplASBinaryOp* top2 = dynamic_cast<RplASBinaryOp*>(top);
+ op->setChild(top2->child2());
+ top2->setChild2(op);
}
lastPrio = prio;
op->setChild2(parseOperand(depth));
*/
RplASItem* RplMFParser::parseExprStatement()
{
- RplASItem* item = parseExpr();
+ RplASItem* item = parseTerm(0);
RplASExprStatement* statement = new RplASExprStatement();
statement->setPosition(item->position());
statement->setChild(item);
varDef a (Int) id: 1 succ: 2 attr: 0x0 <test>:1:4
varDef b (Int) id: 2 succ: 8 attr: 0x0 <test>:2:4
Expr id: 8 succ: 9 expr: 4 <test>:3:2
- BinOp 4 op: = (5) left: 3 right: 5 <test>:3:2
+ BinOp id: 4 op: = (5) left: 3 right: 6 <test>:3:2
namedValue a id: 3 attr: 0x0 <test>:3:2
- namedValue b id: 5 attr: 0x0 <test>:3:6
+ BinOp id: 6 op: = (5) left: 5 right: 7 <test>:3:6
+ namedValue b id: 5 attr: 0x0 <test>:3:6
+ const id: 7 value: 2 <test>:3:8
If id: 9 condition: 11 then: 18 else: 24 <test>:3:11
- BinOp 11 op: < (21) left: 10 right: 12 <test>:4:6
+ BinOp id: 11 op: < (21) left: 10 right: 12 <test>:4:6
const id: 10 value: 11 <test>:4:3
const id: 12 value: 12 <test>:4:8
Expr id: 18 succ: 0 expr: 14 <test>:5:7
- BinOp 14 op: = (5) left: 13 right: 15 <test>:5:7
+ BinOp id: 14 op: = (5) left: 13 right: 15 <test>:5:7
namedValue a id: 13 attr: 0x0 <test>:5:7
const id: 15 value: 13 <test>:5:9
Expr id: 24 succ: 0 expr: 20 <test>:6:7
- BinOp 20 op: = (5) left: 19 right: 21 <test>:6:7
+ BinOp id: 20 op: = (5) left: 19 right: 21 <test>:6:7
namedValue a id: 19 attr: 0x0 <test>:6:7
const id: 21 value: 15 <test>:6:9
-Str x; if 7 < 6 then x = '123'; fi
+Str x;
+if 7 < 6
+then x = '123';
+fi
= <test> (module) parent: global
== Classes:
== Variables:
== Body:
-varDef x (Str) id: 25 succ: 26 attr: 0x0 <test>:1:4
-If id: 26 condition: 28 then: 33 else: 0 <test>:1:7
- BinOp 28 op: < (21) left: 27 right: 29 <test>:1:12
- const id: 27 value: 7 <test>:1:10
- const id: 29 value: 6 <test>:1:14
- Expr id: 33 succ: 0 expr: 31 <test>:1:23
- BinOp 31 op: = (5) left: 30 right: 32 <test>:1:23
- namedValue x id: 30 attr: 0x0 <test>:1:23
- const id: 32 value: '123' <test>:1:25
+varDef x (Str) id: 1 succ: 2 attr: 0x0 <test>:1:4
+If id: 2 condition: 4 then: 9 else: 0 <test>:1:7
+ BinOp id: 4 op: < (21) left: 3 right: 5 <test>:2:5
+ const id: 3 value: 7 <test>:2:3
+ const id: 5 value: 6 <test>:2:7
+ Expr id: 9 succ: 0 expr: 7 <test>:3:7
+ BinOp id: 7 op: = (5) left: 6 right: 8 <test>:3:7
+ namedValue x id: 6 attr: 0x0 <test>:3:7
+ const id: 8 value: '123' <test>:3:9
--- /dev/null
+Int a;
+--aa;
+aa++;
+a--+3*4
+= <test> (module) parent: global
+== Classes:
+== Variables:
+== Body:
+varDef a (Int) id: 1 succ: 0 attr: 0x0 <test>:1:4
+Int a = 20;
+while 3 < 5 do
+ a = 7
+od
= <test> (module) parent: global
== Classes:
== Variables:
== Body:
-varDef a (Int) id: 1 succ: 3 attr: 0x0
- const id: 2 value: 20
-while id: 3 condition: 5 body: 9
- BinOp 5 op: < (21) left: 4 right: 6
- const id: 4 value: 3
- const id: 6 value: 5
- Expr id: 9 succ: 0 expr: 7
- BinOp 7 op: = (5) left: 0 right: 8
- const id: 8 value: 7
+varDef a (Int) id: 1 succ: 3 attr: 0x0 <test>:1:4
+ const id: 2 value: 20 <test>:1:8
+while id: 3 condition: 5 body: 10 <test>:1:12
+ BinOp id: 5 op: < (21) left: 4 right: 6 <test>:2:8
+ const id: 4 value: 3 <test>:2:6
+ const id: 6 value: 5 <test>:2:10
+ Expr id: 10 succ: 0 expr: 8 <test>:3:3
+ BinOp id: 8 op: = (5) left: 7 right: 9 <test>:3:3
+ namedValue a id: 7 attr: 0x0 <test>:3:3
+ const id: 9 value: 7 <test>:3:5
}
protected:
void setSource(const char* content){
+ RplASItem::reset();
m_currentSource = content;
m_tree.clear();
m_source.clear();
RplMFParser parser(m_source, m_tree);
parser.parse();
checkAST("ifTest1.txt", __LINE__);
- setSource("Str x; if 7 < 6 then x = '123'; fi");
+ setSource("Str x;\nif 7 < 6\nthen x = '123';\nfi");
parser.parse();
checkAST("ifTest2.txt", __LINE__);
}
void whileTest(){
- setSource("Int a = 20; while 3 < 5 do a = 7 od");
+ setSource("Int a = 20;\nwhile 3 < 5 do\n a = 7\nod");
RplMFParser parser(m_source, m_tree);
parser.parse();
checkAST("whileTest.txt", __LINE__);
}
void repeatTest(){
- setSource("Int a; repeat a++; until a != 2 * 3;");
+ setSource("Int a;\nrepeat\na++;\nuntil a != 2 * 3;");
RplMFParser parser(m_source, m_tree);
parser.parse();
checkAST("repeatTest.txt", __LINE__);
}
void forCTest(){
- setSource("Int a; for b from 1 to 10 step 2 do a += 1; od");
+ setSource("Int a;\nfor b from 1 to 10 step 2 do\na += 1;\nod");
RplMFParser parser(m_source, m_tree);
parser.parse();
checkAST("forC1.txt", __LINE__);
parser.parse();
checkAST("forC2.txt", __LINE__);
}
+ void opTest(){
+ setSource("--aa;\naa++;\na--+3*4");
+ RplMFParser parser(m_source, m_tree);
+ parser.parse();
+ checkAST("opTest1.txt", __LINE__);
+ }
virtual void doIt(void) {
+ opTest();
ifTest();
whileTest();
repeatTest();