[Avida-SVN] r1996 - development/source/script

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Thu Aug 23 13:18:56 PDT 2007


Author: brysonda
Date: 2007-08-23 16:18:56 -0400 (Thu, 23 Aug 2007)
New Revision: 1996

Modified:
   development/source/script/ASTree.h
   development/source/script/cASTDumpVisitor.cc
   development/source/script/cParser.cc
Log:
AS: Parse function calls.

Modified: development/source/script/ASTree.h
===================================================================
--- development/source/script/ASTree.h	2007-08-23 19:45:59 UTC (rev 1995)
+++ development/source/script/ASTree.h	2007-08-23 20:18:56 UTC (rev 1996)
@@ -331,10 +331,19 @@
 class cASTFunctionCall : public cASTNode
 {
 private:
+  cASTNode* m_target;
+  cASTNode* m_args;
   
 public:
-  cASTFunctionCall() { ; }
+  cASTFunctionCall(cASTNode* target) : m_target(target), m_args(NULL) { ; }
+  ~cASTFunctionCall() { delete m_args; }
   
+  cASTNode* GetTarget() { return m_target; }
+  void SetArguments(cASTNode* args) { m_args = args; }
+  cASTNode* GetArguments() { return m_args; }
+  
+  bool HasArguments() const { return (m_args); }
+  
   void Accept(cASTVisitor& visitor);
 };
 

Modified: development/source/script/cASTDumpVisitor.cc
===================================================================
--- development/source/script/cASTDumpVisitor.cc	2007-08-23 19:45:59 UTC (rev 1995)
+++ development/source/script/cASTDumpVisitor.cc	2007-08-23 20:18:56 UTC (rev 1996)
@@ -298,7 +298,27 @@
 
 void cASTDumpVisitor::visitFunctionCall(cASTFunctionCall& node)
 {
+  indent();
+  cout << "call:" << endl;
+  m_depth++;
   
+  indent();
+  cout << "target:" << endl;
+  
+  m_depth++;
+  node.GetTarget()->Accept(*this);
+  m_depth--;
+  
+  if (node.HasArguments()) {
+    indent();
+    cout << "with:" << endl;
+    
+    m_depth++;
+    node.GetArguments()->Accept(*this);
+    m_depth--;
+  }
+  
+  m_depth--;
 }
 
 

Modified: development/source/script/cParser.cc
===================================================================
--- development/source/script/cParser.cc	2007-08-23 19:45:59 UTC (rev 1995)
+++ development/source/script/cParser.cc	2007-08-23 20:18:56 UTC (rev 1996)
@@ -298,7 +298,7 @@
 {
   PARSE_TRACE("parseArgumentList");
   cASTNode* al = NULL;
-  
+  // @todo - argument list
   parseExpression();
   while (currentToken() == TOKEN(COMMA)) {
     parseExpression();
@@ -324,7 +324,7 @@
 cASTNode* cParser::parseCallExpression()
 {
   PARSE_TRACE("parseCallExpression");
-  cASTNode* ce = NULL;
+  tAutoRelease<cASTNode> ce(new cASTVariableReference(currentText()));
   
   nextToken();
   
@@ -334,14 +334,16 @@
       case TOKEN(DOT):
         if (nextToken() != TOKEN(ID)) {
           PARSE_UNEXPECT();
-          return ce;
+          return ce.Release();
         }
         break;
       case TOKEN(PREC_OPEN):
-        if (nextToken() != TOKEN(PREC_CLOSE)) parseArgumentList();
+        cASTFunctionCall* fc = new cASTFunctionCall(ce.Release());
+        ce.Set(fc);
+        if (nextToken() != TOKEN(PREC_CLOSE)) fc->SetArguments(parseArgumentList());
         if (currentToken() != TOKEN(PREC_CLOSE)) {
           PARSE_UNEXPECT();
-          return ce;   
+          return ce.Release();   
         }
         switch (nextToken()) {
           case TOKEN(IDX_OPEN):
@@ -363,11 +365,11 @@
 
       default:
         PARSE_UNEXPECT();
-        return ce;
+        return ce.Release();
     }
   }
     
-  return ce;
+  return ce.Release();
 }
 
 cASTNode* cParser::parseCodeBlock()
@@ -578,13 +580,15 @@
       break;
     case TOKEN(ID):
       if (peekToken() == TOKEN(PREC_OPEN)) {
+        cASTNode* vr = new cASTVariableReference(currentText());
         nextToken(); // consume id token
-        if (nextToken() != TOKEN(PREC_CLOSE)) parseArgumentList();
+        cASTFunctionCall* fc = new cASTFunctionCall(vr);
+        expr = fc;
+        if (nextToken() != TOKEN(PREC_CLOSE)) fc->SetArguments(parseArgumentList());        
         if (currentToken() != TOKEN(PREC_CLOSE)) {
           PARSE_UNEXPECT();
           return expr;
         }
-        expr = new cASTFunctionCall(); // @todo
       } else {
         expr = new cASTVariableReference(currentText());
       }




More information about the Avida-cvs mailing list