Added Procedures to BAD

Change-Id: I03550a74e2c90179e72345103b3d2c4f98148631
diff --git a/asterix-bad/src/main/resources/lang-extension/lang.txt b/asterix-bad/src/main/resources/lang-extension/lang.txt
index 94b4c78..b433f5f 100644
--- a/asterix-bad/src/main/resources/lang-extension/lang.txt
+++ b/asterix-bad/src/main/resources/lang-extension/lang.txt
@@ -5,6 +5,8 @@
 import org.apache.asterix.bad.lang.statement.CreateBrokerStatement;
 import org.apache.asterix.bad.lang.statement.CreateChannelStatement;
 import org.apache.asterix.bad.lang.statement.CreateProcedureStatement;
+import org.apache.asterix.bad.lang.statement.ExecuteProcedureStatement;
+import org.apache.asterix.bad.lang.statement.ProcedureDropStatement;
 
 
 @merge
@@ -18,7 +20,7 @@
   (
     // merge area 2
     before:
-    after:    | stmt = ChannelSubscriptionStatement())
+    after:    | stmt = ChannelSubscriptionStatement() | stmt = ProcedureExecution())
   {
     // merge area 3
   }
@@ -60,6 +62,10 @@
       {
         stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);	
       }
+              | "procedure" funcSig = FunctionSignature() ifExists = IfExists()
+      {
+        stmt = new ProcedureDropStatement(funcSig, ifExists);
+      }
       )
   {
     // merge area 3
@@ -74,13 +80,13 @@
   CreateChannelStatement ccs = null;
   String fqFunctionName = null;
   Expression period = null;
-  boolean distributed = false;
+  boolean distributed = true;
 }
 {
   (
     "repetitive" "channel"  nameComponents = QualifiedName()
     <USING> appliedFunction = FunctionSignature()
-    "period" period = FunctionCallExpr() ("distributed" { distributed = true; })?
+    "period" period = FunctionCallExpr() ("nondistributed" { distributed = false; })?
     {
       ccs = new CreateChannelStatement(nameComponents.first,
                                    nameComponents.second, appliedFunction, period, distributed);
@@ -91,37 +97,67 @@
     }
 }
 
-
 @new
 CreateProcedureStatement ProcedureSpecification() throws ParseException:
 {
-  Pair<Identifier,Identifier> nameComponents = null;
+  FunctionName fctName = null;
   FunctionSignature signature;
   List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
   String functionBody;
   Token beginPos;
   Token endPos;
-  Expression functionBodyExpr;
+  Statement functionBodyExpr;
+  Expression period = null;
 }
 {
-    "procedure" nameComponents = QualifiedName()
+     "procedure" fctName = FunctionName()
      paramList = ParameterList()
     <LEFTBRACE>
   {
      beginPos = token;
   }
-  functionBodyExpr = Expression() <RIGHTBRACE>
+  functionBodyExpr = SingleStatement() <RIGHTBRACE>
     {
       endPos = token;
       functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
-      signature = new FunctionSignature(nameComponents.first.toString(), nameComponents.second.toString(), paramList.size());
+      signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
       removeCurrentScope();
-      return new CreateProcedureStatement(signature, paramList, functionBody);
     }
+  ("period" period = FunctionCallExpr())?
+  {
+  return new CreateProcedureStatement(signature, paramList, functionBody, period);
+  }
 }
 
-
-
+@new
+ExecuteProcedureStatement ProcedureExecution() throws ParseException:
+{
+  ExecuteProcedureStatement callExpr;
+  List<Expression> argList = new ArrayList<Expression>();
+  Expression tmp;
+  int arity = 0;
+  FunctionName funcName = null;
+  String hint = null;
+}
+{
+  "execute"
+  funcName = FunctionName()
+  <LEFTPAREN> (tmp = Expression()
+    {
+      argList.add(tmp);
+      arity ++;
+    }
+  (<COMMA> tmp = Expression()
+    {
+      argList.add(tmp);
+      arity++;
+    }
+  )*)? <RIGHTPAREN>
+    {
+      String fqFunctionName =  funcName.function;
+      return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity);
+    }
+}
 
 @new
 CreateBrokerStatement BrokerSpecification() throws ParseException: