add spsc
[cdsspec-compiler.git] / grammer / spec_compiler.jj
index 24accc9e998f4db7add1c3bea0ac1501abb57112..a58db9347203fc66501838f5d550ea623db450f7 100644 (file)
@@ -30,7 +30,7 @@
        
        b) Interface construct
        @Begin
-       @Interface: ...
+       @Interface_decl: ...
        @Commit_point_set:
                IDENTIFIER | IDENTIFIER ...
        @Condition: ... (Optional)
        @Begin
        @Interface_define: <Interface_Name>
        @End
+
+       g) Interface declare & define construct
+       @Begin
+       @Interface_decl_define: <Interface_Name>
+       @Commit_point_set:
+               IDENTIFIER | IDENTIFIER ...
+       @Condition: ... (Optional)
+       @HB_Condition:
+               IDENTIFIER :: <C_CPP_Condition>
+       @HB_Condition: ...
+       @ID: ... (Optional, use default ID)
+       @Check: (Optional)
+               ...
+       @Action: (Optional)
+               ...
+       @Post_action: (Optional)
+       @Post_check: (Optional)
+       @End
+
 */
 
 
@@ -162,7 +181,7 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
                        return null;
                }
 
-               public static ArrayList<String> getTemplateArg(String line)
+               public static ArrayList<VariableDeclaration> getTemplateArg(String line)
                throws ParseException {
                        InputStream input = new ByteArrayInputStream(line.getBytes());
                        SpecParser parser = new SpecParser(input);
@@ -187,6 +206,55 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
                        return sb.toString();
                }
 
+               /**
+               boolean spaceSeparator(Token t) {
+                       switch (t.image) {
+                               case "[":
+                               case "]":
+                               case "=":
+                               case "(":
+                               case ")":
+                               case ",":
+                               case ".":
+                               case "*":
+                               case "~":
+                               case "!":
+                               case "&":
+                               case "|":
+                               case "%":
+                               case "+":
+                               case "-":
+                               case "/":
+                               case "<":
+                               case ">":
+                               case "<=":
+                               case ">=":
+                               case "==":
+                               case "!=":
+                               case "&&":
+                               case "||":
+                               case "^":
+                               case "?":
+                               case ":":
+                               case "::":
+                               case "<<":
+                               case ">>":
+                               case ">>>":
+                               case "+=":
+                               case "-=":
+                               case "*=":
+                               case "/=":
+                               case "%=":
+                               case "^=":
+                               case "&=":
+                               case ";":
+                                       return false;
+                               default:
+                                       return true;
+                       }
+               }
+               */
+
        }
 PARSER_END(SpecParser)
 
@@ -315,6 +383,8 @@ SKIP : {
        <INLINE: "inline">
 |
        <STATIC: "static">
+|
+       <FOR: "for">
 |
        <#DIGIT: ["0"-"9"]>
 |
@@ -344,6 +414,8 @@ SKIP : {
 |
 /*   C/C++ only token*/
        <DOT: ".">
+|
+       <DOLLAR: "$">
 |
        <STAR: "*">
 |
@@ -414,7 +486,6 @@ SKIP : {
        <OR_EQUALS: "|=">
 |
        <AND_EQUALS: "&=">
-
 |
        <SEMI_COLON: ";">
 |
@@ -596,22 +667,31 @@ QualifiedName ParseQualifiedName() :
        }
 }
 
-ArrayList<String> TemplateParamList() :
+ArrayList<VariableDeclaration> TemplateParamList() :
 {
-       ArrayList<String> params;
-       String str;
+       ArrayList<VariableDeclaration> params;
+       String type;
+       String name;
 }
 {
        {
-               params = new ArrayList<String>();
+               params = new ArrayList<VariableDeclaration>();
        }
        <TEMPLATE>
        "<"
-       (str = <IDENTIFIER>.image 
-       str = <IDENTIFIER>.image {params.add(str);})
+       (type = <IDENTIFIER>.image 
+       name = <IDENTIFIER>.image
+       {
+               params.add(new VariableDeclaration(type, name));
+       }
+       )
 
-       ("," str = <IDENTIFIER>.image 
-       str = <IDENTIFIER>.image {params.add(str);})*
+       ("," type = <IDENTIFIER>.image 
+       name = <IDENTIFIER>.image
+       {
+               params.add(new VariableDeclaration(type, name));
+       }
+       )*
        ">"
        {
                //System.out.println(params);
@@ -648,12 +728,16 @@ VariableDeclaration TypeParam() :
        }
 }
 
+
+
 ArrayList<String> C_CPP_CODE(ArrayList<String> headers) :
 {
        String text;
        Token t;
        boolean newLine = false;
+       boolean newSpace = true;
        boolean inTemplate = false;
+       boolean inForLoop = false;
        ArrayList<String> content;
        String header;
 }
@@ -669,6 +753,7 @@ ArrayList<String> C_CPP_CODE(ArrayList<String> headers) :
        t = <CONST> | t = <STRUCT> | t = <CLASS> | t = <UNSIGNED> |
        (t = <TEMPLATE> { inTemplate = true;  })|
        t = <STATIC> | t = <INLINE> |
+       (t = <FOR> { inForLoop = true; })|
        (t = <INCLUDE>
        {
                header = t.image;
@@ -679,11 +764,11 @@ ArrayList<String> C_CPP_CODE(ArrayList<String> headers) :
        })
        | t = <IDENTIFIER> | t = <POUND> |
        (t = <OPEN_BRACE>  { newLine = true; } ) |
-       (t = <CLOSE_BRACE>  { newLine = true; } ) | 
+       (t = <CLOSE_BRACE>  { newLine = true; inForLoop = false;} ) | 
        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 = <EXCLAMATION> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
+       t = <DOT> | t = <STAR> | t = <DOLLAR> | t = <NEGATE> | t = <EXCLAMATION> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
        t = <PLUSPLUS> | t = <MINUS> | t = <MINUSMINUS> | t = <DIVIDE> | t = <BACKSLASH> |
        t = <LESS_THAN> |
        (t = <GREATER_THAN> { if (inTemplate) newLine = true; }) |
@@ -703,7 +788,7 @@ ArrayList<String> C_CPP_CODE(ArrayList<String> headers) :
        t = <OR_EQUALS> |
        t = <AND_EQUALS> |
 
-       (t = <SEMI_COLON> { newLine = true; } )
+       (t = <SEMI_COLON> { if (!inForLoop) newLine = true; } )
        | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
        t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL> |
        (t = <DEFINE> { newLine = true; } )
@@ -711,8 +796,17 @@ ArrayList<String> C_CPP_CODE(ArrayList<String> headers) :
        {
                if (text.equals("")) {
                        text = t.image;
+                       newSpace = true;
                } else {
                        text = text + " " + t.image;
+                       /*
+                       if (newSpace && spaceSeparator(t)) {
+                               text = text + " " + t.image;
+                       } else {
+                               text = text + t.image;
+                               if (spaceSeparator(t))
+                                       newSpace = true;
+                       }*/
                }
                if (newLine) {
                        content.add(text);