add more to spec-compiler.jj
authorPeizhao Ou <peizhaoo@uci.edu>
Thu, 10 Oct 2013 23:23:32 +0000 (16:23 -0700)
committerPeizhao Ou <peizhaoo@uci.edu>
Thu, 10 Oct 2013 23:23:32 +0000 (16:23 -0700)
grammer/spec-compiler.jj
src/edu/uci/eecs/specCompiler/specExtraction/SpecExtractor.java

index 110dcb9..bfcd6b9 100644 (file)
        @Begin
        @Interface: ...
        @Commit_point_set:
-               ...
+               IDENTIFIER | IDENTIFIER ...
        @Condition: ... (Optional)
+       @HB_Condition: ...
+       @HB_Condition: ...
        @ID: ... (Optional, use default ID)
        @Check: (Optional)
                ...
@@ -93,18 +95,17 @@ SKIP :
        "\r\n"
 |
        "\t"
-       /*
 |
        // "#" comment for the specification
        <"#" (~["\n", "\r"])* (["\n", "\r"])>
 |
        // "//" comment for the specification
        <"//" (~["\n", "\r"])* (["\n", "\r"])>
-       */
 }
 
 TOKEN :
 {
+/*   Above are specification-only tokens   */
        <HEAD: "/**">
 |
        <TAIL: "*/">
@@ -125,7 +126,7 @@ TOKEN :
 |
        <CONDITION: "@Condition:">
 |
-       <HB_CONDITIONS: "@HB_condition:">
+       <HB_CONDITION: "@HB_condition:">
 |
        <ID: "@ID:">
 |
@@ -146,67 +147,194 @@ TOKEN :
        <COMMIT_POINT_DEFINE: "@Commit_point_define:">
 |
        <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
+
+
+/*   Specification & C/C++ shared tokens   */
 |
        <#DIGIT: ["0"-"9"]>
 |
        <#LETTER: ["a"-"z", "A"-"Z"]>
 |
-       <IDENTIFIER: <LETTER> (<LETTER> | <DIGIT> | "_")*>
+       <IDENTIFIER: (<LETTER> | "_") (<LETTER> | <DIGIT> | "_")*>
 |
        <EQUALS: "=">
 |
-       <LEFT_PARAN: "{">
+       <OPEN_PAREN: "{">
+|
+       <CLOSE_PAREN: "}">
 |
-       <RIGHT_PARAN: "}">
+       <OPEN_BRACKET: "(">
+|
+       <CLOSE_BRACKET: ")">
 |
        <HB_SYMBOL: "->">
 |
        <COMMA: ",">
+
+|
+/*   C/C++ only token*/
+       <DOT: ".">
+|
+       <STAR: "*">
+|
+       <NEGATE: "~">
+|
+       <AND: "&">
+|
+       <OR: "|">
+|
+       <MOD: "%">
+|
+       <PLUS: "+">
+|
+       <PLUSPLUS: "++">
+|
+       <MINUS: "-">
+|
+       <MINUSMINUS: "--">
+|
+       <DIVIDE: "/">
+|
+       <BACKSLASH: "\\">
+|
+       <LESS_THAN: "<">
+|
+       <GREATER_THAN: ">">
+|
+       <QUESTION_MARK: "?">
+|
+       <COLON: ":">
+|
+       <SEMI_COLON: ";">
+|
+       <STRING_LITERAL:
+       "\""
+       ((~["\"","\\","\n","\r"])
+       | ("\\"
+               ( ["n","t","b","r","f","\\","'","\""]
+               | ["0"-"7"] ( ["0"-"7"] )?
+               | ["0"-"3"] ["0"-"7"]
+                       ["0"-"7"]
+               )
+               )
+       )*
+       "\"">
+|
+       <CHARACTER_LITERAL:
+       "'"
+       ((~["'","\\","\n","\r"])
+       | ("\\"
+               (["n","t","b","r","f","\\","'","\""]
+               | ["0"-"7"] ( ["0"-"7"] )?
+               | ["0"-"3"] ["0"-"7"]
+               ["0"-"7"]
+               )
+               )
+       )
+       "'">
+|
+       < INTEGER_LITERAL:
+        <DECIMAL_LITERAL> (["l","L"])?
+      | <HEX_LITERAL> (["l","L"])?
+      | <OCTAL_LITERAL> (["l","L"])?>
+|
+       < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+|
+       < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+|
+       < #OCTAL_LITERAL: "0" (["0"-"7"])* >
+|
+       < FLOATING_POINT_LITERAL:
+        <DECIMAL_FLOATING_POINT_LITERAL>
+      | <HEXADECIMAL_FLOATING_POINT_LITERAL> >
+|
+       < #DECIMAL_FLOATING_POINT_LITERAL:
+        (["0"-"9"])+ "." (["0"-"9"])* (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
+      | "." (["0"-"9"])+ (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
+      | (["0"-"9"])+ <DECIMAL_EXPONENT> (["f","F","d","D"])?
+      | (["0"-"9"])+ (<DECIMAL_EXPONENT>)? ["f","F","d","D"]>
+|
+       < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+|
+       < #HEXADECIMAL_FLOATING_POINT_LITERAL:
+        "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])+ (".")? <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?
+      | "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])* "." (["0"-"9","a"-"f","A"-"F"])+ <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?>
+|
+       < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ >
 }
 
 void Start() :
 {}
 {
-       //Global_construct() <EOF>
-       <IDENTIFIER> <EOF>
-       //<IDENTIFIER> C_CPP_CODE() <EOF>
+       (
+       LOOKAHEAD(3) Global_construct() |
+       LOOKAHEAD(3) Interface() |
+       LOOKAHEAD(3) Potential_commit_point_define() |
+       LOOKAHEAD(3) Commit_point_define() |
+       LOOKAHEAD(3) Commit_point_define_check()
+       )
+       <EOF>
 }
 
 void Global_construct() :
-{}
+{
+}
 {
        <HEAD>
                <BEGIN> 
-                       Global_define() (Interface_cluster())? (Happens_before())?
+                       Global_define() (Interface_clusters())? (Happens_before())?
                <END>
        <TAIL>
 }
 
-/*
-void C_CPP_CODE() :
-{}
+String C_CPP_CODE() :
 {
-       <(~["@"])+>
+       StringBuilder text;
+       Token t;
 }
-*/
+{
+       {
+               text = new StringBuilder();
+               t = new Token();
+       }
+       ((
+       t = <IDENTIFIER> | t = <EQUALS> | t = <OPEN_PAREN> | t = <CLOSE_PAREN> |
+       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 = <SEMI_COLON> | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
+       t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL>
+       )
+       {
+               text.append(t.image);
+               text.append("\n");
+       }
+       )+
+       {
+               System.out.println(text);
+               return text.toString();
+       }
+}
+
 void Global_define() :
 {}
 {
-       <GLOBAL_DEFINE> //C_CPP_CODE()
+       <GLOBAL_DEFINE> C_CPP_CODE()
 }
 
 void Conditional_interface() :
 {}
 {
-       <IDENTIFIER> (<"(" <IDENTIFIER> ")">)*
+       <IDENTIFIER> (<OPEN_BRACKET> <IDENTIFIER> <CLOSE_BRACKET>)*
 }
 
 void Interface_cluster() :
 {}
 {
-       <IDENTIFIER> <EQUALS> <LEFT_PARAN>
+       <IDENTIFIER> <EQUALS> <OPEN_PAREN>
                Conditional_interface() (<COMMA> Conditional_interface())*
-       <RIGHT_PARAN>
+       <CLOSE_PAREN>
 }
 
 void Interface_clusters() :
@@ -224,6 +352,18 @@ void Happens_before() :
 void Interface() :
 {}
 {
+       <HEAD> 
+               <BEGIN>
+                       <INTERFACE> <IDENTIFIER>
+                       <COMMIT_POINT_SET> <IDENTIFIER> (<OR> <IDENTIFIER>)*
+                       (<CONDITION> C_CPP_CODE())?
+                       (<HB_CONDITION> 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())?
+               <END>
        <TAIL>
 }
 
@@ -231,7 +371,9 @@ void Potential_commit_point_define() :
 {}
 {
        <HEAD> 
-               <BEGIN> 
+               <BEGIN>
+                       <POTENTIAL_COMMIT_POINT_DEFINE> C_CPP_CODE()
+                       <LABEL> <IDENTIFIER>
                <END>
        <TAIL>
 }
@@ -241,7 +383,10 @@ void Commit_point_define() :
 {}
 {
        <HEAD> 
-               <BEGIN> 
+               <BEGIN>
+                       <COMMIT_POINT_DEFINE> C_CPP_CODE()
+                       <POTENTIAL_COMMIT_POINT_LABEL> <IDENTIFIER>
+                       <LABEL> <IDENTIFIER>
                <END>
        <TAIL>
 }
@@ -252,6 +397,8 @@ void Commit_point_define_check() :
 {
        <HEAD> 
                <BEGIN> 
+                       <COMMIT_POINT_DEFINE_CHECK> C_CPP_CODE()
+                       <LABEL> <IDENTIFIER>
                <END>
        <TAIL>
 }
index 0c06bad..dc24b28 100644 (file)
@@ -8,8 +8,6 @@ import java.io.IOException;
 import java.io.LineNumberReader;
 import java.util.ArrayList;
 
-import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils.Text;
-
 /**
  * <p>
  * This class represents the specification extractor of the specification. The