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)
28 IDENTIFIER :: <C_CPP_Condition>
30 @ID: ... (Optional, use default ID)
35 @Post_action: (Optional)
36 @Post_check: (Optional)
39 c) Potential commit construct
41 @Potential_commit_point_define: ...
45 d) Commit point define construct
47 @Commit_point_define_check: ...
54 @Commit_point_define: ...
55 @Potential_commit_point_label: ...
64 JAVA_UNICODE_ESCAPE = true;
67 PARSER_BEGIN(SpecParser)
68 package edu.uci.eecs.specCompiler.grammerParser;
70 import java.io.FileInputStream;
71 import java.io.FileNotFoundException;
74 public static void main(String[] argvs)
75 throws ParseException, TokenMgrError {
77 FileInputStream fis = new FileInputStream("./grammer/spec.txt");
78 SpecParser parser = new SpecParser(fis);
80 System.out.println("Parsing finished!");
81 } catch (FileNotFoundException e) {
86 PARSER_END(SpecParser)
100 // "#" comment for the specification
101 <"#" (~["\n", "\r"])* (["\n", "\r"])>
103 // "//" comment for the specification
104 <"//" (~["\n", "\r"])* (["\n", "\r"])>
109 /* Above are specification-only tokens */
118 <GLOBAL_DEFINE: "@Global_define:">
120 <INTERFACE_CLUSTER: "@Interface_cluster:">
122 <HAPPENS_BEFORE: "@Happens_before:">
124 <INTERFACE: "@Interface:">
126 <COMMIT_POINT_SET: "@Commit_point_set:">
128 <CONDITION: "@Condition:">
130 <HB_CONDITION: "@HB_condition:">
138 <POST_ACTION: "@Post_action:">
140 <POST_CHECK: "@Post_check:">
142 <POTENTIAL_COMMIT_POINT_DEFINE: "@Potential_commit_point_define:">
146 <COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
148 <COMMIT_POINT_DEFINE: "@Commit_point_define:">
150 <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
153 /* Specification & C/C++ shared tokens */
157 <#LETTER: ["a"-"z", "A"-"Z"]>
159 <IDENTIFIER: (<LETTER> | "_") (<LETTER> | <DIGIT> | "_")*>
176 /* C/C++ only token*/
205 <GREATER_EQUALS: ">=">
209 <LOGICAL_EQUALS: "==">
229 ((~["\"","\\","\n","\r"])
231 ( ["n","t","b","r","f","\\","'","\""]
232 | ["0"-"7"] ( ["0"-"7"] )?
233 | ["0"-"3"] ["0"-"7"]
242 ((~["'","\\","\n","\r"])
244 (["n","t","b","r","f","\\","'","\""]
245 | ["0"-"7"] ( ["0"-"7"] )?
246 | ["0"-"3"] ["0"-"7"]
254 <DECIMAL_LITERAL> (["l","L"])?
255 | <HEX_LITERAL> (["l","L"])?
256 | <OCTAL_LITERAL> (["l","L"])?>
258 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
260 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
262 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
264 < FLOATING_POINT_LITERAL:
265 <DECIMAL_FLOATING_POINT_LITERAL>
266 | <HEXADECIMAL_FLOATING_POINT_LITERAL> >
268 < #DECIMAL_FLOATING_POINT_LITERAL:
269 (["0"-"9"])+ "." (["0"-"9"])* (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
270 | "." (["0"-"9"])+ (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
271 | (["0"-"9"])+ <DECIMAL_EXPONENT> (["f","F","d","D"])?
272 | (["0"-"9"])+ (<DECIMAL_EXPONENT>)? ["f","F","d","D"]>
274 < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
276 < #HEXADECIMAL_FLOATING_POINT_LITERAL:
277 "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])+ (".")? <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?
278 | "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])* "." (["0"-"9","a"-"f","A"-"F"])+ <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?>
280 < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ >
287 LOOKAHEAD(3) Global_construct() |
288 LOOKAHEAD(3) Interface() |
289 LOOKAHEAD(3) Potential_commit_point_define() |
290 LOOKAHEAD(3) Commit_point_define() |
291 LOOKAHEAD(3) Commit_point_define_check()
296 void Global_construct() :
302 Global_define() (Interface_clusters())? (Happens_before())?
307 String C_CPP_CODE() :
314 text = new StringBuilder();
318 t = <IDENTIFIER> | t = <EQUALS> | t = <OPEN_PAREN> | t = <CLOSE_PAREN> |
319 t = <OPEN_BRACKET> | t = <CLOSE_BRACKET> | t = <HB_SYMBOL> | t = <COMMA> |
320 t = <DOT> | t = <STAR> | t = <NEGATE> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
321 t = <PLUSPLUS> | t = <MINUS> | t = <MINUSMINUS> | t = <DIVIDE> | t = <BACKSLASH> |
322 t = <LESS_THAN> | t = <GREATER_THAN> | t = <GREATER_EQUALS> | t = <LESS_EQUALS> |
323 t = <LOGICAL_EQUALS> | t = <NOT_EQUALS> | t = <LOGICAL_AND> | t = <LOGICAL_OR> | t = <XOR>
324 t = <QUESTION_MARK> | t = <COLON> | t = <DOUBLECOLON> |
325 t = <SEMI_COLON> | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
326 t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL>
329 text.append(t.image);
330 if (t.image.equals(";") || t.image.equals("\\")
331 || t.image.equals("{") || t.image.equals("}"))
338 System.out.println(text);
339 return text.toString();
343 void Global_define() :
346 <GLOBAL_DEFINE> C_CPP_CODE()
349 void Conditional_interface() :
352 <IDENTIFIER> (<OPEN_BRACKET> <IDENTIFIER> <CLOSE_BRACKET>)*
355 void Interface_cluster() :
358 <IDENTIFIER> <EQUALS> <OPEN_PAREN>
359 Conditional_interface() (<COMMA> Conditional_interface())*
363 void Interface_clusters() :
366 <INTERFACE_CLUSTER> (Interface_cluster())+
369 void Happens_before() :
372 <HAPPENS_BEFORE> (Conditional_interface() <HB_SYMBOL> Conditional_interface())+
380 <INTERFACE> <IDENTIFIER>
381 <COMMIT_POINT_SET> <IDENTIFIER> (<OR> <IDENTIFIER>)*
382 (<CONDITION> C_CPP_CODE())?
383 (<HB_CONDITION> <IDENTIFIER> C_CPP_CODE())*
385 (<CHECK> C_CPP_CODE())?
386 (<ACTION> C_CPP_CODE())?
387 (<POST_ACTION> C_CPP_CODE())?
388 (<POST_CHECK> C_CPP_CODE())?
393 void Potential_commit_point_define() :
398 <POTENTIAL_COMMIT_POINT_DEFINE> C_CPP_CODE()
405 void Commit_point_define() :
410 <COMMIT_POINT_DEFINE> C_CPP_CODE()
411 <POTENTIAL_COMMIT_POINT_LABEL> <IDENTIFIER>
418 void Commit_point_define_check() :
423 <COMMIT_POINT_DEFINE_CHECK> C_CPP_CODE()