X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=grammer%2Fspec_compiler.jj;h=43faebf46a2222051b09295db1b19fbc44f3baed;hb=eeea572e974cb93f35d6788250d011a031ffba2f;hp=6a4f61bcace484318977d6568d704f66e42da959;hpb=24022553f123d8f8a796b257410b4c1c1b9ef8ee;p=cdsspec-compiler.git diff --git a/grammer/spec_compiler.jj b/grammer/spec_compiler.jj index 6a4f61b..43faebf 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) @@ -66,6 +66,13 @@ @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 @@ -75,6 +82,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 +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; @@ -102,6 +129,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 +150,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 +165,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 +190,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); @@ -187,12 +222,61 @@ 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) -<*> SKIP : + SKIP : { " " | @@ -221,6 +305,10 @@ SKIP : { "/*": IN_COMMENT } + TOKEN: { + +} + <*> SKIP : { // "//" comment for the specification <"//" (~["\n", "\r"])* (["\n", "\r"])> @@ -293,12 +381,14 @@ SKIP : { | +| + | } - TOKEN : + TOKEN : { /* Specification & C/C++ shared tokens */ // Reserved keywords @@ -315,6 +405,8 @@ SKIP : { | +| + | <#DIGIT: ["0"-"9"]> | @@ -344,6 +436,8 @@ SKIP : { | /* C/C++ only token*/ +| + | | @@ -392,6 +486,28 @@ SKIP : { | +| + +| + >"> +| + >>"> +| + +| + | @@ -468,7 +584,7 @@ String Type() : } { { type = ""; } - ("const" + ( { type = "const"; } )? (((str = .image | str = .image | str = .image) { type = type + " " + str; })? @@ -480,7 +596,7 @@ String Type() : type = name.fullName; }) ) - ((str = "const".image { + ((str = .image { if (!type.equals("")) type = type + " " + str; else @@ -504,24 +620,6 @@ String Type() : } } -void Test() : -{ - String str; - FunctionHeader func; -} -{ - /* - str = Type() - { - System.out.println(str); - } - */ - func = FuncDecl() - { - System.out.println(func); - } - -} String ParameterizedName() : { @@ -530,8 +628,8 @@ String ParameterizedName() : } { (str = .image {res = str;}) - ("<" str = Type() { res = res + "<" + str; } - ("," str = Type() { res = res + ", " + str; })* ">" + ( str = Type() { res = res + "<" + str; } + ( str = Type() { res = res + ", " + str; })* { res = res + ">"; } )? { @@ -573,23 +671,32 @@ QualifiedName ParseQualifiedName() : } } -ArrayList TemplateParamList() : +ArrayList TemplateParamList() : { - ArrayList params; - String str; + ArrayList params; + String type; + String name; } { { - params = new ArrayList(); + params = new ArrayList(); }