a) Global construct
@Begin
+ @Options:
+ # If LANG is not define, it's C++ by default. C does not support class
+ # and template, so if it's defined as C, we should also have a explicit
+ # entry point.
+ LANG = C;
@Global_define:
+ @DeclareVar:
+ @InitVar:
+ @DefineFunc:
...
@Interface_cluster:
...
@Potential_commit_point_label: ...
@Label: ...
@End
+
+ e) Entry point construct
+ @Begin
+ @Entry_point
+ @End
+
+ f) Interface define construct
+ @Begin
+ @Interface_define: <Interface_Name>
+ @End
*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct;
import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct.DefineVar;
+import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.EntryPointConstruct;
public class SpecParser {
public static void main(String[] argvs)
e.printStackTrace();
}
}
+
+ public static Construct parseSpec(String text)
+ throws ParseException, TokenMgrError {
+ InputStream input = new ByteArrayInputStream(text.getBytes());
+ SpecParser parser = new SpecParser(input);
+ return parser.Parse();
+ }
+
+
}
PARSER_END(SpecParser)
<BEGIN: "@Begin">
|
<END: "@End">
+|
+ <OPTIONS: "@Options:">
|
<GLOBAL_DEFINE: "@Global_define:">
+|
+ <DECLARE_VAR: "@DeclareVar:">
+|
+ <INIT_VAR: "@InitVar:">
+|
+ <DEFINE_FUNC: "@DefineFunc:">
|
<INTERFACE_CLUSTER: "@Interface_cluster:">
|
<INTERFACE: "@Interface:">
|
<COMMIT_POINT_SET: "@Commit_point_set:">
+|
+ <ENTRY_POINT: "@Entry_point">
+|
+ <INTERFACE_DEFINE: "@Interface_define:">
|
<CONDITION: "@Condition:">
|
<STAR: "*">
|
<NEGATE: "~">
+|
+ <EXCLAMATION: "!">
|
<AND: "&">
|
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 = Commit_point_define_check() |
+ LOOKAHEAD(3) res = Entry_point() |
+ LOOKAHEAD(3) res = Interface_define()
)
<EOF>
{
- System.out.println(res);
+ //System.out.println(res);
return res;
}
}
GlobalConstruct Global_construct() :
{
GlobalConstruct res;
- String code;
+ SequentialDefineSubConstruct code;
+ HashMap<String, String> options;
+ String key, value;
}
{
- { res = null; }
+ {
+ res = null;
+ options = new HashMap<String, String>();
+ }
<HEAD>
<BEGIN>
+ (<OPTIONS>
+ ((key = <IDENTIFIER>.image)
+ <EQUALS>
+ (value = <IDENTIFIER>.image)
+ {
+ if (options.containsKey(key)) {
+ throw new ParseException("Duplicate options!");
+ }
+ options.put(key, value);
+ }
+ <SEMI_COLON>
+ )*
+ )?
(code = Global_define())
- { res = new GlobalConstruct(code); }
+ { res = new GlobalConstruct(code, options); }
(Interface_clusters(res))?
(Happens_before(res))?
<END>
(
t = <IDENTIFIER> | t = <EQUALS> | t = <OPEN_PAREN> | t = <CLOSE_PAREN> |
t = <OPEN_BRACKET> | t = <CLOSE_BRACKET> | t = <HB_SYMBOL> | t = <COMMA> |
- t = <DOT> | t = <STAR> | t = <NEGATE> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
+ t = <DOT> | t = <STAR> | t = <NEGATE> | t = <EXCLAMATION> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
t = <PLUSPLUS> | t = <MINUS> | t = <MINUSMINUS> | t = <DIVIDE> | t = <BACKSLASH> |
t = <LESS_THAN> | t = <GREATER_THAN> | t = <GREATER_EQUALS> | t = <LESS_EQUALS> |
t = <LOGICAL_EQUALS> | t = <NOT_EQUALS> | t = <LOGICAL_AND> | t = <LOGICAL_OR> | t = <XOR> |
}
}
-String Global_define() :
+SequentialDefineSubConstruct Global_define() :
{
- String code;
+ String declareVar, initVar, defineFunc;
}
{
- <GLOBAL_DEFINE> (code = C_CPP_CODE())
{
- return code;
+ declareVar = "";
+ initVar = "";
+ defineFunc = "";
+ }
+ <GLOBAL_DEFINE>
+ (<DECLARE_VAR> (declareVar = C_CPP_CODE()))?
+ (<INIT_VAR> (initVar = C_CPP_CODE()))?
+ (<DEFINE_FUNC> (defineFunc = C_CPP_CODE()))?
+ {
+ SequentialDefineSubConstruct res = new SequentialDefineSubConstruct(declareVar, initVar, defineFunc);
+ //System.out.println(res);
+ return res;
}
}
{
{
defineVars = new ArrayList<DefineVar>();
+ code = "";
}
<ACTION>
+ (
+ (
(<DEFINEVAR> (defineVarStr = C_CPP_CODE())
{
int eqIdx = defineVarStr.indexOf('=');
expr = defineVarStr.substring(eqIdx + 2);
DefineVar defineVar = new DefineVar(type, name, expr);
defineVars.add(defineVar);
- }
- )*
- <CODE> (code = C_CPP_CODE())
- {
- ActionSubConstruct res = new ActionSubConstruct(defineVars, code);
- return res;
- }
+ })* (<CODE> (code = C_CPP_CODE()))? )
+ )
+
+ {
+ ActionSubConstruct res = new ActionSubConstruct(defineVars, code);
+ return res;
+ }
}
PotentialCPDefineConstruct Potential_commit_point_define() :
return res;
}
}
+
+EntryPointConstruct Entry_point() :
+{}
+{
+
+ <HEAD>
+ <BEGIN>
+ <ENTRY_POINT>
+ <END>
+ <TAIL>
+ {
+ return new EntryPointConstruct();
+ }
+}
+
+InterfaceDefineConstruct Interface_define() :
+{
+ String name;
+}
+{
+ <HEAD>
+ <BEGIN>
+ <INTERFACE_DEFINE> (name = <IDENTIFIER>.image)
+ <END>
+ <TAIL>
+ {
+ return new InterfaceDefineConstruct(name);
+ }
+}
+
+