1 /* spec-compiler.jj Grammer definition for the specification */
6 Each construct should be embraced by /DOUBLE_STAR ... STAR/ annotation.
7 Within there, any line beginning with a "#" is a comment of the annotation.
8 Each constrcut should begin with @Begin and end with @End. Otherwise, the
9 annotation would be considered as normal comments of the source.
21 b) Interface construct
25 IDENTIFIER | IDENTIFIER ...
26 @Condition: ... (Optional)
29 @ID: ... (Optional, use default ID)
34 @Post_action: (Optional)
35 @Post_check: (Optional)
38 c) Potential commit construct
40 @Potential_commit_point_define: ...
44 d) Commit point define construct
46 @Commit_point_define_check: ...
53 @Commit_point_define: ...
54 @Potential_commit_point_label: ...
63 JAVA_UNICODE_ESCAPE = true;
66 PARSER_BEGIN(SpecParser)
67 package edu.uci.eecs.specCompiler.grammerParser;
69 import java.io.FileInputStream;
70 import java.io.FileNotFoundException;
73 public static void main(String[] argvs)
74 throws ParseException, TokenMgrError {
76 FileInputStream fis = new FileInputStream("./grammer/spec.txt");
77 SpecParser parser = new SpecParser(fis);
79 System.out.println("Parsing finished!");
80 } catch (FileNotFoundException e) {
85 PARSER_END(SpecParser)
99 // "#" comment for the specification
100 <"#" (~["\n", "\r"])* (["\n", "\r"])>
102 // "//" comment for the specification
103 <"//" (~["\n", "\r"])* (["\n", "\r"])>
108 /* Above are specification-only tokens */
117 <GLOBAL_DEFINE: "@Global_define:">
119 <INTERFACE_CLUSTER: "@Interface_cluster:">
121 <HAPPENS_BEFORE: "@Happens_before:">
123 <INTERFACE: "@Interface:">
125 <COMMIT_POINT_SET: "@Commit_point_set:">
127 <CONDITION: "@Condition:">
129 <HB_CONDITION: "@HB_condition:">
137 <POST_ACTION: "@Post_action:">
139 <POST_CHECK: "@Post_check:">
141 <POTENTIAL_COMMIT_POINT_DEFINE: "@Potential_commit_point_define:">
145 <COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
147 <COMMIT_POINT_DEFINE: "@Commit_point_define:">
149 <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
152 /* Specification & C/C++ shared tokens */
156 <#LETTER: ["a"-"z", "A"-"Z"]>
158 <IDENTIFIER: (<LETTER> | "_") (<LETTER> | <DIGIT> | "_")*>
175 /* C/C++ only token*/
212 ((~["\"","\\","\n","\r"])
214 ( ["n","t","b","r","f","\\","'","\""]
215 | ["0"-"7"] ( ["0"-"7"] )?
216 | ["0"-"3"] ["0"-"7"]
225 ((~["'","\\","\n","\r"])
227 (["n","t","b","r","f","\\","'","\""]
228 | ["0"-"7"] ( ["0"-"7"] )?
229 | ["0"-"3"] ["0"-"7"]
237 <DECIMAL_LITERAL> (["l","L"])?
238 | <HEX_LITERAL> (["l","L"])?
239 | <OCTAL_LITERAL> (["l","L"])?>
241 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
243 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
245 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
247 < FLOATING_POINT_LITERAL:
248 <DECIMAL_FLOATING_POINT_LITERAL>
249 | <HEXADECIMAL_FLOATING_POINT_LITERAL> >
251 < #DECIMAL_FLOATING_POINT_LITERAL:
252 (["0"-"9"])+ "." (["0"-"9"])* (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
253 | "." (["0"-"9"])+ (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
254 | (["0"-"9"])+ <DECIMAL_EXPONENT> (["f","F","d","D"])?
255 | (["0"-"9"])+ (<DECIMAL_EXPONENT>)? ["f","F","d","D"]>
257 < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
259 < #HEXADECIMAL_FLOATING_POINT_LITERAL:
260 "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])+ (".")? <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?
261 | "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])* "." (["0"-"9","a"-"f","A"-"F"])+ <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?>
263 < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ >
270 LOOKAHEAD(3) Global_construct() |
271 LOOKAHEAD(3) Interface() |
272 LOOKAHEAD(3) Potential_commit_point_define() |
273 LOOKAHEAD(3) Commit_point_define() |
274 LOOKAHEAD(3) Commit_point_define_check()
279 void Global_construct() :
285 Global_define() (Interface_clusters())? (Happens_before())?
290 String C_CPP_CODE() :
297 text = new StringBuilder();
301 t = <IDENTIFIER> | t = <EQUALS> | t = <OPEN_PAREN> | t = <CLOSE_PAREN> |
302 t = <OPEN_BRACKET> | t = <CLOSE_BRACKET> | t = <HB_SYMBOL> | t = <COMMA> |
303 t = <DOT> | t = <STAR> | t = <NEGATE> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
304 t = <PLUSPLUS> | t = <MINUS> | t = <MINUSMINUS> | t = <DIVIDE> | t = <BACKSLASH> |
305 t = <LESS_THAN> | t = <GREATER_THAN> | t = <QUESTION_MARK> | t = <COLON> |
306 t = <SEMI_COLON> | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
307 t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL>
310 text.append(t.image);
315 System.out.println(text);
316 return text.toString();
320 void Global_define() :
323 <GLOBAL_DEFINE> C_CPP_CODE()
326 void Conditional_interface() :
329 <IDENTIFIER> (<OPEN_BRACKET> <IDENTIFIER> <CLOSE_BRACKET>)*
332 void Interface_cluster() :
335 <IDENTIFIER> <EQUALS> <OPEN_PAREN>
336 Conditional_interface() (<COMMA> Conditional_interface())*
340 void Interface_clusters() :
343 <INTERFACE_CLUSTER> (Interface_cluster())+
346 void Happens_before() :
349 <HAPPENS_BEFORE> (Conditional_interface() <HB_SYMBOL> Conditional_interface())+
357 <INTERFACE> <IDENTIFIER>
358 <COMMIT_POINT_SET> <IDENTIFIER> (<OR> <IDENTIFIER>)*
359 (<CONDITION> C_CPP_CODE())?
360 (<HB_CONDITION> C_CPP_CODE())*
362 (<CHECK> C_CPP_CODE())?
363 (<ACTION> C_CPP_CODE())?
364 (<POST_ACTION> C_CPP_CODE())?
365 (<POST_CHECK> C_CPP_CODE())?
370 void Potential_commit_point_define() :
375 <POTENTIAL_COMMIT_POINT_DEFINE> C_CPP_CODE()
382 void Commit_point_define() :
387 <COMMIT_POINT_DEFINE> C_CPP_CODE()
388 <POTENTIAL_COMMIT_POINT_LABEL> <IDENTIFIER>
395 void Commit_point_define_check() :
400 <COMMIT_POINT_DEFINE_CHECK> C_CPP_CODE()