add more, GlobalConstruct parsed
[cdsspec-compiler.git] / grammer / spec-compiler.jj
index bfcd6b99825b7c67e90facd45552b29ddae044a3..a006e7bca3e5a463650b80f917e11477270df1d0 100644 (file)
@@ -24,7 +24,8 @@
        @Commit_point_set:
                IDENTIFIER | IDENTIFIER ...
        @Condition: ... (Optional)
        @Commit_point_set:
                IDENTIFIER | IDENTIFIER ...
        @Condition: ... (Optional)
-       @HB_Condition: ...
+       @HB_Condition:
+               IDENTIFIER :: <C_CPP_Condition>
        @HB_Condition: ...
        @ID: ... (Optional, use default ID)
        @Check: (Optional)
        @HB_Condition: ...
        @ID: ... (Optional, use default ID)
        @Check: (Optional)
@@ -69,7 +70,15 @@ package edu.uci.eecs.specCompiler.grammerParser;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 
-       class SpecParser {
+import edu.uci.eecs.specCompiler.specExtraction.Construct;
+import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
+
+       public class SpecParser {
                public static void main(String[] argvs)
                throws ParseException, TokenMgrError {
                        try {
                public static void main(String[] argvs)
                throws ParseException, TokenMgrError {
                        try {
@@ -200,10 +209,26 @@ TOKEN :
        <LESS_THAN: "<">
 |
        <GREATER_THAN: ">">
        <LESS_THAN: "<">
 |
        <GREATER_THAN: ">">
+|
+       <GREATER_EQUALS: ">=">
+|
+       <LESS_EQUALS: "<=">
+|
+       <LOGICAL_EQUALS: "==">
+|
+       <NOT_EQUALS: "!=">
+|
+       <LOGICAL_AND: "&&">
+|
+       <LOGICAL_OR: "||">
+|
+       <XOR: "^">
 |
        <QUESTION_MARK: "?">
 |
        <COLON: ":">
 |
        <QUESTION_MARK: "?">
 |
        <COLON: ":">
+|
+       <DOUBLECOLON: "::">
 |
        <SEMI_COLON: ";">
 |
 |
        <SEMI_COLON: ";">
 |
@@ -263,28 +288,42 @@ TOKEN :
        < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ >
 }
 
        < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ >
 }
 
-void Start() :
-{}
+Construct Start() :
+{
+       Construct res;  
+}
 {
        (
 {
        (
-       LOOKAHEAD(3) Global_construct() |
-       LOOKAHEAD(3) Interface() |
-       LOOKAHEAD(3) Potential_commit_point_define() |
-       LOOKAHEAD(3) Commit_point_define() |
-       LOOKAHEAD(3) Commit_point_define_check()
+       LOOKAHEAD(3) res = Global_construct() |
+       LOOKAHEAD(3) res = Interface() |
+       LOOKAHEAD(3) res = Potential_commit_point_define() |
+       LOOKAHEAD(3) res = Commit_point_define() |
+       LOOKAHEAD(3) res = Commit_point_define_check()
        )
        <EOF>
        )
        <EOF>
+       { return res; }
 }
 
 }
 
-void Global_construct() :
+GlobalConstruct Global_construct() :
 {
 {
+       GlobalConstruct res;
+       String code;
 }
 {
 }
 {
+       { res = null; }
        <HEAD>
                <BEGIN> 
        <HEAD>
                <BEGIN> 
-                       Global_define() (Interface_clusters())? (Happens_before())?
+                       (code = Global_define())
+                       { res = new GlobalConstruct(code); }
+                       (Interface_clusters(res))?
+                       (Happens_before(res))?
                <END>
        <TAIL>
                <END>
        <TAIL>
+       {
+               res.unfoldInterfaceCluster();
+               System.out.println(res);
+               return res;
+       }
 }
 
 String C_CPP_CODE() :
 }
 
 String C_CPP_CODE() :
@@ -302,62 +341,100 @@ String C_CPP_CODE() :
        t = <OPEN_BRACKET> | t = <CLOSE_BRACKET> | t = <HB_SYMBOL> | t = <COMMA> |
        t = <DOT> | t = <STAR> | t = <NEGATE> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
        t = <PLUSPLUS> | t = <MINUS> | t = <MINUSMINUS> | t = <DIVIDE> | t = <BACKSLASH> |
        t = <OPEN_BRACKET> | t = <CLOSE_BRACKET> | t = <HB_SYMBOL> | t = <COMMA> |
        t = <DOT> | t = <STAR> | t = <NEGATE> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
        t = <PLUSPLUS> | t = <MINUS> | t = <MINUSMINUS> | t = <DIVIDE> | t = <BACKSLASH> |
-       t = <LESS_THAN> | t = <GREATER_THAN> | t = <QUESTION_MARK> | t = <COLON> |
+       t = <LESS_THAN> | t = <GREATER_THAN> | t = <GREATER_EQUALS>     | t = <LESS_EQUALS> |
+       t = <LOGICAL_EQUALS> | t = <NOT_EQUALS> | t = <LOGICAL_AND> | t = <LOGICAL_OR> | t = <XOR>
+       t = <QUESTION_MARK> | t = <COLON> | t = <DOUBLECOLON> |
        t = <SEMI_COLON> | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
        t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL>
        )
        {
                text.append(t.image);
        t = <SEMI_COLON> | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
        t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL>
        )
        {
                text.append(t.image);
-               text.append("\n");
+               if (t.image.equals(";") || t.image.equals("\\")
+                       || t.image.equals("{") || t.image.equals("}"))
+                       text.append("\n");
+               else
+                       text.append(" ");
        }
        )+
        {
        }
        )+
        {
-               System.out.println(text);
+               //System.out.println(text);
                return text.toString();
        }
 }
 
                return text.toString();
        }
 }
 
-void Global_define() :
-{}
+String Global_define() :
 {
 {
-       <GLOBAL_DEFINE> C_CPP_CODE()
+       String code;    
+}
+{
+       <GLOBAL_DEFINE> (code = C_CPP_CODE())
+       {
+               return code;
+       }
 }
 
 }
 
-void Conditional_interface() :
-{}
+ConditionalInterface Conditional_interface() :
 {
 {
-       <IDENTIFIER> (<OPEN_BRACKET> <IDENTIFIER> <CLOSE_BRACKET>)*
+       String interfaceName, hbConditionLabel;
+}
+{
+       {
+               hbConditionLabel = "";
+       }
+       interfaceName = <IDENTIFIER>.image (<OPEN_BRACKET> hbConditionLabel =
+       <IDENTIFIER>.image <CLOSE_BRACKET>)?
+       {
+               return new ConditionalInterface(interfaceName, hbConditionLabel);
+       }
 }
 
 }
 
-void Interface_cluster() :
-{}
+void Interface_cluster(GlobalConstruct inst) :
+{
+       String clusterName;
+       ConditionalInterface condInterface;
+}
 {
 {
-       <IDENTIFIER> <EQUALS> <OPEN_PAREN>
-               Conditional_interface() (<COMMA> Conditional_interface())*
+       (clusterName= <IDENTIFIER>.image)
+       <EQUALS> <OPEN_PAREN>
+               (condInterface = Conditional_interface()
+               { inst.addInterface2Cluster(clusterName, condInterface); } 
+               )
+               (<COMMA> condInterface = Conditional_interface()
+               { inst.addInterface2Cluster(clusterName, condInterface); } 
+               )*
        <CLOSE_PAREN>
 }
 
        <CLOSE_PAREN>
 }
 
-void Interface_clusters() :
+void Interface_clusters(GlobalConstruct inst) :
 {}
 {
 {}
 {
-       <INTERFACE_CLUSTER> (Interface_cluster())+
+       <INTERFACE_CLUSTER> (Interface_cluster(inst))+
 }
 
 }
 
-void Happens_before() :
-{}
+void Happens_before(GlobalConstruct inst) :
 {
 {
-       <HAPPENS_BEFORE> (Conditional_interface() <HB_SYMBOL> Conditional_interface())+
+       ConditionalInterface left, right;       
+}
+{
+       <HAPPENS_BEFORE> 
+       (
+       left = Conditional_interface() <HB_SYMBOL> right = Conditional_interface()
+       { inst.addHBCondition(left, right); }
+       )+
 }
 
 }
 
-void Interface() :
-{}
+InterfaceConstruct Interface() :
+{
+       InterfaceConstruct res; 
+}
 {
 {
+       { res = null; }
        <HEAD> 
                <BEGIN>
                        <INTERFACE> <IDENTIFIER>
                        <COMMIT_POINT_SET> <IDENTIFIER> (<OR> <IDENTIFIER>)*
                        (<CONDITION> C_CPP_CODE())?
        <HEAD> 
                <BEGIN>
                        <INTERFACE> <IDENTIFIER>
                        <COMMIT_POINT_SET> <IDENTIFIER> (<OR> <IDENTIFIER>)*
                        (<CONDITION> C_CPP_CODE())?
-                       (<HB_CONDITION> C_CPP_CODE())*
+                       (<HB_CONDITION> <IDENTIFIER> C_CPP_CODE())*
                        (<ID> C_CPP_CODE())?
                        (<CHECK> C_CPP_CODE())?
                        (<ACTION> C_CPP_CODE())?
                        (<ID> C_CPP_CODE())?
                        (<CHECK> C_CPP_CODE())?
                        (<ACTION> C_CPP_CODE())?
@@ -365,23 +442,33 @@ void Interface() :
                        (<POST_CHECK> C_CPP_CODE())?
                <END>
        <TAIL>
                        (<POST_CHECK> C_CPP_CODE())?
                <END>
        <TAIL>
+       { return res; }
 }
 
 }
 
-void Potential_commit_point_define() :
-{}
+PotentialCPDefineConstruct Potential_commit_point_define() :
+{
+       PotentialCPDefineConstruct res; 
+}
 {
 {
+
+       { res = null; }
        <HEAD> 
                <BEGIN>
                        <POTENTIAL_COMMIT_POINT_DEFINE> C_CPP_CODE()
                        <LABEL> <IDENTIFIER>
                <END>
        <TAIL>
        <HEAD> 
                <BEGIN>
                        <POTENTIAL_COMMIT_POINT_DEFINE> C_CPP_CODE()
                        <LABEL> <IDENTIFIER>
                <END>
        <TAIL>
+       { return res; }
 }
 
 
 }
 
 
-void Commit_point_define() :
-{}
+CPDefineConstruct Commit_point_define() :
+{
+       CPDefineConstruct res;  
+}
 {
 {
+
+       { res = null; }
        <HEAD> 
                <BEGIN>
                        <COMMIT_POINT_DEFINE> C_CPP_CODE()
        <HEAD> 
                <BEGIN>
                        <COMMIT_POINT_DEFINE> C_CPP_CODE()
@@ -389,16 +476,22 @@ void Commit_point_define() :
                        <LABEL> <IDENTIFIER>
                <END>
        <TAIL>
                        <LABEL> <IDENTIFIER>
                <END>
        <TAIL>
+       { return res; }
 }
 
 
 }
 
 
-void Commit_point_define_check() :
-{}
+CPDefineCheckConstruct Commit_point_define_check() :
 {
 {
+       CPDefineCheckConstruct res;     
+}
+{
+
+       { res = null; }
        <HEAD> 
                <BEGIN> 
                        <COMMIT_POINT_DEFINE_CHECK> C_CPP_CODE()
                        <LABEL> <IDENTIFIER>
                <END>
        <TAIL>
        <HEAD> 
                <BEGIN> 
                        <COMMIT_POINT_DEFINE_CHECK> C_CPP_CODE()
                        <LABEL> <IDENTIFIER>
                <END>
        <TAIL>
+       { return res; }
 }
 }