X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=grammer%2Fspec-compiler.jj;h=bfcd6b99825b7c67e90facd45552b29ddae044a3;hb=b1e52c7b681a0bc2704509b63a8907b3004901b3;hp=45960880b935606614470f42822555d1aea74a53;hpb=542a00635aafcb2b664e4d15be95f11df7ff0c81;p=cdsspec-compiler.git diff --git a/grammer/spec-compiler.jj b/grammer/spec-compiler.jj index 4596088..bfcd6b9 100644 --- a/grammer/spec-compiler.jj +++ b/grammer/spec-compiler.jj @@ -1,5 +1,63 @@ /* spec-compiler.jj Grammer definition for the specification */ + +/* + SPEC constructs: + Each construct should be embraced by /DOUBLE_STAR ... STAR/ annotation. + Within there, any line beginning with a "#" is a comment of the annotation. + Each constrcut should begin with @Begin and end with @End. Otherwise, the + annotation would be considered as normal comments of the source. + + a) Global construct + @Begin + @Global_define: + ... + @Interface_cluster: + ... + @Happens-before: + ... + @End + + b) Interface construct + @Begin + @Interface: ... + @Commit_point_set: + IDENTIFIER | IDENTIFIER ... + @Condition: ... (Optional) + @HB_Condition: ... + @HB_Condition: ... + @ID: ... (Optional, use default ID) + @Check: (Optional) + ... + @Action: (Optional) + ... + @Post_action: (Optional) + @Post_check: (Optional) + @End + + c) Potential commit construct + @Begin + @Potential_commit_point_define: ... + @Label: ... + @End + + d) Commit point define construct + @Begin + @Commit_point_define_check: ... + @Label: ... + @End + + OR + + @Begin + @Commit_point_define: ... + @Potential_commit_point_label: ... + @Label: ... + @End +*/ + + + options { STATIC = false; JAVA_UNICODE_ESCAPE = true; @@ -8,24 +66,46 @@ options { PARSER_BEGIN(SpecParser) package edu.uci.eecs.specCompiler.grammerParser; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + class SpecParser { public static void main(String[] argvs) throws ParseException, TokenMgrError { - SpecParser parser = new SpecParser(System.in); - parser.Start(); - System.out.println("Parsing finished!"); + try { + FileInputStream fis = new FileInputStream("./grammer/spec.txt"); + SpecParser parser = new SpecParser(fis); + parser.Start(); + System.out.println("Parsing finished!"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } } } PARSER_END(SpecParser) -SKIP : {" " | "\n" | "\r" | "\r\n" | } - -TOKEN : +SKIP : { - + " " +| + "\n" +| + "\r" +| + "\r\n" +| + "\t" | - "#" (~["\n", "\r"])* ["\n", "\r"]> + // "#" comment for the specification + <"#" (~["\n", "\r"])* (["\n", "\r"])> | + // "//" comment for the specification + <"//" (~["\n", "\r"])* (["\n", "\r"])> +} + +TOKEN : +{ +/* Above are specification-only tokens */ | @@ -34,11 +114,291 @@ TOKEN : | | - + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + + + +/* Specification & C/C++ shared tokens */ +| + <#DIGIT: ["0"-"9"]> +| + <#LETTER: ["a"-"z", "A"-"Z"]> +| + | "_") ( | | "_")*> +| + +| + +| + +| + +| + "> +| + + +| +/* C/C++ only token*/ + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + +| + "> +| + +| + +| + +| + +| + +| + < INTEGER_LITERAL: + (["l","L"])? + | (["l","L"])? + | (["l","L"])?> +| + < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > +| + < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > +| + < #OCTAL_LITERAL: "0" (["0"-"7"])* > +| + < FLOATING_POINT_LITERAL: + + | > +| + < #DECIMAL_FLOATING_POINT_LITERAL: + (["0"-"9"])+ "." (["0"-"9"])* ()? (["f","F","d","D"])? + | "." (["0"-"9"])+ ()? (["f","F","d","D"])? + | (["0"-"9"])+ (["f","F","d","D"])? + | (["0"-"9"])+ ()? ["f","F","d","D"]> +| + < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > +| + < #HEXADECIMAL_FLOATING_POINT_LITERAL: + "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])+ (".")? (["f","F","d","D"])? + | "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])* "." (["0"-"9","a"-"f","A"-"F"])+ (["f","F","d","D"])?> +| + < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ > } void Start() : {} { - + ( + LOOKAHEAD(3) Global_construct() | + LOOKAHEAD(3) Interface() | + LOOKAHEAD(3) Potential_commit_point_define() | + LOOKAHEAD(3) Commit_point_define() | + LOOKAHEAD(3) Commit_point_define_check() + ) + +} + +void Global_construct() : +{ +} +{ + + + Global_define() (Interface_clusters())? (Happens_before())? + + +} + +String C_CPP_CODE() : +{ + StringBuilder text; + Token t; +} +{ + { + text = new StringBuilder(); + t = new Token(); + } + (( + t = | t = | t = | t = | + t = | t = | t = | t = | + t = | t = | t = | t = | t = | t = | t = | + t = | t = | t = | t = | t = | + t = | t = | t = | t = | + t = | t = | t = | + t = | t = + ) + { + text.append(t.image); + text.append("\n"); + } + )+ + { + System.out.println(text); + return text.toString(); + } +} + +void Global_define() : +{} +{ + C_CPP_CODE() +} + +void Conditional_interface() : +{} +{ + ( )* +} + +void Interface_cluster() : +{} +{ + + Conditional_interface() ( Conditional_interface())* + +} + +void Interface_clusters() : +{} +{ + (Interface_cluster())+ +} + +void Happens_before() : +{} +{ + (Conditional_interface() Conditional_interface())+ +} + +void Interface() : +{} +{ + + + + ( )* + ( C_CPP_CODE())? + ( C_CPP_CODE())* + ( C_CPP_CODE())? + ( C_CPP_CODE())? + ( C_CPP_CODE())? + ( C_CPP_CODE())? + ( C_CPP_CODE())? + + +} + +void Potential_commit_point_define() : +{} +{ + + + C_CPP_CODE() +