[Avida-SVN] r2024 - development/source/script
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue Aug 28 19:12:18 PDT 2007
Author: brysonda
Date: 2007-08-28 22:12:18 -0400 (Tue, 28 Aug 2007)
New Revision: 2024
Modified:
development/source/script/ASTree.h
development/source/script/cASTDumpVisitor.cc
development/source/script/cParser.cc
Log:
AS: Parse Array Unpack.
Modified: development/source/script/ASTree.h
===================================================================
--- development/source/script/ASTree.h 2007-08-28 19:38:47 UTC (rev 2023)
+++ development/source/script/ASTree.h 2007-08-29 02:12:18 UTC (rev 2024)
@@ -446,18 +446,24 @@
tManagedPointerArray<cString> m_nodes;
bool m_last_wild;
bool m_last_named;
+ cASTNode* m_expr;
public:
- cASTUnpackTarget() : m_last_wild(false), m_last_named(false) { ; }
- ~cASTUnpackTarget() { ; }
+ cASTUnpackTarget() : m_last_wild(false), m_last_named(false), m_expr(NULL) { ; }
+ ~cASTUnpackTarget() { delete m_expr; }
inline void AddVar(const cString& name) { m_nodes.Push(name); }
inline int GetSize() const { return m_nodes.GetSize(); }
inline const cString& GetVar(int idx) const { return m_nodes[idx]; }
+ inline bool IsLastNamed() const { return m_last_named; }
+ inline bool IsLastWild() const { return m_last_wild; }
+
inline void SetLastNamed() { m_last_wild = true; m_last_named = true; }
inline void SetLastWild() { m_last_wild = true; m_last_named = false; }
+ cASTNode* GetExpression() const { return m_expr; }
+ void SetExpression(cASTNode* expr) { delete m_expr; m_expr = expr; }
void Accept(cASTVisitor& visitor);
};
Modified: development/source/script/cASTDumpVisitor.cc
===================================================================
--- development/source/script/cASTDumpVisitor.cc 2007-08-28 19:38:47 UTC (rev 2023)
+++ development/source/script/cASTDumpVisitor.cc 2007-08-29 02:12:18 UTC (rev 2024)
@@ -388,5 +388,38 @@
void cASTDumpVisitor::visitUnpackTarget(cASTUnpackTarget& node)
{
- // @todo
+ m_depth++;
+
+ // Array unpack portion
+ indent();
+ cout << "@{";
+ m_depth++;
+
+ for (int i = 0; i < node.GetSize(); i++) {
+ cout << endl;
+ indent();
+ cout << node.GetVar(i);
+ }
+ if (node.IsLastNamed()) {
+ cout << "..";
+ } else if (node.IsLastWild()) {
+ cout << endl;
+ indent();
+ cout << "..";
+ }
+ cout << endl;
+ m_depth--;
+ indent();
+ cout << "}" << endl;
+
+ // Equals
+ m_depth--;
+ indent();
+ cout << "=" << endl;
+ m_depth++;
+
+ // Expression portion
+ node.GetExpression()->Accept(*this);
+
+ m_depth--;
}
Modified: development/source/script/cParser.cc
===================================================================
--- development/source/script/cParser.cc 2007-08-28 19:38:47 UTC (rev 2023)
+++ development/source/script/cParser.cc 2007-08-29 02:12:18 UTC (rev 2024)
@@ -291,6 +291,12 @@
PARSE_UNEXPECT();
}
}
+
+ if (nextToken() != TOKEN(ARR_CLOSE)) PARSE_UNEXPECT();
+ if (nextToken() != TOKEN(ASSIGN)) PARSE_UNEXPECT();
+ nextToken(); // consume '='
+
+ (*ut).SetExpression(parseExpression());
return ut.Release();
}
More information about the Avida-cvs
mailing list