parsing passed
[cdsspec-compiler.git] / grammer / spec-compiler.jj
index a006e7bca3e5a463650b80f917e11477270df1d0..ca38b5facb925cb5208d3bf36b535214c16c3c1f 100644 (file)
@@ -69,6 +69,9 @@ package edu.uci.eecs.specCompiler.grammerParser;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 
 import edu.uci.eecs.specCompiler.specExtraction.Construct;
 import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
@@ -301,7 +304,10 @@ Construct Start() :
        LOOKAHEAD(3) res = Commit_point_define_check()
        )
        <EOF>
-       { return res; }
+       {
+               System.out.println(res);
+               return res;
+       }
 }
 
 GlobalConstruct Global_construct() :
@@ -321,7 +327,6 @@ GlobalConstruct Global_construct() :
        <TAIL>
        {
                res.unfoldInterfaceCluster();
-               System.out.println(res);
                return res;
        }
 }
@@ -425,73 +430,128 @@ void Happens_before(GlobalConstruct inst) :
 
 InterfaceConstruct Interface() :
 {
-       InterfaceConstruct res; 
+       InterfaceConstruct res;
+       String interfaceName, condition, idCode, check, action, postAction,
+               postCheck, commitPoint, hbLabel, hbCondition;
+       ArrayList<String> commitPointSet;
+       HashMap<String, String> hbConditions;
 }
 {
-       { res = null; }
+       {
+               res = null;
+               condition = "";
+               idCode = "";
+               check = "";
+               action = "";
+               postAction = "";
+               postCheck = "";
+               commitPointSet = new ArrayList<String>();
+               hbConditions = new HashMap<String, String>();
+       }
        <HEAD> 
                <BEGIN>
-                       <INTERFACE> <IDENTIFIER>
-                       <COMMIT_POINT_SET> <IDENTIFIER> (<OR> <IDENTIFIER>)*
-                       (<CONDITION> C_CPP_CODE())?
-                       (<HB_CONDITION> <IDENTIFIER> C_CPP_CODE())*
-                       (<ID> C_CPP_CODE())?
-                       (<CHECK> C_CPP_CODE())?
-                       (<ACTION> C_CPP_CODE())?
-                       (<POST_ACTION> C_CPP_CODE())?
-                       (<POST_CHECK> C_CPP_CODE())?
+                       <INTERFACE> (interfaceName = <IDENTIFIER>.image)
+                       <COMMIT_POINT_SET>
+                               (commitPoint = <IDENTIFIER>.image
+                               { commitPointSet.add(commitPoint); }
+                               )
+                               (<OR>
+                                       (commitPoint = <IDENTIFIER>.image)
+                                       {
+                                               if (commitPointSet.contains(commitPoint)) {
+                                                       throw new ParseException(interfaceName + " has" +
+                                                               "duplicate commit point labels");
+                                               }
+                                               commitPointSet.add(commitPoint);
+                                       }
+                               )*
+
+                       (<CONDITION> (condition = C_CPP_CODE()))?
+                       (
+                               <HB_CONDITION>
+                               (hbLabel = <IDENTIFIER>.image)
+                               (hbCondition = C_CPP_CODE())
+                               {
+                                       if (hbConditions.containsKey(hbLabel)) {
+                                               throw new ParseException(interfaceName + " has" +
+                                                       "duplicate happens-before condtion labels");
+                                       }
+                                       hbConditions.put(hbLabel, hbCondition);
+                               }
+                       )*
+                       (<ID> (idCode = C_CPP_CODE()))?
+                       (<CHECK> (check = C_CPP_CODE()))?
+                       (<ACTION> (action = C_CPP_CODE()))?
+                       (<POST_ACTION> (postAction = C_CPP_CODE()))?
+                       (<POST_CHECK> (postCheck = C_CPP_CODE()))?
                <END>
        <TAIL>
-       { return res; }
+       {
+               res = new InterfaceConstruct(interfaceName, commitPointSet, condition,
+                       hbConditions, idCode, check, action, postAction, postCheck);
+               return res;
+       }
 }
 
 PotentialCPDefineConstruct Potential_commit_point_define() :
 {
-       PotentialCPDefineConstruct res; 
+       PotentialCPDefineConstruct res;
+       String label, condition;
 }
 {
 
        { res = null; }
        <HEAD> 
                <BEGIN>
-                       <POTENTIAL_COMMIT_POINT_DEFINE> C_CPP_CODE()
-                       <LABEL> <IDENTIFIER>
+                       <POTENTIAL_COMMIT_POINT_DEFINE> (condition = C_CPP_CODE())
+                       <LABEL> (label = <IDENTIFIER>.image)
                <END>
        <TAIL>
-       { return res; }
+       {
+               res = new PotentialCPDefineConstruct(label, condition); 
+               return res;
+       }
 }
 
 
 CPDefineConstruct Commit_point_define() :
 {
-       CPDefineConstruct res;  
+       CPDefineConstruct res;
+       String label, potentialCPLabel, condition;
 }
 {
 
        { res = null; }
        <HEAD> 
                <BEGIN>
-                       <COMMIT_POINT_DEFINE> C_CPP_CODE()
-                       <POTENTIAL_COMMIT_POINT_LABEL> <IDENTIFIER>
-                       <LABEL> <IDENTIFIER>
+                       <COMMIT_POINT_DEFINE> (condition = C_CPP_CODE())
+                       <POTENTIAL_COMMIT_POINT_LABEL> (potentialCPLabel = <IDENTIFIER>.image)
+                       <LABEL> (label = <IDENTIFIER>.image)
                <END>
        <TAIL>
-       { return res; }
+       {
+               res = new CPDefineConstruct(label, potentialCPLabel, condition);
+               return res;
+       }
 }
 
 
 CPDefineCheckConstruct Commit_point_define_check() :
 {
        CPDefineCheckConstruct res;     
+       String label, condition;
 }
 {
 
        { res = null; }
        <HEAD> 
                <BEGIN> 
-                       <COMMIT_POINT_DEFINE_CHECK> C_CPP_CODE()
-                       <LABEL> <IDENTIFIER>
+                       <COMMIT_POINT_DEFINE_CHECK> (condition = C_CPP_CODE())
+                       <LABEL> (label = <IDENTIFIER>.image)
                <END>
        <TAIL>
-       { return res; }
+       {
+               res = new CPDefineCheckConstruct(label, condition);
+               return res;
+       }
 }