X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=blobdiff_plain;f=grammer%2Fspec-compiler.jj;h=a006e7bca3e5a463650b80f917e11477270df1d0;hp=bfcd6b99825b7c67e90facd45552b29ddae044a3;hb=944b6af217212532a88e314df52a4cf5a99ed36a;hpb=b1e52c7b681a0bc2704509b63a8907b3004901b3;ds=inline diff --git a/grammer/spec-compiler.jj b/grammer/spec-compiler.jj index bfcd6b9..a006e7b 100644 --- a/grammer/spec-compiler.jj +++ b/grammer/spec-compiler.jj @@ -24,7 +24,8 @@ @Commit_point_set: IDENTIFIER | IDENTIFIER ... @Condition: ... (Optional) - @HB_Condition: ... + @HB_Condition: + IDENTIFIER :: @HB_Condition: ... @ID: ... (Optional, use default ID) @Check: (Optional) @@ -69,7 +70,15 @@ package edu.uci.eecs.specCompiler.grammerParser; import java.io.FileInputStream; import java.io.FileNotFoundException; - class SpecParser { +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 { try { @@ -200,10 +209,26 @@ TOKEN : | "> +| + ="> +| + +| + +| + | | +| + | | @@ -263,28 +288,42 @@ TOKEN : < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ > } -void Start() : -{} +Construct Start() : +{ + Construct res; +} { ( - LOOKAHEAD(3) Global_construct() | - LOOKAHEAD(3) Interface() | - LOOKAHEAD(3) Potential_commit_point_define() | - LOOKAHEAD(3) Commit_point_define() | - LOOKAHEAD(3) Commit_point_define_check() + 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_clusters())? (Happens_before())? + (code = Global_define()) + { res = new GlobalConstruct(code); } + (Interface_clusters(res))? + (Happens_before(res))? + { + res.unfoldInterfaceCluster(); + System.out.println(res); + return res; + } } String C_CPP_CODE() : @@ -302,62 +341,100 @@ String C_CPP_CODE() : 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); - text.append("\n"); + if (t.image.equals(";") || t.image.equals("\\") + || t.image.equals("{") || t.image.equals("}")) + text.append("\n"); + else + text.append(" "); } )+ { - System.out.println(text); + //System.out.println(text); return text.toString(); } } -void Global_define() : -{} +String Global_define() : { - C_CPP_CODE() + String 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) : { - (Conditional_interface() Conditional_interface())+ + ConditionalInterface left, right; +} +{ + + ( + 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())? @@ -365,23 +442,33 @@ void Interface() : ( C_CPP_CODE())? + { return res; } } -void Potential_commit_point_define() : -{} +PotentialCPDefineConstruct Potential_commit_point_define() : +{ + PotentialCPDefineConstruct res; +} { + + { res = null; } C_CPP_CODE()