public Object execute(ExecutionEvent event) throws ExecutionException {\r
// prompt the user for a file\r
FileDialog dialog = new FileDialog(HandlerUtil.getActiveShell(event), SWT.SAVE);\r
- dialog.setFilterExtensions(new String[] {"*.xml","*.*"});\r
+ dialog.setFilterExtensions(new String[] {"*.xmile","*.*"});\r
dialog.setOverwrite(true);\r
\r
String fileName = dialog.open();\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
// prompt the user for a file\r
FileDialog dialog = new FileDialog(HandlerUtil.getActiveShell(event), SWT.OPEN);\r
- dialog.setFilterExtensions(new String[] {"*.xml","*.*"});\r
+ dialog.setFilterExtensions(new String[] {"*.xmile","*.*"});\r
\r
String fileName = dialog.open();\r
if (fileName == null) {\r
import org.simantics.sysdyn.xmile.XmileUtil;
public class XmileExpressionParser implements XmileExpressionParserConstants {
- private static final boolean DEBUG = true;
-
public static String parse(String expression, Map<String, String> subscripts) {
XmileExpressionParser parser = new XmileExpressionParser(new StringReader(expression));
}
final public String Expression(Map<String, String> subscripts) throws ParseException {String e;
- e = BinExpr(subscripts);
+ e = CondExpr(subscripts);
jj_consume_token(0);
{if ("" != null) return e;}
throw new Error("Missing return statement in function");
}
+ final public String CondExpr(Map<String, String> subscripts) throws ParseException {String condExpr = null;
+ String thenExpr = null;
+ String elseExpr = null;
+ String expr;
+ switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
+ case IF:{
+ jj_consume_token(IF);
+ condExpr = BinExpr(subscripts);
+ jj_consume_token(THEN);
+ thenExpr = BinExpr(subscripts);
+ jj_consume_token(ELSE);
+ elseExpr = BinExpr(subscripts);
+{if ("" != null) return "if "+condExpr+" then "+thenExpr+" else "+elseExpr;}
+ break;
+ }
+ case LNOT:
+ case PLUS:
+ case MINUS:
+ case LPAREN:
+ case NUMBER:
+ case IDENT:
+ case QIDENT:{
+ expr = BinExpr(subscripts);
+{if ("" != null) return expr;}
+ break;
+ }
+ default:
+ jj_la1[0] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
final public String BinOp() throws ParseException {
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case LOR:{
break;
}
default:
- jj_la1[0] = jj_gen;
+ jj_la1[1] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
}
default:
- jj_la1[1] = jj_gen;
+ jj_la1[2] = jj_gen;
;
}
{if ("" != null) return o != null ? l + o + r : l;}
break;
}
default:
- jj_la1[2] = jj_gen;
+ jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
}
default:
- jj_la1[3] = jj_gen;
+ jj_la1[4] = jj_gen;
;
}
e = Atom(subscripts);
break;
}
default:
- jj_la1[4] = jj_gen;
+ jj_la1[5] = jj_gen;
if (jj_2_1(2)) {
s = Function(subscripts);
{if ("" != null) return s;}
}
case LPAREN:{
jj_consume_token(LPAREN);
- s = BinExpr(subscripts);
+ s = CondExpr(subscripts);
jj_consume_token(RPAREN);
{if ("" != null) return "(" + s + ")";}
break;
}
default:
- jj_la1[5] = jj_gen;
+ jj_la1[6] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
}
default:
- jj_la1[6] = jj_gen;
+ jj_la1[7] = jj_gen;
break label_1;
}
jj_consume_token(COMMA);
break;
}
default:
- jj_la1[7] = jj_gen;
+ jj_la1[8] = jj_gen;
;
}
jj_consume_token(RPAREN);
break;
}
default:
- jj_la1[8] = jj_gen;
+ jj_la1[9] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
private Token jj_scanpos, jj_lastpos;
private int jj_la;
private int jj_gen;
- final private int[] jj_la1 = new int[9];
+ final private int[] jj_la1 = new int[10];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
- jj_la1_0 = new int[] {0x7fec,0x7fec,0xc10,0xc10,0x80000,0x310000,0x40000,0x390c10,0x300000,};
+ jj_la1_0 = new int[] {0x1c90c10,0x7fec,0x7fec,0xc10,0xc10,0x400000,0x1810000,0x40000,0x1c10c10,0x1800000,};
}
final private JJCalls[] jj_2_rtns = new JJCalls[1];
private boolean jj_rescan = false;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 10; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 10; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 10; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 10; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 10; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 9; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 10; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
/** Generate ParseException. */
public ParseException generateParseException() {
jj_expentries.clear();
- boolean[] la1tokens = new boolean[22];
+ boolean[] la1tokens = new boolean[25];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
- for (int i = 0; i < 9; i++) {
+ for (int i = 0; i < 10; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
}
}
}
- for (int i = 0; i < 22; i++) {
+ for (int i = 0; i < 25; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
import org.simantics.sysdyn.xmile.XmileUtil;\r
\r
public class XmileExpressionParser {\r
- private static final boolean DEBUG = true;\r
-\r
public static String parse(String expression, Map<String, String> subscripts) {\r
XmileExpressionParser parser = new XmileExpressionParser(new StringReader(expression));\r
\r
| <LPAREN : "("> \r
| <RPAREN : ")">\r
| <COMMA : ",">\r
+| <IF : "IF">\r
+| <THEN : "THEN">\r
+| <ELSE : "ELSE">\r
}\r
\r
TOKEN : \r
String e;\r
}\r
{\r
- e=BinExpr(subscripts) <EOF> { return e; }\r
+ e=CondExpr(subscripts) <EOF> { return e; }\r
+}\r
+\r
+String CondExpr(Map<String, String> subscripts) :\r
+{\r
+ String condExpr = null;\r
+ String thenExpr = null;\r
+ String elseExpr = null;\r
+ String expr;\r
+}\r
+{\r
+ <IF> condExpr=BinExpr(subscripts) <THEN> thenExpr=BinExpr(subscripts) <ELSE> elseExpr=BinExpr(subscripts) { return "if "+condExpr+" then "+thenExpr+" else "+elseExpr; }\r
+| expr = BinExpr(subscripts) { return expr; }\r
}\r
\r
String BinOp() :\r
t=<NUMBER> { return t.image; }\r
| LOOKAHEAD(2) s=Function(subscripts) { return s; }\r
| s=Variable(subscripts) { return s; }\r
-| <LPAREN> s=BinExpr(subscripts) <RPAREN> { return "(" + s + ")"; }\r
+| <LPAREN> s=CondExpr(subscripts) <RPAREN> { return "(" + s + ")"; }\r
}\r
\r
String Function(Map<String, String> subscripts) :\r
/** RegularExpression Id. */\r
int COMMA = 18;\r
/** RegularExpression Id. */\r
- int NUMBER = 19;\r
+ int IF = 19;\r
/** RegularExpression Id. */\r
- int IDENT = 20;\r
+ int THEN = 20;\r
/** RegularExpression Id. */\r
- int QIDENT = 21;\r
+ int ELSE = 21;\r
+ /** RegularExpression Id. */\r
+ int NUMBER = 22;\r
+ /** RegularExpression Id. */\r
+ int IDENT = 23;\r
+ /** RegularExpression Id. */\r
+ int QIDENT = 24;\r
\r
/** Lexical state. */\r
int DEFAULT = 0;\r
"\"(\"",\r
"\")\"",\r
"\",\"",\r
+ "\"IF\"",\r
+ "\"THEN\"",\r
+ "\"ELSE\"",\r
"<NUMBER>",\r
"<IDENT>",\r
"<QIDENT>",\r
switch (pos)
{
case 0:
- if ((active0 & 0xc0L) != 0L)
- return 1;
- if ((active0 & 0x401cL) != 0L)
+ if ((active0 & 0x38401cL) != 0L)
{
- jjmatchedKind = 20;
+ jjmatchedKind = 23;
return 9;
}
+ if ((active0 & 0xc0L) != 0L)
+ return 1;
return -1;
case 1:
- if ((active0 & 0x4018L) != 0L)
+ if ((active0 & 0x304018L) != 0L)
{
- jjmatchedKind = 20;
+ jjmatchedKind = 23;
jjmatchedPos = 1;
return 9;
}
- if ((active0 & 0x4L) != 0L)
+ if ((active0 & 0x80004L) != 0L)
+ return 9;
+ return -1;
+ case 2:
+ if ((active0 & 0x300000L) != 0L)
+ {
+ jjmatchedKind = 23;
+ jjmatchedPos = 2;
+ return 9;
+ }
+ if ((active0 & 0x4018L) != 0L)
return 9;
return -1;
default :
return jjMoveStringLiteralDfa1_0(0x200L);
case 65:
return jjMoveStringLiteralDfa1_0(0x8L);
+ case 69:
+ return jjMoveStringLiteralDfa1_0(0x200000L);
+ case 73:
+ return jjMoveStringLiteralDfa1_0(0x80000L);
case 77:
return jjMoveStringLiteralDfa1_0(0x4000L);
case 78:
return jjMoveStringLiteralDfa1_0(0x10L);
case 79:
return jjMoveStringLiteralDfa1_0(0x4L);
+ case 84:
+ return jjMoveStringLiteralDfa1_0(0x100000L);
case 94:
return jjStopAtPos(0, 15);
default :
else if ((active0 & 0x200L) != 0L)
return jjStopAtPos(1, 9);
break;
+ case 70:
+ if ((active0 & 0x80000L) != 0L)
+ return jjStartNfaWithStates_0(1, 19, 9);
+ break;
+ case 72:
+ return jjMoveStringLiteralDfa2_0(active0, 0x100000L);
+ case 76:
+ return jjMoveStringLiteralDfa2_0(active0, 0x200000L);
case 78:
return jjMoveStringLiteralDfa2_0(active0, 0x8L);
case 79:
else if ((active0 & 0x4000L) != 0L)
return jjStartNfaWithStates_0(2, 14, 9);
break;
+ case 69:
+ return jjMoveStringLiteralDfa3_0(active0, 0x100000L);
+ case 83:
+ return jjMoveStringLiteralDfa3_0(active0, 0x200000L);
case 84:
if ((active0 & 0x10L) != 0L)
return jjStartNfaWithStates_0(2, 4, 9);
}
return jjStartNfa_0(1, active0);
}
+private int jjMoveStringLiteralDfa3_0(long old0, long active0){
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(1, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(2, active0);
+ return 3;
+ }
+ switch(curChar)
+ {
+ case 69:
+ if ((active0 & 0x200000L) != 0L)
+ return jjStartNfaWithStates_0(3, 21, 9);
+ break;
+ case 78:
+ if ((active0 & 0x100000L) != 0L)
+ return jjStartNfaWithStates_0(3, 20, 9);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(2, active0);
+}
private int jjStartNfaWithStates_0(int pos, int kind, int state)
{
jjmatchedKind = kind;
case 0:
if ((0x3ff000000000000L & l) != 0L)
{
- if (kind > 19)
- kind = 19;
+ if (kind > 22)
+ kind = 22;
{ jjCheckNAddStates(0, 4); }
}
else if (curChar == 34)
case 4:
if ((0x3ff000000000000L & l) == 0L)
break;
- if (kind > 19)
- kind = 19;
+ if (kind > 22)
+ kind = 22;
{ jjCheckNAddTwoStates(4, 5); }
break;
case 6:
case 7:
if ((0x3ff000000000000L & l) == 0L)
break;
- if (kind > 19)
- kind = 19;
+ if (kind > 22)
+ kind = 22;
{ jjCheckNAdd(7); }
break;
case 9:
if ((0x3ff001000000000L & l) == 0L)
break;
- if (kind > 20)
- kind = 20;
+ if (kind > 23)
+ kind = 23;
jjstateSet[jjnewStateCnt++] = 9;
break;
case 10:
{ jjCheckNAddStates(8, 10); }
break;
case 15:
- if (curChar == 34 && kind > 21)
- kind = 21;
+ if (curChar == 34 && kind > 24)
+ kind = 24;
break;
case 16:
if ((0x3ff000000000000L & l) == 0L)
break;
- if (kind > 19)
- kind = 19;
+ if (kind > 22)
+ kind = 22;
{ jjCheckNAddStates(0, 4); }
break;
case 17:
if ((0x3ff000000000000L & l) == 0L)
break;
- if (kind > 19)
- kind = 19;
+ if (kind > 22)
+ kind = 22;
{ jjCheckNAddStates(11, 13); }
break;
case 18:
if (curChar != 46)
break;
- if (kind > 19)
- kind = 19;
+ if (kind > 22)
+ kind = 22;
{ jjCheckNAddTwoStates(19, 5); }
break;
case 19:
if ((0x3ff000000000000L & l) == 0L)
break;
- if (kind > 19)
- kind = 19;
+ if (kind > 22)
+ kind = 22;
{ jjCheckNAddTwoStates(19, 5); }
break;
case 20:
case 0:
if ((0x7fffffe07fffffeL & l) == 0L)
break;
- if (kind > 20)
- kind = 20;
+ if (kind > 23)
+ kind = 23;
{ jjCheckNAdd(9); }
break;
case 5:
case 9:
if ((0x7fffffe87fffffeL & l) == 0L)
break;
- if (kind > 20)
- kind = 20;
+ if (kind > 23)
+ kind = 23;
{ jjCheckNAdd(9); }
break;
case 11:
public static final String[] jjstrLiteralImages = {
"", null, "\117\122", "\101\116\104", "\116\117\124", null, "\74", "\74\75",
"\76", "\76\75", "\53", "\55", "\52", "\57", "\115\117\104", "\136", "\50", "\51",
-"\54", null, null, null, };
+"\54", "\111\106", "\124\110\105\116", "\105\114\123\105", null, null, null, };
protected Token jjFillToken()
{
final Token t;
"DEFAULT",
};
static final long[] jjtoToken = {
- 0x3ffffdL,
+ 0x1fffffdL,
};
static final long[] jjtoSkip = {
0x2L,