changes
[cdsspec-compiler.git] / grammer / spec_compiler.jj
index 440007ad07fed8c985a509fc1daf800dba463080..43faebf46a2222051b09295db1b19fbc44f3baed 100644 (file)
                # entry point.
                LANG = C;
        @Global_define:
+               @DeclareStruct:
                @DeclareVar:
                @InitVar:
                @DefineFunc:
                ...
+               @DefineFunc:
        @Interface_cluster:
                ...
        @Happens-before:
@@ -28,7 +30,7 @@
        
        b) Interface construct
        @Begin
-       @Interface: ...
+       @Interface_decl: ...
        @Commit_point_set:
                IDENTIFIER | IDENTIFIER ...
        @Condition: ... (Optional)
@@ -39,9 +41,6 @@
        @Check: (Optional)
                ...
        @Action: (Optional)
-               # Type here must be a pointer
-               @DefineVar: Type var1 = SomeExpression (Optional)
-               @Code (Optional)
                ...
        @Post_action: (Optional)
        @Post_check: (Optional)
        @Label: ...
        @End
 
+       // Commit point clear (just as a normal commit point, but it is used to
+       // clear all commit points)
+       @Begin
+       @Commit_point_clear: ...
+       @Label: ...
+       @End
+
        e) Entry point construct
        @Begin
        @Entry_point
        @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
+
 */
 
 
@@ -96,6 +121,7 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Arrays;
 
 import edu.uci.eecs.specCompiler.specExtraction.Construct;
 import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
@@ -103,15 +129,17 @@ 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.CPClearConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
-import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct;
-import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct.DefineVar;
 import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.EntryPointConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.ClassBeginConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.ClassEndConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.FunctionHeader;
+import edu.uci.eecs.specCompiler.specExtraction.QualifiedName;
+import edu.uci.eecs.specCompiler.specExtraction.SourceFileInfo;
+import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
 
        public class SpecParser {
                private static ArrayList<String> _content;
@@ -122,39 +150,54 @@ import edu.uci.eecs.specCompiler.specExtraction.FunctionHeader;
                public static void main(String[] argvs)
                throws ParseException, TokenMgrError {
                        try {
-                               String line = "int* A::B<sfd, _sdf>::id(const char * ch_ptr, int a)";
-                               System.out.println(parseFuncHeader(line));
-
-                               File f = new File("./grammer/spec.txt");
+                               File f = new File("./grammer/spec1.txt");
                                FileInputStream fis = new FileInputStream(f);
                                SpecParser parser = new SpecParser(fis);
-                               /**
+                               
                                ArrayList<String> content = new ArrayList<String>();
                                ArrayList<Construct> constructs = new ArrayList<Construct>();
-                               parser.Parse(f, content, constructs);
+                               ArrayList<String> headers = new ArrayList<String>();
+                               parser.Parse(f, content, constructs, headers);
                                for (int i = 0; i < content.size(); i++) {
                                        System.out.println(content.get(i));
                                }
-                               */
-                               parser.Test();
+                               
+                               for (int i = 0; i < constructs.size(); i++) {
+                                       System.out.println(constructs.get(i));
+                               }
+                               
+                               
+                               //parser.Test();
                                System.out.println("Parsing finished!");
                        } catch (FileNotFoundException e) {
                                e.printStackTrace();
                        }
                }
 
-               public static void ParseFile(File f, ArrayList<String> content, ArrayList<Construct> constructs)
+               public static SourceFileInfo ParseFile(File f)
                throws ParseException, TokenMgrError {
                        try {
                                InputStream input = new FileInputStream(f);
                                SpecParser parser = new SpecParser(input);
-                               parser.Parse(f, content, constructs);
+                               ArrayList<String> content = new ArrayList<String>(),
+                                       headers = new ArrayList<String>();
+                               ArrayList<Construct> constructs = new ArrayList<Construct>();
+                               parser.Parse(f, content, constructs, headers);
+                               return new SourceFileInfo(f, content, headers, constructs);
                        } catch (FileNotFoundException e) {
                                e.printStackTrace();
                        }
+                       return null;
                }
 
-               public static ArrayList<String> getTemplateArg(String line)
+
+               private static ArrayList<String> breakLines(String all) {
+                       String lines[] = all.split("[\\r\\n]+");
+                       return new ArrayList<String>(Arrays.asList(lines));
+               }
+
+
+               public static ArrayList<VariableDeclaration> getTemplateArg(String line)
                throws ParseException {
                        InputStream input = new ByteArrayInputStream(line.getBytes());
                        SpecParser parser = new SpecParser(input);
@@ -171,18 +214,69 @@ import edu.uci.eecs.specCompiler.specExtraction.FunctionHeader;
 
                public static String stringArray2String(ArrayList<String> content) {
                        StringBuilder sb = new StringBuilder();
+                       if (content.size() == 1)
+                               return content.get(0);
                        for (int i = 0; i < content.size(); i++) {
                                sb.append(content.get(i) + "\n");
                        }
                        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)
 
 
 
-<*> SKIP :
+<IN_POTENTIAL_SPEC, IN_SPEC> SKIP :
 {
        " "
 |
@@ -211,6 +305,10 @@ SKIP : {
        "/*": IN_COMMENT
 }
 
+<DEFAULT> TOKEN: {
+       <ANY: ~[]>
+}
+
 <*> SKIP : {
        // "//" comment for the specification
        <"//" (~["\n", "\r"])* (["\n", "\r"])>
@@ -235,6 +333,8 @@ SKIP : {
        <OPTIONS: "@Options:">
 |
        <GLOBAL_DEFINE: "@Global_define:">
+|
+       <DECLARE_STRUCT: "@DeclareStruct:">
 |
        <DECLARE_VAR: "@DeclareVar:">
 |
@@ -267,8 +367,6 @@ SKIP : {
        <CHECK: "@Check:">
 |
        <ACTION: "@Action:">
-|
-       <DEFINEVAR: "@DefineVar:">
 |
        <CODE: "@Code:">
 |
@@ -283,12 +381,14 @@ SKIP : {
        <COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
 |
        <COMMIT_POINT_DEFINE: "@Commit_point_define:">
+|
+       <COMMIT_POINT_CLEAR: "@Commit_point_clear:">
 |
        <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
 }
 
 
-<IN_SPEC, DEFAULT> TOKEN :
+<IN_SPEC> TOKEN :
 {
 /*   Specification & C/C++ shared tokens   */
 // Reserved keywords
@@ -297,8 +397,16 @@ SKIP : {
        <STRUCT: "struct">
 |
        <CLASS: "class">
+|
+       <UNSIGNED: "unsigned">
 |
        <TEMPLATE: "template">
+|
+       <INLINE: "inline">
+|
+       <STATIC: "static">
+|
+       <FOR: "for">
 |
        <#DIGIT: ["0"-"9"]>
 |
@@ -325,10 +433,11 @@ SKIP : {
        <HB_SYMBOL: "->">
 |
        <COMMA: ",">
-
 |
 /*   C/C++ only token*/
        <DOT: ".">
+|
+       <DOLLAR: "$">
 |
        <STAR: "*">
 |
@@ -377,6 +486,28 @@ SKIP : {
        <COLON: ":">
 |
        <DOUBLECOLON: "::">
+|
+       <DOUBLELESSTHAN: "<<">
+|
+       <DOUBLEGREATERTHAN: ">>">
+|
+       <TRIPLEGREATERTHAN: ">>>">
+|
+       <PLUS_EQUALS: "+=">
+|
+       <MINUS_EQUALS: "-=">
+|
+       <TIMES_EQUALS: "*=">
+|
+       <DIVIDE_EQUALS: "/=">
+|
+       <MOD_EQUALS: "%=">
+|
+       <XOR_EQUALS: "^=">
+|
+       <OR_EQUALS: "|=">
+|
+       <AND_EQUALS: "&=">
 |
        <SEMI_COLON: ";">
 |
@@ -449,29 +580,23 @@ String Type() :
 {
        String type;
        String str;
+       QualifiedName name;
 }
 {
        { type = ""; }
-       ("const"
+       (<CONST>
        { type = "const"; }
        )?
-       (((str = <STRUCT>.image | str = <CLASS>.image) { type = type + " " + str; })? 
-       (
-       str = QualifiedName() {
-               if (!type.equals(""))
-                       type = type + " " + str;
-               else
-                       type = str;
-       })
+       (((str = <STRUCT>.image | str = <CLASS>.image | str = <UNSIGNED>.image) { type = type + " " + str; })? 
        (
-       str = ParameterizedName() {
+       name = ParseQualifiedName() {
                if (!type.equals(""))
-                       type = type + " " + str;
+                       type = type + " " + name.fullName;
                else
-                       type = str;
+                       type = name.fullName;
        })
        )
-       ((str = "const".image {
+       ((str = <CONST>.image {
                if (!type.equals(""))
                        type = type + " " + str;
                else
@@ -495,12 +620,6 @@ String Type() :
        }
 }
 
-void Test() :
-{}
-{
-       Type()
-       //FuncDecl()
-}
 
 String ParameterizedName() :
 {
@@ -509,8 +628,8 @@ String ParameterizedName() :
 }
 {
        (str = <IDENTIFIER>.image {res = str;})
-       ("<" str = <IDENTIFIER>.image { res = res + "<" + str; }
-       ("," str = <IDENTIFIER>.image { res = res + ", " + str; })* ">"
+       (<OPEN_BRACKET> str = Type() { res = res + "<" + str; }
+       (<COMMA> str = Type() { res = res + ", " + str; })* <CLOSE_BRACKET>
        { res = res + ">"; }
        )?
        {
@@ -520,92 +639,111 @@ String ParameterizedName() :
 
 FunctionHeader FuncDecl() :
 {
-       String ret, qualifiedName, bareName;
-       ArrayList<String> args;
+       String ret;
+       QualifiedName funcName;
+       ArrayList<VariableDeclaration> args;
 }
 {
+       (<STATIC> | <INLINE>)*
        ret = Type() 
-       qualifiedName = QualifiedName() 
-       bareName = <IDENTIFIER>.image
+       funcName = ParseQualifiedName() 
        args = FormalParamList() 
        {
-               FunctionHeader res = new FunctionHeader(ret, qualifiedName, bareName, args);
+               FunctionHeader res = new FunctionHeader(ret, funcName, args);
                //System.out.println(res);
                return res;
        }
 }
 
-String QualifiedName() :
+QualifiedName ParseQualifiedName() :
 {
        String qualifiedName, str;
 }
 {
        { qualifiedName = ""; }
-       (LOOKAHEAD(2) (str = ParameterizedName() { qualifiedName = qualifiedName +
-       str + "::"; } <DOUBLECOLON> ))* 
+       (str = ParameterizedName() { qualifiedName = qualifiedName + str; } )
+       ( <DOUBLECOLON> (str = ParameterizedName() { qualifiedName = qualifiedName +
+       "::" + str; }  ))*
        {
-               return qualifiedName;
+               QualifiedName res = new QualifiedName(qualifiedName);
+               //System.out.println(res);
+               return res;
        }
 }
 
-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);})
+       <OPEN_BRACKET>
+       (type = <IDENTIFIER>.image 
+       name = <IDENTIFIER>.image
+       {
+               params.add(new VariableDeclaration(type, name));
+       }
+       )
 
-       ("," str = <IDENTIFIER>.image 
-       str = <IDENTIFIER>.image {params.add(str);})*
-       ">"
+       (<COMMA> type = <IDENTIFIER>.image 
+       name = <IDENTIFIER>.image
+       {
+               params.add(new VariableDeclaration(type, name));
+       }
+       )*
+       <CLOSE_BRACKET>
        {
                //System.out.println(params);
                return params;
        }
 }
 
-ArrayList<String> FormalParamList() :
+ArrayList<VariableDeclaration > FormalParamList() :
 {
-       ArrayList<String> typeParams;
+       ArrayList<VariableDeclaration > typeParams;
+       VariableDeclaration varDecl;
 }
 {
        {
-               typeParams = new ArrayList<String>();
+               typeParams = new ArrayList<VariableDeclaration >();
        }
-       "("
-       (TypeParam(typeParams) (<COMMA> TypeParam(typeParams))*)?
-       ")"
+       <OPEN_PAREN>
+       ((varDecl = TypeParam() {typeParams.add(varDecl);})
+       ((<COMMA> varDecl = TypeParam() {typeParams.add(varDecl);}))*)?
+       <CLOSE_PAREN>
        {
                return typeParams;
        }
 }
 
-void TypeParam(ArrayList<String> typeParams) :
+VariableDeclaration TypeParam() :
 {
        String type, param;
 }
 {
        (type = Type()) (param = <IDENTIFIER>.image)
        {
-               typeParams.add(type);
-               typeParams.add(param);
+               return new VariableDeclaration(type, param);
        }
 }
 
-ArrayList<String> C_CPP_CODE() :
+
+
+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;
 }
 {
        {
@@ -616,57 +754,134 @@ ArrayList<String> C_CPP_CODE() :
        (
        LOOKAHEAD(2)
        (
-       t = <CONST> | t = <STRUCT> | t = <CLASS> |
+       t = <CONST> | t = <STRUCT> | t = <CLASS> | t = <UNSIGNED> |
        (t = <TEMPLATE> { inTemplate = true;  })|
-       t = <IDENTIFIER> | t = <POUND> |
+       t = <STATIC> | t = <INLINE> |
+       (t = <FOR> { inForLoop = true; })|
+       (t = <INCLUDE>
+       {
+               header = t.image;
+               newLine = true;
+               if (headers != null) {
+                       headers.add(header.substring(header.lastIndexOf(' ') + 1));
+               }
+       })
+       | 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; }) |
        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> { newLine = true; } )
+       t = <DOUBLELESSTHAN> | 
+       t = <DOUBLEGREATERTHAN> |
+       t = <TRIPLEGREATERTHAN> | 
+
+       t = <PLUS_EQUALS> |
+       t = <MINUS_EQUALS> |
+       t = <TIMES_EQUALS> |
+       t = <DIVIDE_EQUALS> |
+       t = <MOD_EQUALS> |
+       t = <XOR_EQUALS> |
+       t = <OR_EQUALS> |
+       t = <AND_EQUALS> |
+
+       (t = <SEMI_COLON> { if (!inForLoop) newLine = true; } )
        | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
        t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL> |
-       (t = <INCLUDE> { newLine = true; } ) |
        (t = <DEFINE> { newLine = true; } )
        )
        {
-               text = text + " " + t.image;
+               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);
                        text = "";
                        newLine = false;
+                       inTemplate = false;
                }
        }
        )+
 
        {
+               if (content.size() == 0) {
+                       content.add(text);
+               }
                return content;
        }
 }
 
 
-void Parse(File f, ArrayList<String> content, ArrayList<Construct> constructs) :
+void Parse(File f, ArrayList<String> content, ArrayList<Construct> constructs, ArrayList<String> headers) :
 {
        Construct inst;
-       ArrayList<String> code;
+       StringBuilder sb;
+       boolean flushSB;
 }
 {
        {
                _file = f;
                _content = content;
                _constructs = constructs;
+               sb = new StringBuilder();
+       }
+       (
+       (inst = ParseSpec()
+       {
+               _constructs.add(inst);
+       }
+       ) |
+       //((code = C_CPP_CODE(headers)) { _content.addAll(code); })
+       (
+       flushSB = OriginalCode(sb)
+       {
+               if (flushSB) {
+                       sb = new StringBuilder();
+               }
+       }
+       )
+       )* 
+       // For the last piece of code
+       {
+               _content.add(sb.toString());
+       }
+       <EOF>
+}
+
+// If true, there's a new line and sb should be flushed
+boolean OriginalCode(StringBuilder sb) :
+{
+       String str;
+}
+{
+       str = <ANY>.image
+       {
+               if (!str.equals("\n")) {
+                       sb.append(str);
+                       return false;
+               } else {
+                       _content.add(sb.toString());
+                       return true;
+               }
        }
-       ((inst = ParseSpec() { _constructs.add(inst); }) |
-       ((code = C_CPP_CODE()) { _content.addAll(code); })
-       )* <EOF>
 }
 
 Construct ParseSpec() :
@@ -680,6 +895,7 @@ Construct ParseSpec() :
        LOOKAHEAD(2) res = Potential_commit_point_define() |
        LOOKAHEAD(2) res = Commit_point_define() |
        LOOKAHEAD(2) res = Commit_point_define_check() |
+       LOOKAHEAD(2) res = Commit_point_clear() |
        LOOKAHEAD(2) res = Entry_point() |
        LOOKAHEAD(2) res = Class_begin() |
        LOOKAHEAD(2) res = Class_end() |
@@ -730,21 +946,30 @@ GlobalConstruct Global_construct() :
 
 SequentialDefineSubConstruct Global_define() :
 {
-       String declareVar, initVar, defineFunc;
-       ArrayList<String> code;
+       ArrayList<String> initVar, defineFunc, code, declareStruct;
+       ArrayList<ArrayList<String>> defineFuncs;
+       ArrayList<VariableDeclaration> declareVars;
+       ArrayList<ArrayList<String>> declareStructs;
+       VariableDeclaration declareVar;
+
 }
 {
        {
-               declareVar = "";
-               initVar = "";
-               defineFunc = "";
+               declareVars = new ArrayList<VariableDeclaration>();
+               initVar = null;
+               defineFuncs = new ArrayList<ArrayList<String>>();
+               declareStructs = new ArrayList<ArrayList<String>>();
        }
        <GLOBAL_DEFINE>
-               (<DECLARE_VAR> (code = C_CPP_CODE() { declareVar = stringArray2String(code); } ))?
-       (<INIT_VAR> (code = C_CPP_CODE() { initVar = stringArray2String(code); } ))?
-       (<DEFINE_FUNC> (code = C_CPP_CODE() { defineFunc = stringArray2String(code); }))?
+       (<DECLARE_STRUCT> (declareStruct = C_CPP_CODE(null) {
+               declareStructs.add(declareStruct); }))*
+               (<DECLARE_VAR> ((declareVar = TypeParam() <SEMI_COLON> {
+                       declareVars.add(declareVar); } )*))?
+       (<INIT_VAR> (code = C_CPP_CODE(null) { initVar = code; } ))?
+       (<DEFINE_FUNC> (defineFunc = C_CPP_CODE(null) { defineFuncs.add(defineFunc); }))*
        {
-               SequentialDefineSubConstruct res = new SequentialDefineSubConstruct(declareVar, initVar, defineFunc);
+               SequentialDefineSubConstruct res = new
+                       SequentialDefineSubConstruct(declareStructs, declareVars, initVar, defineFuncs);
                //System.out.println(res);
                return res;
        }
@@ -758,8 +983,8 @@ ConditionalInterface Conditional_interface() :
        {
                hbConditionLabel = "";
        }
-       interfaceName = <IDENTIFIER>.image (<OPEN_BRACKET> hbConditionLabel =
-       <IDENTIFIER>.image <CLOSE_BRACKET>)?
+       interfaceName = <IDENTIFIER>.image (<OPEN_PAREN> hbConditionLabel =
+       <IDENTIFIER>.image <CLOSE_PAREN>)?
        {
                return new ConditionalInterface(interfaceName, hbConditionLabel);
        }
@@ -772,14 +997,14 @@ void Interface_cluster(GlobalConstruct inst) :
 }
 {
        (clusterName= <IDENTIFIER>.image)
-       <EQUALS> <OPEN_PAREN>
+       <EQUALS> <OPEN_BRACE>
                (condInterface = Conditional_interface()
                { inst.addInterface2Cluster(clusterName, condInterface); } 
                )
                (<COMMA> condInterface = Conditional_interface()
                { inst.addInterface2Cluster(clusterName, condInterface); } 
                )*
-       <CLOSE_PAREN>
+       <CLOSE_BRACE>
 }
 
 void Interface_clusters(GlobalConstruct inst) :
@@ -803,24 +1028,24 @@ void Happens_before(GlobalConstruct inst) :
 InterfaceConstruct Interface() :
 {
        InterfaceConstruct res;
-       String interfaceName, condition, idCode, check, postAction,
+       String interfaceName, condition, idCode, check,
                postCheck, commitPoint, hbLabel, hbCondition;
-       ActionSubConstruct action;
        ArrayList<String> commitPointSet;
+       ArrayList<String> action, postAction;
        HashMap<String, String> hbConditions;
        ArrayList<String> content;
 }
 {
        {
                res = null;
-               action = null;
+               action = new ArrayList<String>();
                condition = "";
                idCode = "";
                check = "";
-               postAction = "";
                postCheck = "";
                commitPointSet = new ArrayList<String>();
                hbConditions = new HashMap<String, String>();
+               postAction = new ArrayList<String>();
        }
                <BEGIN>
                        <INTERFACE> (interfaceName = <IDENTIFIER>.image)
@@ -839,11 +1064,11 @@ InterfaceConstruct Interface() :
                                        }
                                )*
 
-                       (<CONDITION> (content = C_CPP_CODE() { condition = stringArray2String(content); }))?
+                       (<CONDITION> (content = C_CPP_CODE(null) { condition = stringArray2String(content); }))?
                        (
                                <HB_CONDITION>
-                               (hbLabel = <IDENTIFIER>.image)
-                               (content = C_CPP_CODE() { hbCondition = stringArray2String(content); })
+                               (hbLabel = <IDENTIFIER>.image) <DOUBLECOLON>
+                               (content = C_CPP_CODE(null) { hbCondition = stringArray2String(content); })
                                {
                                        if (hbConditions.containsKey(hbLabel)) {
                                                throw new ParseException(interfaceName + " has" +
@@ -852,11 +1077,11 @@ InterfaceConstruct Interface() :
                                        hbConditions.put(hbLabel, hbCondition);
                                }
                        )*
-                       (<ID> (content = C_CPP_CODE() { idCode = stringArray2String(content); }))?
-                       (<CHECK> (content = C_CPP_CODE() { check = stringArray2String(content); }))?
-                       (action = Action())?
-                       (<POST_ACTION> (content = C_CPP_CODE() { postAction = stringArray2String(content); }))?
-                       (<POST_CHECK> (content = C_CPP_CODE() { postCheck = stringArray2String(content); }))?
+                       (<ID> (content = C_CPP_CODE(null) { idCode = stringArray2String(content); }))?
+                       (<CHECK> (content = C_CPP_CODE(null) { check = stringArray2String(content); }))?
+                       (<ACTION> action = C_CPP_CODE(null))?
+                       (<POST_ACTION> (postAction = C_CPP_CODE(null) ))?
+                       (<POST_CHECK> (content = C_CPP_CODE(null) { postCheck = stringArray2String(content); }))?
                <END>
        {
                res = new InterfaceConstruct(_file, _content.size(), interfaceName, commitPointSet, condition,
@@ -865,37 +1090,6 @@ InterfaceConstruct Interface() :
        }
 }
 
-ActionSubConstruct Action() :
-{
-       String type, name, expr, defineVarStr, code;
-       ArrayList<DefineVar> defineVars;
-       ArrayList<String> content;
-}
-{
-       {
-               defineVars = new ArrayList<DefineVar>();
-               code = "";
-       }
-       <ACTION>
-       (
-               (
-               (<DEFINEVAR> (content = C_CPP_CODE() { defineVarStr = stringArray2String(content); }) 
-               {
-                       int eqIdx = defineVarStr.indexOf('=');
-                       int typeEnd = defineVarStr.lastIndexOf(' ', eqIdx - 2);
-                       type = defineVarStr.substring(0, typeEnd);
-                       name = defineVarStr.substring(typeEnd + 1, eqIdx - 1);
-                       expr = defineVarStr.substring(eqIdx + 2);
-                       DefineVar defineVar = new DefineVar(type, name, expr);
-                       defineVars.add(defineVar);
-               })*  (<CODE> (content = C_CPP_CODE() { code = stringArray2String(content); }))? ) 
-       )
-       
-       {
-               ActionSubConstruct res = new ActionSubConstruct(defineVars, code);
-               return res;
-       }
-}
 
 PotentialCPDefineConstruct Potential_commit_point_define() :
 {
@@ -907,7 +1101,7 @@ PotentialCPDefineConstruct Potential_commit_point_define() :
 
        { res = null; }
                <BEGIN>
-                       <POTENTIAL_COMMIT_POINT_DEFINE> (content = C_CPP_CODE() { condition = stringArray2String(content); })
+                       <POTENTIAL_COMMIT_POINT_DEFINE> (content = C_CPP_CODE(null) { condition = stringArray2String(content); })
                        <LABEL> (label = <IDENTIFIER>.image)
                <END>
        {
@@ -927,7 +1121,7 @@ CPDefineConstruct Commit_point_define() :
 
        { res = null; }
                <BEGIN>
-                       <COMMIT_POINT_DEFINE> (content = C_CPP_CODE() { condition = stringArray2String(content); })
+                       <COMMIT_POINT_DEFINE> (content = C_CPP_CODE(null) { condition = stringArray2String(content); })
                        <POTENTIAL_COMMIT_POINT_LABEL> (potentialCPLabel = <IDENTIFIER>.image)
                        <LABEL> (label = <IDENTIFIER>.image)
                <END>
@@ -937,6 +1131,25 @@ CPDefineConstruct Commit_point_define() :
        }
 }
 
+CPClearConstruct Commit_point_clear() :
+{
+       CPClearConstruct res;   
+       String label, condition;
+       ArrayList<String> content;
+}
+{
+
+       { res = null; }
+               <BEGIN> 
+                       <COMMIT_POINT_CLEAR> (content = C_CPP_CODE(null) { condition = stringArray2String(content); })
+                       <LABEL> (label = <IDENTIFIER>.image)
+               <END>
+       {
+               res = new CPClearConstruct(_file, _content.size(), label, condition);
+               return res;
+       }
+}
+
 
 CPDefineCheckConstruct Commit_point_define_check() :
 {
@@ -948,7 +1161,7 @@ CPDefineCheckConstruct Commit_point_define_check() :
 
        { res = null; }
                <BEGIN> 
-                       <COMMIT_POINT_DEFINE_CHECK> (content = C_CPP_CODE() { condition = stringArray2String(content); })
+                       <COMMIT_POINT_DEFINE_CHECK> (content = C_CPP_CODE(null) { condition = stringArray2String(content); })
                        <LABEL> (label = <IDENTIFIER>.image)
                <END>
        {