X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=grammer%2Fspec_compiler.jj;h=575dcf32b569fcf2aec4b24a1ebea85031760497;hb=a0721aba5feb313cce48120d4e98e0165bb476bc;hp=93a5d8b07f7985553c9439a2601a73d3a1770ab2;hpb=f2d6efad8b1ee05ef5dd12175af9e59e61c7b8f8;p=cdsspec-compiler.git diff --git a/grammer/spec_compiler.jj b/grammer/spec_compiler.jj index 93a5d8b..575dcf3 100644 --- a/grammer/spec_compiler.jj +++ b/grammer/spec_compiler.jj @@ -30,7 +30,7 @@ b) Interface construct @Begin - @Interface: ... + @Interface_decl: ... @Commit_point_set: IDENTIFIER | IDENTIFIER ... @Condition: ... (Optional) @@ -50,19 +50,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 + @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_define: ... - @Potential_commit_point_label: ... + @Commit_point_clear: ... @Label: ... @End @@ -75,6 +109,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 + */ @@ -95,6 +148,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; @@ -102,6 +156,7 @@ 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.SequentialDefineSubConstruct; import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct; @@ -122,10 +177,10 @@ 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); - /* + ArrayList content = new ArrayList(); ArrayList constructs = new ArrayList(); ArrayList headers = new ArrayList(); @@ -137,9 +192,9 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration; for (int i = 0; i < constructs.size(); i++) { System.out.println(constructs.get(i)); } - */ - parser.Test(); + + //parser.Test(); System.out.println("Parsing finished!"); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -162,7 +217,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); @@ -179,18 +241,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 : { " " | @@ -219,6 +332,10 @@ SKIP : { "/*": IN_COMMENT } + TOKEN: { + +} + <*> SKIP : { // "//" comment for the specification <"//" (~["\n", "\r"])* (["\n", "\r"])> @@ -285,18 +402,28 @@ SKIP : { | +| + | | +| + | +| + +| + | +| + } - TOKEN : + TOKEN : { /* Specification & C/C++ shared tokens */ // Reserved keywords @@ -309,6 +436,12 @@ SKIP : { | +| + +| + +| + | <#DIGIT: ["0"-"9"]> | @@ -338,6 +471,8 @@ SKIP : { | /* C/C++ only token*/ +| + | | @@ -386,6 +521,28 @@ SKIP : { | +| + +| + >"> +| + >>"> +| + +| + | @@ -462,7 +619,7 @@ String Type() : } { { type = ""; } - ("const" + ( { type = "const"; } )? (((str = .image | str = .image | str = .image) { type = type + " " + str; })? @@ -474,7 +631,7 @@ String Type() : type = name.fullName; }) ) - ((str = "const".image { + ((str = .image { if (!type.equals("")) type = type + " " + str; else @@ -498,25 +655,6 @@ String Type() : } } -void Test() : -{ - String str; - FunctionHeader func; -} -{ - /* - str = Type() - { - System.out.println(str); - } - */ - func = FuncDecl() - { - System.out.println(func); - } - - -} String ParameterizedName() : { @@ -525,8 +663,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 + ">"; } )? { @@ -541,6 +679,7 @@ FunctionHeader FuncDecl() : ArrayList args; } { + ( | )* ret = Type() funcName = ParseQualifiedName() args = FormalParamList() @@ -567,23 +706,32 @@ QualifiedName ParseQualifiedName() : } } -ArrayList TemplateParamList() : +ArrayList TemplateParamList() : { - ArrayList params; - String str; + ArrayList params; + String type; + String name; } { { - params = new ArrayList(); + params = new ArrayList(); }