X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=blobdiff_plain;f=grammer%2Fspec_compiler.jj;h=9195e13a6c70a479d44ade76a9d27658de8299a2;hp=22fada84bf025aaee801daa7da9d01569a3f9729;hb=7919b41aeee6c8d5f572299f80f2e91d389ae164;hpb=e8466e30b587947c60bbba7df22b8b0908c75f26 diff --git a/grammer/spec_compiler.jj b/grammer/spec_compiler.jj index 22fada8..9195e13 100644 --- a/grammer/spec_compiler.jj +++ b/grammer/spec_compiler.jj @@ -16,6 +16,7 @@ # entry point. LANG = C; @Global_define: + @DeclareStruct: @DeclareVar: @InitVar: @DefineFunc: @@ -23,13 +24,18 @@ @DefineFunc: @Interface_cluster: ... - @Happens-before: + @Happens_before: ... + @Commutativity: // This is to define the admissibility condition + // Enq <-> Enq (_M1.q != _M2.q) + // Enq <-> Deq (_M1.q != _M2.q) + // Deq <-> Deq (_M1.q != _M2.q) + // Enq <-> Deq (_M1.q == _M2.q && _M2.__RET__ == NULL) @End b) Interface construct @Begin - @Interface: ... + @Interface_decl: ... @Commit_point_set: IDENTIFIER | IDENTIFIER ... @Condition: ... (Optional) @@ -49,19 +55,53 @@ @Begin @Potential_commit_point_define: ... @Label: ... + @End + + OR + + @Begin + @Potential_additional_ordering_point_define: ... + @Label: ... @End d) Commit point define construct @Begin @Commit_point_define_check: ... @Label: ... + @End + + OR + + # Addition ordering point is used to order operations when there are "equal" + # commit point operations on the same location and that we cannot decide + # which operation goes first, we will use additional ordering point to order + # them (it's just similar to commit points). In implementation, we can just + # treat them as commit points with a special flag. + + @Begin + @Additional_ordering_point_define: ... + @Potential_additional_ordering_point_label: ... + @Label: ... @End OR + + @Begin + @Additional_ordering_point_define: ... + @Label: ... + @End + + OR @Begin - @Commit_point_define: ... - @Potential_commit_point_label: ... + @Additional_ordering_point_define_check: ... + @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 @@ -74,6 +114,25 @@ @Begin @Interface_define: @End + + g) Interface declare & define construct + @Begin + @Interface_decl_define: + @Commit_point_set: + IDENTIFIER | IDENTIFIER ... + @Condition: ... (Optional) + @HB_Condition: + IDENTIFIER :: + @HB_Condition: ... + @ID: ... (Optional, use default ID) + @Check: (Optional) + ... + @Action: (Optional) + ... + @Post_action: (Optional) + @Post_check: (Optional) + @End + */ @@ -94,13 +153,16 @@ 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; import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct; import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct; +import edu.uci.eecs.specCompiler.specExtraction.CommutativityRule; 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.SequentialDefineSubConstruct; import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct; @@ -121,7 +183,7 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration; public static void main(String[] argvs) throws ParseException, TokenMgrError { try { - File f = new File("./grammer/spec.txt"); + File f = new File("./grammer/spec1.txt"); FileInputStream fis = new FileInputStream(f); SpecParser parser = new SpecParser(fis); @@ -137,6 +199,7 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration; System.out.println(constructs.get(i)); } + //parser.Test(); System.out.println("Parsing finished!"); } catch (FileNotFoundException e) { @@ -160,7 +223,14 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration; return null; } - public static ArrayList getTemplateArg(String line) + + private static ArrayList breakLines(String all) { + String lines[] = all.split("[\\r\\n]+"); + return new ArrayList(Arrays.asList(lines)); + } + + + public static ArrayList getTemplateArg(String line) throws ParseException { InputStream input = new ByteArrayInputStream(line.getBytes()); SpecParser parser = new SpecParser(input); @@ -177,18 +247,69 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration; public static String stringArray2String(ArrayList 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 : + SKIP : { " " | @@ -217,6 +338,10 @@ SKIP : { "/*": IN_COMMENT } + TOKEN: { + +} + <*> SKIP : { // "//" comment for the specification <"//" (~["\n", "\r"])* (["\n", "\r"])> @@ -241,16 +366,22 @@ SKIP : { | +| + | | +| + | | | +| + | | @@ -281,18 +412,28 @@ SKIP : { | +| + | | +| + | +| + +| + | +| + } - TOKEN : + TOKEN : { /* Specification & C/C++ shared tokens */ // Reserved keywords @@ -301,8 +442,16 @@ SKIP : { | +| + | +| + +| + +| + | <#DIGIT: ["0"-"9"]> | @@ -327,11 +476,15 @@ SKIP : { | "> +| + "> | | /* C/C++ only token*/ +| + | | @@ -380,6 +533,28 @@ SKIP : { | +| + +| + >"> +| + >>"> +| + +| + | @@ -456,10 +631,10 @@ String Type() : } { { type = ""; } - ("const" + ( { type = "const"; } )? - (((str = .image | str = .image) { type = type + " " + str; })? + (((str = .image | str = .image | str = .image) { type = type + " " + str; })? ( name = ParseQualifiedName() { if (!type.equals("")) @@ -468,7 +643,7 @@ String Type() : type = name.fullName; }) ) - ((str = "const".image { + ((str = .image { if (!type.equals("")) type = type + " " + str; else @@ -492,23 +667,6 @@ String Type() : } } -void Test() : -{ - String str; - FunctionHeader func; -} -{ - /* - str = Type() - { - System.out.println(str); - } - */ - func = FuncDecl() - { - System.out.println(func); - } -} String ParameterizedName() : { @@ -517,8 +675,8 @@ String ParameterizedName() : } { (str = .image {res = str;}) - ("<" str = .image { res = res + "<" + str; } - ("," str = .image { res = res + ", " + str; })* ">" + ( str = Type() { res = res + "<" + str; } + ( str = Type() { res = res + ", " + str; })* { res = res + ">"; } )? { @@ -533,6 +691,7 @@ FunctionHeader FuncDecl() : ArrayList args; } { + ( | )* ret = Type() funcName = ParseQualifiedName() args = FormalParamList() @@ -559,23 +718,32 @@ QualifiedName ParseQualifiedName() : } } -ArrayList TemplateParamList() : +ArrayList TemplateParamList() : { - ArrayList params; - String str; + ArrayList params; + String type; + String name; } { { - params = new ArrayList(); + params = new ArrayList(); }