SpecExtractor.java seems to work
[cdsspec-compiler.git] / grammer / spec-compiler.jj
index 45960880b935606614470f42822555d1aea74a53..f7a4248d377c41f64cb7ef3c7b69009e29432d18 100644 (file)
@@ -1,5 +1,61 @@
 /* spec-compiler.jj Grammer definition for the specification */
 
+
+/*
+       SPEC constructs:
+       Each construct should be embraced by /DOUBLE_STAR ... STAR/ annotation.
+       Within there, any line beginning with a "#" is a comment of the annotation.
+       Each constrcut should begin with @Begin and end with @End. Otherwise, the
+       annotation would be considered as normal comments of the source.
+       
+       a) Global construct
+       @Begin
+       @Global_define:
+               ...
+       @Interface_cluster:
+               ...
+       @Happens-before:
+               ...
+       @End
+       
+       b) Interface construct
+       @Begin
+       @Interface: ...
+       @Commit_point_set:
+               ...
+       @Condition: ... (Optional)
+       @ID: ... (Optional, use default ID)
+       @Check: (Optional)
+               ...
+       @Action: (Optional)
+               ...
+       @Post_action: (Optional)
+       @Post_check: (Optional)
+       @End
+
+       c) Potential commit construct
+       @Begin
+       @Potential_commit_point_define: ...
+       @Label: ...
+       @End
+
+       d) Commit point define construct
+       @Begin
+       @Commit_point_define_check: ...
+       @Label: ...
+       @End
+       
+               OR
+
+       @Begin
+       @Commit_point_define: ...
+       @Potential_commit_point_label: ...
+       @Label: ...
+       @End
+*/
+
+
+
 options {
        STATIC = false;
        JAVA_UNICODE_ESCAPE = true;
@@ -8,24 +64,47 @@ options {
 PARSER_BEGIN(SpecParser)
 package edu.uci.eecs.specCompiler.grammerParser;
 
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
        class SpecParser {
                public static void main(String[] argvs)
                throws ParseException, TokenMgrError {
-                       SpecParser parser = new SpecParser(System.in);
-                       parser.Start();
-                       System.out.println("Parsing finished!");
+                       try {
+                               FileInputStream fis = new FileInputStream("./grammer/spec.txt");
+                               SpecParser parser = new SpecParser(fis);
+                               parser.Start();
+                               System.out.println("Parsing finished!");
+                       } catch (FileNotFoundException e) {
+                               e.printStackTrace();
+                       }
                }
        }
 PARSER_END(SpecParser)
 
-SKIP : {" " | "\n" | "\r" | "\r\n" | <COMMENT>}
-
-TOKEN :
+SKIP :
 {
-       <SPACE: (" " | "\t")+>
+       " "
+|
+       "\n"
+|
+       "\r"
+|
+       "\r\n"
+|
+       "\t"
+       /*
 |
-       <COMMENT: <SPACE> "#" (~["\n", "\r"])* ["\n", "\r"]>
+       // "#" comment for the specification
+       <"#" (~["\n", "\r"])* (["\n", "\r"])>
 |
+       // "//" comment for the specification
+       <"//" (~["\n", "\r"])* (["\n", "\r"])>
+       */
+}
+
+TOKEN :
+{
        <HEAD: "/**">
 |
        <TAIL: "*/">
@@ -34,11 +113,132 @@ TOKEN :
 |
        <END: "@End">
 |
-       
+       <GLOBAL_DEFINE: "@Global_define:">
+|
+       <INTERFACE_CLUSTER: "@Interface_cluster:">
+|
+       <HAPPENS_BEFORE: "@Happens_before:">
+|
+       <INTERFACE: "@Interface:">
+|
+       <COMMIT_POINT_SET: "@Commit_point_set:">
+|
+       <CONDITION: "@Condition:">
+|
+       <HB_CONDITIONS: "@HB_condition:">
+|
+       <ID: "@ID:">
+|
+       <CHECK: "@Check:">
+|
+       <ACTION: "@Action:">
+|
+       <POST_ACTION: "@Post_action:">
+|
+       <POST_CHECK: "@Post_check:">
+|
+       <POTENTIAL_COMMIT_POINT_DEFINE: "@Potential_commit_point_define:">
+|
+       <LABEL: "@Label:">
+|
+       <COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
+|
+       <COMMIT_POINT_DEFINE: "@Commit_point_define:">
+|
+       <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
+|
+       <#DIGIT: ["0"-"9"]>
+|
+       <#LETTER: ["a"-"z", "A"-"Z"]>
+|
+       <IDENTIFIER: <LETTER> (<LETTER> | <DIGIT> | "_")>       
 }
 
 void Start() :
 {}
 {
-       <HEAD> <BEGIN> <END> <TAIL> <EOF>
+       //Global_construct() <EOF>
+       <EOF>
+       //<IDENTIFIER> <EOF>
+}
+
+void Global_construct() :
+{}
+{
+       <HEAD>
+               <BEGIN> 
+                       //Global_define() (Interface_cluster())? (Happens_before())?
+               <END>
+       <TAIL>
+}
+
+void C_CPP_CODE() :
+{String code;}
+{
+       <(~["@"])+>
+}
+
+void Global_define() :
+{}
+{
+       <GLOBAL_DEFINE> C_CPP_CODE()
+}
+
+void Conditional_interface() :
+{}
+{
+       <IDENTIFIER> (<"(" <IDENTIFIER> ")"> | "")
+}
+
+void Interface_cluster() :
+{}
+{
+       <IDENTIFIER> "=" "{" Conditional_interface() (",," Conditional_interface())* "}"
+}
+
+void Interface_clusters() :
+{}
+{
+       <INTERFACE_CLUSTER> (Interface_cluster())+
+}
+
+void Happens_before() :
+{}
+{
+       <HAPPENS_BEFORE> (Conditional_interface()  "->" Conditional_interface())+
+}
+
+void Interface() :
+{}
+{
+       <TAIL>
+}
+
+void Potential_commit_point_define() :
+{}
+{
+       <HEAD> 
+               <BEGIN> 
+               <END>
+       <TAIL>
+}
+
+
+void Commit_point_define() :
+{}
+{
+       <HEAD> 
+               <BEGIN> 
+               <END>
+       <TAIL>
+}
+
+
+void Commit_point_define_check() :
+{}
+{
+       <HEAD> 
+               <BEGIN> 
+               <END>
+       <TAIL>
 }