X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=blobdiff_plain;f=grammer%2Fspec-compiler.jj;fp=grammer%2Fspec-compiler.jj;h=c048141757d13c02a569022f959815f02e0de274;hp=309fbb443f05171a7c6f4dbba64415806aafad02;hb=f32aa9d68bb48b853fce1b667a756d77060500ec;hpb=589dca6c19ba28251d70ef9ac3f757b6532d9c82 diff --git a/grammer/spec-compiler.jj b/grammer/spec-compiler.jj index 309fbb4..c048141 100644 --- a/grammer/spec-compiler.jj +++ b/grammer/spec-compiler.jj @@ -115,7 +115,7 @@ import edu.uci.eecs.specCompiler.specExtraction.EntryPointConstruct; try { FileInputStream fis = new FileInputStream("./grammer/spec.txt"); SpecParser parser = new SpecParser(fis); - parser.Parse(); + parser.ParseSpec(); System.out.println("Parsing finished!"); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -133,32 +133,21 @@ import edu.uci.eecs.specCompiler.specExtraction.EntryPointConstruct; } PARSER_END(SpecParser) -SKIP : -{ - " " -| - "\n" -| - "\r" -| - "\r\n" -| - "\t" -| - // "#" comment for the specification - <"#" (~["\n", "\r"])* (["\n", "\r"])> -| - // "//" comment for the specification - <"//" (~["\n", "\r"])* (["\n", "\r"])> +< IN_COMMENT > SKIP : { < ~[] > } + +< IN_COMMENT, IN_SPEC > SKIP : { + "*/": DEFAULT } -TOKEN : -{ -/* Above are specification-only tokens */ - -| - -| +SKIP : { + "/*": IN_COMMENT +} + +SKIP : { + "/**": IN_SPEC +} + + TOKEN : { | @@ -212,9 +201,36 @@ TOKEN : | +} +SKIP : +{ + " " +| + "\n" +| + "\r" +| + "\r\n" +| + "\t" +| + // "#" comment for the specification + <"#" (~["\n", "\r"])* (["\n", "\r"])> +| + // "//" comment for the specification + <"//" (~["\n", "\r"])* (["\n", "\r"])> +} + TOKEN : +{ /* Specification & C/C++ shared tokens */ +// Reserved keywords + +| + +| + | <#DIGIT: ["0"-"9"]> | @@ -346,66 +362,80 @@ TOKEN : < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ > } -Construct Parse() : +String Type() : { - Construct res; + String type; + String str; } { - ( - 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() | - LOOKAHEAD(3) res = Entry_point() | - LOOKAHEAD(3) res = Interface_define() - ) - + { type = ""; } + ("const" + { type = "const"; } + )? + (("struct" { type = type + " struct"; })? + (str = .image { + if (!type.equals("")) + type = type + " " + str; + else + type = str; + })) + ((str = "const".image { + if (!type.equals("")) + type = type + " " + str; + else + type = str; + }) | + (str = .image { + if (!type.equals("")) + type = type + " " + str; + else + type = str; + }) | + (str = .image { + if (!type.equals("")) + type = type + " " + str; + else + type = str; + }) + )* { - //System.out.println(res); - return res; + return type; } } -GlobalConstruct Global_construct() : +ArrayList FormalParamList() : { - GlobalConstruct res; - SequentialDefineSubConstruct code; - HashMap options; - String key, value; + ArrayList typeParams; } { { - res = null; - options = new HashMap(); + typeParams = new ArrayList(); } - - - ( - ((key = .image) - - (value = .image) - { - if (options.containsKey(key)) { - throw new ParseException("Duplicate options!"); - } - options.put(key, value); - } - - )* - )? - (code = Global_define()) - { res = new GlobalConstruct(code, options); } - (Interface_clusters(res))? - (Happens_before(res))? - - + (TypeParam(typeParams) ( TypeParam(typeParams))*)? { - res.unfoldInterfaceCluster(); - return res; + System.out.println(typeParams); + return typeParams; } } +void TypeParam(ArrayList typeParams) : +{ + String type, param; +} +{ + (type = Type()) (param = .image) + { + typeParams.add(type); + typeParams.add(param); + } +} + +void ParseSpec() : +{} +{ + C_CPP_CODE()