Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / tools / org / apache / derby / impl / tools / ij / mtGrammar.jj
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/tools/org/apache/derby/impl/tools/ij/mtGrammar.jj b/JMCR-Stable/real-world application/MyDerby-10.3/java/tools/org/apache/derby/impl/tools/ij/mtGrammar.jj
new file mode 100644 (file)
index 0000000..7aae43a
--- /dev/null
@@ -0,0 +1,406 @@
+/*\r
+* Licensed to the Apache Software Foundation (ASF) under one or more\r
+* contributor license agreements.  See the NOTICE file distributed with\r
+* this work for additional information regarding copyright ownership.\r
+* The ASF licenses this file to you under the Apache License, Version 2.0\r
+* (the "License"); you may not use this file except in compliance with\r
+* the License.  You may obtain a copy of the License at\r
+*\r
+*     http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*/\r
+\r
+options {\r
+       STATIC = false;\r
+       DEBUG_PARSER = false;\r
+       DEBUG_TOKEN_MANAGER = false;\r
+       ERROR_REPORTING = true;\r
+       USER_TOKEN_MANAGER = false;\r
+       USER_CHAR_STREAM = false;\r
+       JAVA_UNICODE_ESCAPE = false;\r
+       UNICODE_INPUT = true;\r
+       IGNORE_CASE = true;\r
+       CACHE_TOKENS = true;\r
+       LOOKAHEAD = 1;\r
+}\r
+\r
+PARSER_BEGIN(mtGrammar)\r
+\r
+package org.apache.derby.impl.tools.ij;\r
+\r
+import java.util.Hashtable;\r
+import java.util.Vector;\r
+import java.io.IOException;\r
+import org.apache.derby.iapi.tools.i18n.*;\r
+\r
+public class mtGrammar \r
+{\r
+       private LocalizedOutput currOut;\r
+       private LocalizedInput currIn;\r
+\r
+\r
+       mtGrammar() { }\r
+}\r
+\r
+PARSER_END(mtGrammar)\r
+\r
+/* WHITE SPACE */\r
+\r
+SKIP :\r
+{\r
+  " "\r
+| "\t"\r
+| "\r\n"\r
+| "\n"\r
+| "\r"\r
+| "\f"\r
+}\r
+\r
+SPECIAL_TOKEN : /* COMMENTS */\r
+{\r
+  <SINGLE_LINE_SQLCOMMENT: "--" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>\r
+       | <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>\r
+       | <SINGLE_LINE_COMMENT2: "#" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>\r
+}\r
+\r
+TOKEN [IGNORE_CASE] :\r
+{\r
+       <CASE: "case:">\r
+|      <FILE: "file:"> \r
+|      <LAST: "last:"> \r
+|      <INIT: "init:"> \r
+|      <WEIGHT: "weight:">     \r
+|      <DESCRIPTION: "description:">   \r
+|      <IGNOREERRORS: "ignoreErrors:"> \r
+|      <PROPERTIES: "properties:">     \r
+|      <THREADS: "threads:">   \r
+|      <RUNTIME: "runtime:">   \r
+|      <INT: (["0"-"9"])+> \r
+|      <WORD: (["a"-"z", "A"-"Z", "_", "/", ".","$", "0"-"9"])+> \r
+|      <STRING: ["\""] (~["\n", "\r", "\""])+ ["\""] > \r
+}\r
+\r
+TOKEN :\r
+{      /* Operators and punctuation */\r
+       <COMMA: ","> \r
+|      <COLON: ":"> \r
+}\r
+\r
+\r
+//\r
+// start of BNF rules\r
+//\r
+\r
+mtTestSuite\r
+grammarStatement() :\r
+{\r
+       Vector cases = null;\r
+       Vector init = null;\r
+       Vector last = null;\r
+       int     threads = 0;\r
+       mtTime time; \r
+}\r
+{\r
+       threads=numThreads() \r
+       time=runTime() \r
+       [ init=init() ]\r
+       cases=cases()\r
+       [ last=last() ]\r
+       <EOF>\r
+       {\r
+               return new mtTestSuite(threads, time, init, cases, last);\r
+       \r
+       }       \r
+}\r
+int\r
+numThreads() :\r
+{\r
+       Token   t;\r
+}\r
+{\r
+       <THREADS> t=<INT>\r
+       {\r
+               int val = Integer.decode(t.image).intValue();\r
+               return val;\r
+       }\r
+}\r
+\r
+mtTime\r
+runTime() :\r
+{\r
+       mtTime time;\r
+}\r
+{\r
+       <RUNTIME> time=time()\r
+       {\r
+               return time;\r
+       }\r
+}\r
+\r
+Vector\r
+cases() :\r
+{\r
+       Vector testCases = new Vector(5);       // start with 5\r
+}\r
+{\r
+       (testCase(testCases))+\r
+       {\r
+               return testCases;\r
+       }\r
+}\r
+\r
+\r
+\r
+void\r
+testCase(Vector testCases) :\r
+{\r
+       Token   t;\r
+       mtTestCase testCase = new mtTestCase();\r
+}\r
+{\r
+       <CASE> t=<WORD> caseInfo(testCase)\r
+       {\r
+               testCase.setName(t.image);\r
+               testCases.addElement(testCase);\r
+       }\r
+}\r
+\r
+\r
+Vector\r
+init() :\r
+{\r
+       Vector testCases = new Vector(5);       // start with 5\r
+}\r
+{\r
+       (initCase(testCases))+ \r
+       {\r
+               return testCases;\r
+       }\r
+}\r
+\r
+\r
+\r
+void\r
+initCase(Vector testCases) :\r
+{\r
+       Token   t;\r
+       mtTestCase testCase = new mtTestCase();\r
+}\r
+{\r
+       <INIT> t=<WORD> caseInfo(testCase)\r
+       {\r
+               testCase.setName(t.image);\r
+               testCases.addElement(testCase);\r
+       }\r
+}\r
+\r
+Vector\r
+last() :\r
+{\r
+       Vector testCases = new Vector(1);       // start with 1\r
+}\r
+{\r
+       (lastCase(testCases))+ \r
+       {\r
+               return testCases;\r
+       }\r
+}\r
+\r
+\r
+\r
+void\r
+lastCase(Vector testCases) :\r
+{\r
+       Token   t;\r
+       mtTestCase testCase = new mtTestCase();\r
+}\r
+{\r
+       <LAST> t=<WORD> caseInfo(testCase)\r
+       {\r
+               testCase.setName(t.image);\r
+               testCases.addElement(testCase);\r
+       }\r
+}\r
+\r
+void\r
+caseInfo(mtTestCase testCase) :\r
+{\r
+       String  file;\r
+       String  prop = null;\r
+       int     weight = 50;\r
+       Hashtable errorList = null;\r
+       String  description = null;\r
+}\r
+{\r
+       file=scriptFile() \r
+       {\r
+               testCase.setFile(file);\r
+       }\r
+\r
+       [ prop=propFile() ]\r
+       {\r
+               testCase.setPropFile(prop);\r
+       }\r
+\r
+       [ weight=weight() ]\r
+       {\r
+               testCase.setWeight(weight);\r
+       } \r
+\r
+       [ errorList=ignoreErrors() ] \r
+       {\r
+               if (errorList == null)\r
+                       errorList = new Hashtable();\r
+\r
+               testCase.setIgnoreErrors(errorList);\r
+       }\r
+\r
+       [ description=description() ]\r
+       {\r
+               testCase.setDescription(description);\r
+       }\r
+}\r
+\r
+\r
+String\r
+scriptFile() :\r
+{\r
+       Token   t;\r
+}\r
+{\r
+       <FILE> t=<WORD>\r
+       {\r
+               return t.image;\r
+       }\r
+}\r
+\r
+\r
+String\r
+propFile() :\r
+{\r
+       Token   t;\r
+}\r
+{\r
+       <PROPERTIES> t=<WORD>\r
+       {\r
+               return t.image;\r
+       }\r
+}\r
+\r
+int\r
+weight() :\r
+{\r
+       Token   t;\r
+}\r
+{\r
+       <WEIGHT> t=<INT>\r
+       {\r
+               int val = Integer.decode(t.image).intValue();\r
+               if (val > 100 || val < 1)\r
+               {\r
+                       System.out.println("LINE "+t.beginLine +": Weight '"+t.image\r
+                                                       +"' is invalid, must be between 1..100"\r
+                                                       +" -- defaulting to 50.");\r
+                       val = 50;\r
+               }\r
+               return val;     \r
+       }\r
+}\r
+\r
+String \r
+description() :\r
+{\r
+       Token   t;\r
+}\r
+{\r
+       <DESCRIPTION> t=<STRING>\r
+       {\r
+               return t.image;\r
+       }       \r
+}\r
+\r
+Hashtable\r
+ignoreErrors() :\r
+{\r
+       // note: we need a non-null errorlist even\r
+       // if there is nothing in it\r
+       Hashtable errorList = new Hashtable();\r
+}\r
+{\r
+       <IGNOREERRORS> getError(errorList) (<COMMA> getError(errorList))*\r
+       {\r
+               return errorList;\r
+       }\r
+}\r
+\r
+void\r
+getError(Hashtable errorList) :\r
+{\r
+       String  s;\r
+}\r
+{\r
+       s=word_or_int()\r
+       {\r
+               if (errorList == null)\r
+               {\r
+               }\r
+               errorList.put(s, new Integer(0));\r
+       }\r
+}\r
+\r
+String\r
+word_or_int() :\r
+{\r
+       Token   t;\r
+}\r
+{\r
+       t=<WORD>\r
+       {\r
+               return t.image;\r
+       }\r
+|      t=<INT>\r
+       {\r
+               return t.image;\r
+       }\r
+}\r
+\r
+/*\r
+** Possible formats:\r
+**\r
+**     HH:MM:SS\r
+**        MM:SS\r
+**           SS\r
+*/\r
+mtTime\r
+time() :\r
+{\r
+       Token h, m, s;\r
+}\r
+{\r
+       LOOKAHEAD(4) h=<INT> <COLON> m=<INT> <COLON> s=<INT>\r
+       {\r
+               return new mtTime(\r
+                               Integer.decode(h.image).intValue(),\r
+                               Integer.decode(m.image).intValue(),\r
+                               Integer.decode(s.image).intValue());\r
+       }\r
+|      LOOKAHEAD(2) m=<INT> <COLON> s=<INT> \r
+       {\r
+               return new mtTime(\r
+                               0,\r
+                               Integer.decode(m.image).intValue(),\r
+                               Integer.decode(s.image).intValue());\r
+       }\r
+|      s=<INT>\r
+       {\r
+               return new mtTime(\r
+                               0,\r
+                               0,\r
+                               Integer.decode(s.image).intValue());\r
+       }\r
+}      \r