@Check: (Optional)
...
@Action: (Optional)
+ @DefineVar: Type var1 = SomeExpression (Optional)
+ @Code (Optional)
...
@Post_action: (Optional)
@Post_check: (Optional)
import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct;
import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
+import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct.DefineVar;
public class SpecParser {
public static void main(String[] argvs)
try {
FileInputStream fis = new FileInputStream("./grammer/spec.txt");
SpecParser parser = new SpecParser(fis);
- parser.Start();
+ parser.Parse();
System.out.println("Parsing finished!");
} catch (FileNotFoundException e) {
e.printStackTrace();
<CHECK: "@Check:">
|
<ACTION: "@Action:">
+|
+ <DEFINEVAR: "@DefineVar:">
+|
+ <CODE: "@Code:">
|
<POST_ACTION: "@Post_action:">
|
< #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ >
}
-Construct Start() :
+Construct Parse() :
{
Construct res;
}
text = new StringBuilder();
t = new Token();
}
- ((
+ (
+ //LOOKAHEAD(2)
+ (
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 = <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>
+ t = <LOGICAL_EQUALS> | t = <NOT_EQUALS> | t = <LOGICAL_AND> | t = <LOGICAL_OR> | t = <XOR> |
t = <QUESTION_MARK> | t = <COLON> | t = <DOUBLECOLON> |
t = <SEMI_COLON> | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL>
InterfaceConstruct Interface() :
{
InterfaceConstruct res;
- String interfaceName, condition, idCode, check, action, postAction,
+ String interfaceName, condition, idCode, check, postAction,
postCheck, commitPoint, hbLabel, hbCondition;
+ ActionSubConstruct action;
ArrayList<String> commitPointSet;
HashMap<String, String> hbConditions;
}
{
{
res = null;
+ action = null;
condition = "";
idCode = "";
check = "";
- action = "";
postAction = "";
postCheck = "";
commitPointSet = new ArrayList<String>();
)*
(<ID> (idCode = C_CPP_CODE()))?
(<CHECK> (check = C_CPP_CODE()))?
- (<ACTION> (action = C_CPP_CODE()))?
+ (action = Action())?
(<POST_ACTION> (postAction = C_CPP_CODE()))?
(<POST_CHECK> (postCheck = C_CPP_CODE()))?
<END>
}
}
+ActionSubConstruct Action() :
+{
+ String type, name, expr, defineVarStr, code;
+ ArrayList<DefineVar> defineVars;
+}
+{
+ {
+ defineVars = new ArrayList<DefineVar>();
+ }
+ <ACTION>
+ (<DEFINEVAR> (defineVarStr = C_CPP_CODE())
+ {
+ int eqIdx = defineVarStr.indexOf('=');
+ int typeEnd = defineVarStr.lastIndexOf(' ', eqIdx - 2);
+ type = defineVarStr.substring(0, typeEnd);
+ name = defineVarStr.substring(typeEnd + 1, eqIdx - 1);
+ 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;
+ }
+}
+
PotentialCPDefineConstruct Potential_commit_point_define() :
{
PotentialCPDefineConstruct res;
--- /dev/null
+package edu.uci.eecs.specCompiler.specExtraction;
+
+import java.util.ArrayList;
+
+public class ActionSubConstruct {
+ public static class DefineVar {
+ public final String varType;
+ public final String varName;
+ public final String varExpr;
+
+ public DefineVar(String varType, String varName, String varExpr) {
+ this.varType = varType;
+ this.varName = varName;
+ this.varExpr = varExpr;
+ }
+
+ public String toString() {
+ return varType + " " + varName + " = " + varExpr;
+ }
+ }
+
+ public final ArrayList<DefineVar> defineVars;
+ public final String code;
+
+ public ActionSubConstruct(ArrayList<DefineVar> defineVars, String code) {
+ this.code = code;
+ this.defineVars = defineVars;
+ }
+
+ public void addDefineVar(DefineVar defineVar) {
+ defineVars.add(defineVar);
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("@Action:\n");
+ for (DefineVar defineVar : defineVars) {
+ sb.append("\t@DefineVar: " + defineVar + "\n");
+ }
+ sb.append("\t@Code: " + code);
+ return sb.toString();
+ }
+}
public final HashMap<String, String> hbConditions;
public final String idCode;
public final String check;
- public final String action;
+ public final ActionSubConstruct action;
public final String postAction;
public final String postCheck;
public InterfaceConstruct(String name, ArrayList<String> commitPointSet,
String condition, HashMap<String, String> hbConditions, String idCode,
- String check, String action, String postAction, String postCheck) {
+ String check, ActionSubConstruct action, String postAction, String postCheck) {
this.name = name;
this.commitPointSet = commitPointSet;
this.condition = condition;
sb.append("@ID: ");
sb.append(idCode + "\n");
sb.append("@Check: " + check + "\n");
- sb.append("@Action:\n");
sb.append(action + "\n");
sb.append("@Post_action:\n");
sb.append(postAction + "\n");
if (trimedLine.endsWith("*/")) {
_endLineNum = reader.getLineNumber();
foundHead = false;
+ //Constrcut inst = SpecParser
System.out.println("Spec<" + specIndex + "> Begin: "
+ _beginLine + " End: " + _endLineNum);
specText = new StringBuilder();
}
}
- }
+ }
// At the end we can only find the head "/**" but no tail found
if (foundHead) {
String msg = "In file \"" + file.getAbsolutePath() + "\", line: "
}
}
+ private String readInterfaceDecl(LineNumberReader reader) throws IOException {
+ String res = "", curLine;
+ while ((curLine = reader.readLine()) != null) {
+ int braceIdx = curLine.indexOf(')');
+ if (braceIdx == -1) {
+ res = res + " " + curLine;
+ } else {
+ res = res + curLine.substring(0, braceIdx + 1);
+ }
+ }
+ return res;
+ }
+
private String trimSpace(String line) {
int i, j;
char ch;