From b85d0dd0715058f57dc734b1b0c71634857e2e34 Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 30 Jul 2010 08:26:33 +0000 Subject: [PATCH] Improved table parser to also accept negative numbers git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16875 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/tableParser/TableParser.java | 62 +++-- .../sysdyn/tableParser/TableParser.jj | 14 +- .../tableParser/TableParserConstants.java | 3 + .../tableParser/TableParserTokenManager.java | 261 +++++++++++++----- 4 files changed, 234 insertions(+), 106 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.java index b829fbe1..2693343a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.java @@ -5,29 +5,41 @@ import java.util.ArrayList; public class TableParser implements TableParserConstants { ArrayList xTokens = new ArrayList(); + ArrayList yTokens = new ArrayList(); public ArrayList getXTokens() { return xTokens; } + public ArrayList getYTokens() { + return yTokens; + } + /*** Parser ********************************************************/ final public void table() throws ParseException { - jj_consume_token(6); - table_element(); - label_1: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 13: - ; - break; - default: - jj_la1[0] = jj_gen; - break label_1; - } - jj_consume_token(13); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + jj_consume_token(6); table_element(); + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 13: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + jj_consume_token(13); + table_element(); + } + jj_consume_token(7); + break; + default: + jj_la1[1] = jj_gen; + ; } - jj_consume_token(7); jj_consume_token(0); } @@ -46,23 +58,19 @@ public class TableParser implements TableParserConstants { final public void y_value() throws ParseException { signed_number(); + yTokens.add(token); } final public void signed_number() throws ParseException { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 28: - jj_consume_token(28); + case UNSIGNED_INTEGER: + jj_consume_token(UNSIGNED_INTEGER); break; - default: - jj_la1[1] = jj_gen; - ; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case UNSIGNED_NUMBER: jj_consume_token(UNSIGNED_NUMBER); break; - case UNSIGNED_INTEGER: - jj_consume_token(UNSIGNED_INTEGER); + case SIGNED_NUMBER: + jj_consume_token(SIGNED_NUMBER); break; default: jj_la1[2] = jj_gen; @@ -88,10 +96,10 @@ public class TableParser implements TableParserConstants { jj_la1_init_1(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x2000,0x10000000,0x0,}; + jj_la1_0 = new int[] {0x2000,0x40,0x0,}; } private static void jj_la1_init_1() { - jj_la1_1 = new int[] {0x0,0x0,0x60000,}; + jj_la1_1 = new int[] {0x0,0x0,0xe0000,}; } /** Constructor with InputStream. */ @@ -208,7 +216,7 @@ public class TableParser implements TableParserConstants { /** Generate ParseException. */ public ParseException generateParseException() { jj_expentries.clear(); - boolean[] la1tokens = new boolean[51]; + boolean[] la1tokens = new boolean[52]; if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; @@ -225,7 +233,7 @@ public class TableParser implements TableParserConstants { } } } - for (int i = 0; i < 51; i++) { + for (int i = 0; i < 52; i++) { if (la1tokens[i]) { jj_expentry = new int[1]; jj_expentry[0] = i; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.jj b/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.jj index e4bede05..988888e4 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.jj +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.jj @@ -10,11 +10,16 @@ import java.util.ArrayList; public class TableParser { ArrayList xTokens = new ArrayList(); + ArrayList yTokens = new ArrayList(); public ArrayList getXTokens() { return xTokens; } + public ArrayList getYTokens() { + return yTokens; + } + } PARSER_END(TableParser) @@ -48,13 +53,14 @@ TOKEN: | "." (["e","E"] )? | ["e","E"] ) > +| | ))> } /*** Parser ********************************************************/ void table() : { } { - "{" table_element() ( "," table_element() )* "}" + ( "{" table_element() ( "," table_element() )* "}" )? } void table_element() : { @@ -72,10 +78,12 @@ void x_value() : { void y_value() : { } { - signed_number() + signed_number() { + yTokens.add(token); + } } void signed_number() : { } { - ("-")? ( | ) + ( | | ) } \ No newline at end of file diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserConstants.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserConstants.java index 5404a888..ab745ea1 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserConstants.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserConstants.java @@ -24,6 +24,8 @@ public interface TableParserConstants { int UNSIGNED_INTEGER = 49; /** RegularExpression Id. */ int UNSIGNED_NUMBER = 50; + /** RegularExpression Id. */ + int SIGNED_NUMBER = 51; /** Lexical state. */ int DEFAULT = 0; @@ -81,6 +83,7 @@ public interface TableParserConstants { "", "", "", + "", }; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserTokenManager.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserTokenManager.java index 20f1e07a..3653b9d9 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserTokenManager.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserTokenManager.java @@ -16,13 +16,15 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0) { case 0: if ((active0 & 0x100000000L) != 0L) - return 13; + return 24; if ((active0 & 0x7f80001fc000L) != 0L) { jjmatchedKind = 47; return 2; } if ((active0 & 0x1660000400L) != 0L) + return 46; + if ((active0 & 0x10000000L) != 0L) return 9; return -1; case 1: @@ -143,12 +145,12 @@ private int jjMoveStringLiteralDfa0_0() case 44: return jjStopAtPos(0, 13); case 45: - return jjStopAtPos(0, 28); + return jjStartNfaWithStates_0(0, 28, 9); case 46: jjmatchedKind = 10; return jjMoveStringLiteralDfa1_0(0x1660000000L); case 47: - return jjStartNfaWithStates_0(0, 32, 13); + return jjStartNfaWithStates_0(0, 32, 24); case 58: jjmatchedKind = 11; return jjMoveStringLiteralDfa1_0(0x4000000000L); @@ -522,7 +524,7 @@ static final long[] jjbitVec0 = { private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; - jjnewStateCnt = 31; + jjnewStateCnt = 46; int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; @@ -537,34 +539,60 @@ private int jjMoveNfa_0(int startState, int curPos) { switch(jjstateSet[--i]) { - case 13: + case 24: if (curChar == 47) { if (kind > 3) kind = 3; - jjCheckNAdd(20); + jjCheckNAdd(31); } else if (curChar == 42) jjCheckNAddStates(0, 2); break; + case 46: + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 51) + kind = 51; + jjCheckNAddTwoStates(10, 11); + } + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 50) + kind = 50; + jjCheckNAddTwoStates(43, 44); + } + break; + case 9: + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 51) + kind = 51; + jjCheckNAddStates(3, 7); + } + else if (curChar == 46) + jjCheckNAdd(10); + break; case 0: if ((0x3ff000000000000L & l) != 0L) { if (kind > 49) kind = 49; - jjCheckNAddStates(3, 7); + jjCheckNAddStates(8, 17); } else if ((0x100002600L & l) != 0L) { if (kind > 1) kind = 1; } - else if (curChar == 47) - jjAddStates(8, 9); else if (curChar == 46) - jjCheckNAdd(9); + jjCheckNAddTwoStates(43, 10); + else if (curChar == 47) + jjAddStates(18, 19); + else if (curChar == 45) + jjAddStates(20, 21); else if (curChar == 34) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(22, 24); break; case 2: if ((0x3ff000000000000L & l) == 0L) @@ -575,125 +603,193 @@ private int jjMoveNfa_0(int startState, int curPos) break; case 3: if (curChar == 34) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(22, 24); break; case 4: if ((0xfffffffbfffffbffL & l) != 0L) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(22, 24); break; case 6: if ((0xfffffffffffffbffL & l) != 0L) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(22, 24); break; case 7: if (curChar == 34 && kind > 48) kind = 48; break; case 8: - if (curChar == 46) - jjCheckNAdd(9); + if (curChar == 45) + jjAddStates(20, 21); break; - case 9: + case 10: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 50) - kind = 50; - jjCheckNAddTwoStates(9, 10); + if (kind > 51) + kind = 51; + jjCheckNAddTwoStates(10, 11); break; - case 11: + case 12: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 50) - kind = 50; - jjstateSet[jjnewStateCnt++] = 11; + if (kind > 51) + kind = 51; + jjstateSet[jjnewStateCnt++] = 12; break; - case 12: - if (curChar == 47) - jjAddStates(8, 9); + case 13: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 51) + kind = 51; + jjCheckNAddStates(3, 7); break; case 14: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 51) + kind = 51; + jjCheckNAdd(14); + break; + case 15: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(15, 16); + break; + case 17: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 51) + kind = 51; + jjstateSet[jjnewStateCnt++] = 17; + break; + case 18: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(18, 19); + break; + case 19: + if (curChar != 46) + break; + if (kind > 51) + kind = 51; + jjCheckNAddTwoStates(20, 21); + break; + case 20: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 51) + kind = 51; + jjCheckNAddTwoStates(20, 21); + break; + case 22: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 51) + kind = 51; + jjstateSet[jjnewStateCnt++] = 22; + break; + case 23: + if (curChar == 47) + jjAddStates(18, 19); + break; + case 25: if ((0xfffffbffffffffffL & l) != 0L) jjCheckNAddStates(0, 2); break; - case 15: + case 26: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 16; + jjstateSet[jjnewStateCnt++] = 27; break; - case 16: + case 27: if ((0xffff7fffffffffffL & l) != 0L) jjCheckNAddStates(0, 2); break; - case 17: + case 28: if (curChar == 47 && kind > 2) kind = 2; break; - case 18: + case 29: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 17; + jjstateSet[jjnewStateCnt++] = 28; break; - case 19: + case 30: if (curChar != 47) break; if (kind > 3) kind = 3; - jjCheckNAdd(20); + jjCheckNAdd(31); break; - case 20: + case 31: if ((0xfffffffffffffbffL & l) == 0L) break; if (kind > 3) kind = 3; - jjCheckNAdd(20); + jjCheckNAdd(31); break; - case 21: + case 32: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 49) kind = 49; - jjCheckNAddStates(3, 7); + jjCheckNAddStates(8, 17); break; - case 22: + case 33: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 49) kind = 49; - jjCheckNAdd(22); + jjCheckNAdd(33); break; - case 23: + case 34: if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(23, 24); + jjCheckNAddTwoStates(34, 35); break; - case 24: + case 35: if (curChar != 46) break; if (kind > 50) kind = 50; - jjCheckNAddTwoStates(25, 26); + jjCheckNAddTwoStates(36, 37); break; - case 25: + case 36: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 50) kind = 50; - jjCheckNAddTwoStates(25, 26); + jjCheckNAddTwoStates(36, 37); break; - case 27: + case 38: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 50) kind = 50; - jjstateSet[jjnewStateCnt++] = 27; + jjstateSet[jjnewStateCnt++] = 38; break; - case 28: + case 39: if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(28, 29); + jjCheckNAddTwoStates(39, 40); break; - case 30: + case 41: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 50) kind = 50; - jjstateSet[jjnewStateCnt++] = 30; + jjstateSet[jjnewStateCnt++] = 41; + break; + case 42: + if (curChar == 46) + jjCheckNAddTwoStates(43, 10); + break; + case 43: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 50) + kind = 50; + jjCheckNAddTwoStates(43, 44); + break; + case 45: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 50) + kind = 50; + jjstateSet[jjnewStateCnt++] = 45; break; default : break; } @@ -716,35 +812,47 @@ private int jjMoveNfa_0(int startState, int curPos) break; case 4: if ((0xffffffffefffffffL & l) != 0L) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(22, 24); break; case 5: if (curChar == 92) jjstateSet[jjnewStateCnt++] = 6; break; case 6: - jjCheckNAddStates(10, 12); + jjCheckNAddStates(22, 24); break; - case 10: + case 11: if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 11; + jjstateSet[jjnewStateCnt++] = 12; break; - case 14: case 16: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 17; + break; + case 21: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 22; + break; + case 25: + case 27: jjCheckNAddStates(0, 2); break; - case 20: + case 31: if (kind > 3) kind = 3; - jjstateSet[jjnewStateCnt++] = 20; + jjstateSet[jjnewStateCnt++] = 31; break; - case 26: + case 37: if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 27; + jjstateSet[jjnewStateCnt++] = 38; break; - case 29: + case 40: if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 30; + jjstateSet[jjnewStateCnt++] = 41; + break; + case 44: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 45; break; default : break; } @@ -761,19 +869,19 @@ private int jjMoveNfa_0(int startState, int curPos) case 4: case 6: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(22, 24); break; - case 14: - case 16: + case 25: + case 27: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(0, 2); break; - case 20: + case 31: if ((jjbitVec0[i2] & l2) == 0L) break; if (kind > 3) kind = 3; - jjstateSet[jjnewStateCnt++] = 20; + jjstateSet[jjnewStateCnt++] = 31; break; default : break; } @@ -786,14 +894,15 @@ private int jjMoveNfa_0(int startState, int curPos) kind = 0x7fffffff; } ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 31 - (jjnewStateCnt = startsAt))) + if ((i = jjnewStateCnt) == (startsAt = 46 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } } } static final int[] jjnextStates = { - 14, 15, 18, 22, 23, 24, 28, 29, 13, 19, 4, 5, 7, + 25, 26, 29, 14, 15, 16, 18, 19, 33, 34, 35, 39, 40, 14, 15, 16, + 18, 19, 24, 30, 9, 13, 4, 5, 7, }; /** Token literal values. */ @@ -805,21 +914,21 @@ public static final String[] jjstrLiteralImages = { "\136", "\56\136", "\75", "\72\75", "\146\141\154\163\145", "\164\162\165\145", "\145\156\144", "\141\156\156\157\164\141\164\151\157\156", "\145\141\143\150", "\146\151\156\145", "\162\145\144\145\143\154\141\162\145", -"\162\145\160\154\141\143\145\141\142\154\145", null, null, null, null, }; +"\162\145\160\154\141\143\145\141\142\154\145", null, null, null, null, null, }; /** Lexer state names. */ public static final String[] lexStateNames = { "DEFAULT", }; static final long[] jjtoToken = { - 0x7fffffffffff1L, + 0xffffffffffff1L, }; static final long[] jjtoSkip = { 0xeL, }; protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[31]; -private final int[] jjstateSet = new int[62]; +private final int[] jjrounds = new int[46]; +private final int[] jjstateSet = new int[92]; private final StringBuilder jjimage = new StringBuilder(); private StringBuilder image = jjimage; private int jjimageLen; @@ -850,7 +959,7 @@ private void ReInitRounds() { int i; jjround = 0x80000001; - for (i = 31; i-- > 0;) + for (i = 46; i-- > 0;) jjrounds[i] = 0x80000000; } -- 2.47.1