X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=blobdiff_plain;f=grammer%2Fspec-compiler.jj;h=a006e7bca3e5a463650b80f917e11477270df1d0;hp=6ce449540a67b830787c8a5d8ca810b2d59d841f;hb=944b6af217212532a88e314df52a4cf5a99ed36a;hpb=a54d319679844e59186728d1f71322c3026148bf diff --git a/grammer/spec-compiler.jj b/grammer/spec-compiler.jj index 6ce4495..a006e7b 100644 --- a/grammer/spec-compiler.jj +++ b/grammer/spec-compiler.jj @@ -22,8 +22,11 @@ @Begin @Interface: ... @Commit_point_set: - ... + IDENTIFIER | IDENTIFIER ... @Condition: ... (Optional) + @HB_Condition: + IDENTIFIER :: + @HB_Condition: ... @ID: ... (Optional, use default ID) @Check: (Optional) ... @@ -64,12 +67,28 @@ options { PARSER_BEGIN(SpecParser) package edu.uci.eecs.specCompiler.grammerParser; - class SpecParser { +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +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.CPDefineConstruct; +import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct; +import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface; + + public 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) @@ -81,6 +100,8 @@ SKIP : "\n" | "\r" +| + "\r\n" | "\t" | @@ -93,6 +114,7 @@ SKIP : TOKEN : { +/* Above are specification-only tokens */ | @@ -113,7 +135,7 @@ TOKEN : | | - + | | @@ -134,108 +156,342 @@ TOKEN : | + + +/* Specification & C/C++ shared tokens */ | <#DIGIT: ["0"-"9"]> -| - <#NONZERO_DIGIT: ["1"-"9"]> | <#LETTER: ["a"-"z", "A"-"Z"]> | - <#NUM: > + | "_") ( | | "_")*> +| + +| + +| + +| + +| + "> +| + + +| +/* 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() : -{} +Construct Start() : { - Global_construct() + Construct res; +} +{ + ( + LOOKAHEAD(3) res = Global_construct() | + LOOKAHEAD(3) res = Interface() | + LOOKAHEAD(3) res = Potential_commit_point_define() | + LOOKAHEAD(3) res = Commit_point_define() | + LOOKAHEAD(3) res = Commit_point_define_check() + ) + + { return res; } } -void Global_construct() : -{} +GlobalConstruct Global_construct() : { + GlobalConstruct res; + String code; +} +{ + { res = null; } - Global_define() (Interface_cluster())? (Happens_before())? + (code = Global_define()) + { res = new GlobalConstruct(code); } + (Interface_clusters(res))? + (Happens_before(res))? + { + res.unfoldInterfaceCluster(); + System.out.println(res); + return res; + } } -void C_CPP_CODE() : -{} +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 = + t = | t = | t = | + t = | t = | t = | + t = | t = + ) + { + text.append(t.image); + if (t.image.equals(";") || t.image.equals("\\") + || t.image.equals("{") || t.image.equals("}")) + text.append("\n"); + else + text.append(" "); + } + )+ + { + //System.out.println(text); + return text.toString(); + } } -void Global_define() : -{} +String Global_define() : +{ + String code; +} { - C_CPP_CODE() + (code = C_CPP_CODE()) + { + return code; + } } -void Conditional_interface() : -{} +ConditionalInterface Conditional_interface() : +{ + String interfaceName, hbConditionLabel; +} { - (<"(" ")"> | "") + { + hbConditionLabel = ""; + } + interfaceName = .image ( hbConditionLabel = + .image )? + { + return new ConditionalInterface(interfaceName, hbConditionLabel); + } } -void Interface_cluster() : -{} +void Interface_cluster(GlobalConstruct inst) : +{ + String clusterName; + ConditionalInterface condInterface; +} { - "=" "{" Conditional_interface() (",," Conditional_interface())* "}" + (clusterName= .image) + + (condInterface = Conditional_interface() + { inst.addInterface2Cluster(clusterName, condInterface); } + ) + ( condInterface = Conditional_interface() + { inst.addInterface2Cluster(clusterName, condInterface); } + )* + } -void Interface_clusters() : +void Interface_clusters(GlobalConstruct inst) : {} { - (Interface_cluster())+ + (Interface_cluster(inst))+ } -void Happens_before() : -{} +void Happens_before(GlobalConstruct inst) : +{ + ConditionalInterface left, right; +} { - (Conditional_interface() "->" Conditional_interface())+ + + ( + left = Conditional_interface() right = Conditional_interface() + { inst.addHBCondition(left, right); } + )+ } -void Interface() : -{} +InterfaceConstruct Interface() : +{ + InterfaceConstruct res; +} { + { res = null; } - - "(" ")" "->" + + + ( )* + ( C_CPP_CODE())? + ( C_CPP_CODE())* + ( C_CPP_CODE())? + ( C_CPP_CODE())? + ( C_CPP_CODE())? + ( C_CPP_CODE())? + ( C_CPP_CODE())? + { return res; } } -void Potential_commit_point_define() : -{} +PotentialCPDefineConstruct Potential_commit_point_define() : +{ + PotentialCPDefineConstruct res; +} { + + { res = null; } - - "(" ")" "->" + + C_CPP_CODE() +