From 3f12ba020c95cc8016e1f721f35f6dcf472676cf Mon Sep 17 00:00:00 2001 From: lempinen Date: Mon, 20 Dec 2010 16:00:55 +0000 Subject: [PATCH] better support for arrays and for loops git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19173 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../expressionParser/ExpressionParser.java | 449 +++++++++++------- .../expressionParser/ExpressionParser.jj | 65 ++- 2 files changed, 325 insertions(+), 189 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java index 4eba9ba1..083230fd 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java @@ -10,6 +10,8 @@ import java.util.HashMap; public class ExpressionParser implements ExpressionParserConstants { + boolean forIndex = false; + HashMap> references = new HashMap>(); public HashMap> getReferences() { @@ -22,6 +24,20 @@ public class ExpressionParser implements ExpressionParserConstants { return ranges; } + List currentRange = null; + + HashMap> forIndices = new HashMap>(); + + public HashMap> getForIndices() { + return forIndices; + } + + HashMap> enumerationReferences = new HashMap>(); + + public HashMap> getEnumerationReferences() { + return enumerationReferences; + } + /*** Parser ********************************************************/ // https://javacc.dev.java.net/doc/javaccgrm.html @@ -385,7 +401,7 @@ public class ExpressionParser implements ExpressionParserConstants { } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IDENT: - component_reference(); + component_reference(null); break; case 62: jj_consume_token(62); @@ -440,14 +456,28 @@ public class ExpressionParser implements ExpressionParserConstants { } } - final public void component_reference() throws ParseException { + final public void component_reference(Token prevToken) throws ParseException { jj_consume_token(IDENT); String name = token.image; - if(references.get(name) == null) { - references.put(name, new ArrayList()); + + // prevToken != null => this is the second part of an enumeration + if(forIndex == true && prevToken != null) { + if(enumerationReferences.get(prevToken.image) == null) { + enumerationReferences.put(prevToken.image, new ArrayList()); + } + List list = enumerationReferences.get(prevToken.image); + list.add(token); + + // prevToken == null => this is a normal variable + } else { + if(references.get(name) == null) { + references.put(name, new ArrayList()); + } + List list = references.get(name); + list.add(token); } - List list = references.get(name); - list.add(token); + + Token curToken = token; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 66: array_subscripts(); @@ -459,7 +489,7 @@ public class ExpressionParser implements ExpressionParserConstants { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 68: jj_consume_token(68); - component_reference(); + component_reference(curToken); break; default: jj_la1[23] = jj_gen; @@ -499,12 +529,25 @@ public class ExpressionParser implements ExpressionParserConstants { if (jj_2_2(2)) { expression(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 21: case 71: - jj_consume_token(71); - function_arguments(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + jj_consume_token(71); + function_arguments(); + break; + case 21: + jj_consume_token(21); + for_indices(); + break; + default: + jj_la1[25] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } break; default: - jj_la1[25] = jj_gen; + jj_la1[26] = jj_gen; ; } } else { @@ -513,13 +556,46 @@ public class ExpressionParser implements ExpressionParserConstants { named_arguments(); break; default: - jj_la1[26] = jj_gen; + jj_la1[27] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } } + final public void for_indices() throws ParseException { + for_index(); + label_8: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[28] = jj_gen; + break label_8; + } + jj_consume_token(71); + for_index(); + } + } + + final public void for_index() throws ParseException { + jj_consume_token(IDENT); + forIndices.put(token, currentRange); + forIndex = true; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 41: + jj_consume_token(41); + expression(); + break; + default: + jj_la1[29] = jj_gen; + ; + } + forIndex = false; + } + final public void named_arguments() throws ParseException { named_argument(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -528,7 +604,7 @@ public class ExpressionParser implements ExpressionParserConstants { named_arguments(); break; default: - jj_la1[27] = jj_gen; + jj_la1[30] = jj_gen; ; } } @@ -560,18 +636,18 @@ public class ExpressionParser implements ExpressionParserConstants { expression(); break; default: - jj_la1[28] = jj_gen; + jj_la1[31] = jj_gen; ; } - label_8: + label_9: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 71: ; break; default: - jj_la1[29] = jj_gen; - break label_8; + jj_la1[32] = jj_gen; + break label_9; } jj_consume_token(71); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -594,7 +670,7 @@ public class ExpressionParser implements ExpressionParserConstants { expression(); break; default: - jj_la1[30] = jj_gen; + jj_la1[33] = jj_gen; ; } } @@ -602,15 +678,15 @@ public class ExpressionParser implements ExpressionParserConstants { final public void expression_list() throws ParseException { expression(); - label_9: + label_10: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 71: ; break; default: - jj_la1[31] = jj_gen; - break label_9; + jj_la1[34] = jj_gen; + break label_10; } jj_consume_token(71); expression(); @@ -622,18 +698,18 @@ public class ExpressionParser implements ExpressionParserConstants { ranges.put(token.image, new ArrayList>()); } List> rangesList = ranges.get(token.image); - List currentRange = new ArrayList(); + currentRange = new ArrayList(); jj_consume_token(66); subscript(currentRange); - label_10: + label_11: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 71: ; break; default: - jj_la1[32] = jj_gen; - break label_10; + jj_la1[35] = jj_gen; + break label_11; } jj_consume_token(71); subscript(currentRange); @@ -660,7 +736,7 @@ public class ExpressionParser implements ExpressionParserConstants { rangeIndex(rangeToken, true); break; default: - jj_la1[33] = jj_gen; + jj_la1[36] = jj_gen; ; } rangeToken.endColumn = token.endColumn; @@ -668,7 +744,7 @@ public class ExpressionParser implements ExpressionParserConstants { currentRange.add(rangeToken); break; default: - jj_la1[34] = jj_gen; + jj_la1[37] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -687,7 +763,7 @@ public class ExpressionParser implements ExpressionParserConstants { rangeToken.image = rangeToken.image + token.image; break; default: - jj_la1[35] = jj_gen; + jj_la1[38] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -707,82 +783,62 @@ public class ExpressionParser implements ExpressionParserConstants { finally { jj_save(1, xla); } } - private boolean jj_3R_14() { - if (jj_scan_token(68)) return true; - if (jj_3R_11()) return true; - return false; - } - - private boolean jj_3R_44() { - if (jj_scan_token(IDENT)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_48()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_49()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_11() { - if (jj_scan_token(IDENT)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_14()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3_1() { - if (jj_3R_11()) return true; - if (jj_scan_token(62)) return true; - return false; - } - - private boolean jj_3R_42() { + private boolean jj_3R_45() { if (jj_scan_token(87)) return true; return false; } - private boolean jj_3R_41() { + private boolean jj_3R_44() { if (jj_scan_token(64)) return true; - if (jj_3R_47()) return true; + if (jj_3R_50()) return true; return false; } - private boolean jj_3R_40() { + private boolean jj_3R_43() { if (jj_scan_token(66)) return true; - if (jj_3R_46()) return true; + if (jj_3R_49()) return true; return false; } - private boolean jj_3R_37() { - if (jj_3R_11()) return true; - if (jj_3R_43()) return true; + private boolean jj_3R_40() { + if (jj_3R_12()) return true; + if (jj_3R_46()) return true; return false; } - private boolean jj_3R_39() { + private boolean jj_3R_42() { if (jj_scan_token(62)) return true; - if (jj_3R_45()) return true; + if (jj_3R_48()) return true; if (jj_scan_token(63)) return true; return false; } - private boolean jj_3R_35() { + private boolean jj_3R_38() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(86)) { jj_scanpos = xsp; - if (jj_3R_42()) return true; + if (jj_3R_45()) return true; } return false; } - private boolean jj_3R_38() { - if (jj_3R_44()) return true; + private boolean jj_3R_41() { + if (jj_3R_47()) return true; return false; } - private boolean jj_3R_34() { + private boolean jj_3R_53() { + if (jj_3R_13()) return true; + return false; + } + + private boolean jj_3R_49() { + if (jj_3R_13()) return true; + return false; + } + + private boolean jj_3R_37() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(93)) { @@ -795,15 +851,15 @@ public class ExpressionParser implements ExpressionParserConstants { jj_scanpos = xsp; if (jj_scan_token(33)) { jj_scanpos = xsp; - if (jj_3R_37()) { + if (jj_3R_40()) { jj_scanpos = xsp; - if (jj_3R_38()) { + if (jj_3R_41()) { jj_scanpos = xsp; - if (jj_3R_39()) { + if (jj_3R_42()) { jj_scanpos = xsp; - if (jj_3R_40()) { + if (jj_3R_43()) { jj_scanpos = xsp; - if (jj_3R_41()) { + if (jj_3R_44()) { jj_scanpos = xsp; if (jj_scan_token(35)) return true; } @@ -819,22 +875,38 @@ public class ExpressionParser implements ExpressionParserConstants { return false; } - private boolean jj_3R_33() { - if (jj_3R_36()) return true; + private boolean jj_3R_48() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_53()) jj_scanpos = xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_54()) { jj_scanpos = xsp; break; } + } return false; } - private boolean jj_3R_26() { - if (jj_3R_30()) return true; + private boolean jj_3R_58() { + if (jj_scan_token(IDENT)) return true; + return false; + } + + private boolean jj_3R_36() { + if (jj_3R_39()) return true; return false; } private boolean jj_3R_29() { - if (jj_3R_31()) return true; + if (jj_3R_33()) return true; return false; } - private boolean jj_3R_36() { + private boolean jj_3R_32() { + if (jj_3R_34()) return true; + return false; + } + + private boolean jj_3R_39() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(82)) { @@ -850,40 +922,45 @@ public class ExpressionParser implements ExpressionParserConstants { return false; } - private boolean jj_3R_32() { - if (jj_3R_34()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_35()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_51() { + private boolean jj_3R_18() { if (jj_scan_token(71)) return true; return false; } - private boolean jj_3R_28() { - if (jj_3R_32()) return true; + private boolean jj_3R_14() { Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_33()) { jj_scanpos = xsp; break; } + xsp = jj_scanpos; + if (jj_3R_18()) { + jj_scanpos = xsp; + if (jj_3R_19()) return true; } return false; } - private boolean jj_3R_53() { - if (jj_scan_token(66)) return true; + private boolean jj_3R_35() { + if (jj_3R_37()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_38()) jj_scanpos = xsp; return false; } - private boolean jj_3R_13() { - if (jj_scan_token(71)) return true; + private boolean jj_3R_57() { + if (jj_3R_58()) return true; return false; } private boolean jj_3R_31() { + if (jj_3R_35()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_36()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_34() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(78)) { @@ -899,29 +976,34 @@ public class ExpressionParser implements ExpressionParserConstants { return false; } - private boolean jj_3R_23() { + private boolean jj_3R_52() { + if (jj_scan_token(68)) return true; + return false; + } + + private boolean jj_3R_26() { if (jj_scan_token(9)) return true; return false; } - private boolean jj_3R_27() { - if (jj_3R_31()) return true; + private boolean jj_3R_30() { + if (jj_3R_34()) return true; return false; } - private boolean jj_3R_25() { + private boolean jj_3R_28() { Token xsp; xsp = jj_scanpos; - if (jj_3R_27()) jj_scanpos = xsp; - if (jj_3R_28()) return true; + if (jj_3R_30()) jj_scanpos = xsp; + if (jj_3R_31()) return true; while (true) { xsp = jj_scanpos; - if (jj_3R_29()) { jj_scanpos = xsp; break; } + if (jj_3R_32()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_30() { + private boolean jj_3R_33() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(72)) { @@ -943,147 +1025,156 @@ public class ExpressionParser implements ExpressionParserConstants { return false; } - private boolean jj_3R_19() { + private boolean jj_3R_22() { if (jj_scan_token(69)) return true; return false; } - private boolean jj_3R_21() { + private boolean jj_3R_24() { if (jj_scan_token(22)) return true; return false; } - private boolean jj_3R_50() { - if (jj_3R_12()) return true; - return false; - } - - private boolean jj_3R_46() { - if (jj_3R_12()) return true; + private boolean jj_3R_55() { + if (jj_3R_57()) return true; return false; } - private boolean jj_3R_24() { - if (jj_3R_25()) return true; + private boolean jj_3R_27() { + if (jj_3R_28()) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_26()) jj_scanpos = xsp; + if (jj_3R_29()) jj_scanpos = xsp; return false; } - private boolean jj_3R_45() { + private boolean jj_3R_50() { Token xsp; xsp = jj_scanpos; - if (jj_3R_50()) jj_scanpos = xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_51()) { jj_scanpos = xsp; break; } + if (jj_3_2()) { + jj_scanpos = xsp; + if (jj_3R_55()) return true; } return false; } - private boolean jj_3R_49() { - if (jj_scan_token(68)) return true; + private boolean jj_3_2() { + if (jj_3R_13()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_14()) jj_scanpos = xsp; return false; } - private boolean jj_3R_22() { + private boolean jj_3R_25() { Token xsp; xsp = jj_scanpos; if (jj_scan_token(12)) jj_scanpos = xsp; - if (jj_3R_24()) return true; + if (jj_3R_27()) return true; return false; } - private boolean jj_3R_55() { - if (jj_scan_token(IDENT)) return true; + private boolean jj_3R_46() { + if (jj_scan_token(62)) return true; return false; } - private boolean jj_3R_20() { - if (jj_3R_22()) return true; + private boolean jj_3R_23() { + if (jj_3R_25()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_23()) { jj_scanpos = xsp; break; } + if (jj_3R_26()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_54() { - if (jj_3R_55()) return true; - return false; - } - - private boolean jj_3R_52() { - if (jj_3R_54()) return true; + private boolean jj_3R_51() { + if (jj_3R_56()) return true; return false; } - private boolean jj_3R_18() { - if (jj_3R_20()) return true; + private boolean jj_3R_21() { + if (jj_3R_23()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_21()) { jj_scanpos = xsp; break; } + if (jj_3R_24()) { jj_scanpos = xsp; break; } } return false; } - private boolean jj_3R_47() { + private boolean jj_3R_20() { + if (jj_3R_21()) return true; Token xsp; xsp = jj_scanpos; - if (jj_3_2()) { + if (jj_3R_22()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_17() { + if (jj_scan_token(31)) return true; + if (jj_3R_13()) return true; + return false; + } + + private boolean jj_3R_13() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_16()) { jj_scanpos = xsp; - if (jj_3R_52()) return true; + if (jj_3R_17()) return true; } return false; } - private boolean jj_3_2() { + private boolean jj_3R_16() { + if (jj_3R_20()) return true; + return false; + } + + private boolean jj_3R_15() { + if (jj_scan_token(68)) return true; if (jj_3R_12()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_13()) jj_scanpos = xsp; return false; } - private boolean jj_3R_17() { - if (jj_3R_18()) return true; + private boolean jj_3R_47() { + if (jj_scan_token(IDENT)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_19()) jj_scanpos = xsp; + if (jj_3R_51()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_52()) jj_scanpos = xsp; return false; } - private boolean jj_3R_16() { - if (jj_scan_token(31)) return true; - if (jj_3R_12()) return true; + private boolean jj_3R_54() { + if (jj_scan_token(71)) return true; return false; } - private boolean jj_3R_43() { - if (jj_scan_token(62)) return true; + private boolean jj_3R_19() { + if (jj_scan_token(21)) return true; return false; } private boolean jj_3R_12() { + if (jj_scan_token(IDENT)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_15()) { - jj_scanpos = xsp; - if (jj_3R_16()) return true; - } + if (jj_3R_15()) jj_scanpos = xsp; return false; } - private boolean jj_3R_15() { - if (jj_3R_17()) return true; + private boolean jj_3R_56() { + if (jj_scan_token(66)) return true; return false; } - private boolean jj_3R_48() { - if (jj_3R_53()) return true; + private boolean jj_3_1() { + if (jj_3R_12()) return true; + if (jj_scan_token(62)) return true; return false; } @@ -1098,7 +1189,7 @@ public class ExpressionParser implements ExpressionParserConstants { private Token jj_scanpos, jj_lastpos; private int jj_la; private int jj_gen; - final private int[] jj_la1 = new int[36]; + final private int[] jj_la1 = new int[39]; static private int[] jj_la1_0; static private int[] jj_la1_1; static private int[] jj_la1_2; @@ -1108,13 +1199,13 @@ public class ExpressionParser implements ExpressionParserConstants { jj_la1_init_2(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x100000,0x80001040,0x100000,0x80001040,0x0,0x0,0x400000,0x200,0x1000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x80001040,0x0,0x0,0x0,0x80001040,0x0,0x80001040,0x0,0x0,0x0,0x0,0x0,}; + jj_la1_0 = new int[] {0x100000,0x80001040,0x100000,0x80001040,0x0,0x0,0x400000,0x200,0x1000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x80001040,0x200000,0x200000,0x0,0x0,0x0,0x0,0x80001040,0x0,0x80001040,0x0,0x0,0x0,0x0,0x0,}; } private static void jj_la1_init_1() { - jj_la1_1 = new int[] {0x0,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x40000008,0x0,0x0,0x0,0x4000000a,0x0,0x0,0x0,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,}; + jj_la1_1 = new int[] {0x0,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x40000008,0x0,0x0,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x200,0x0,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,}; } private static void jj_la1_init_2() { - jj_la1_2 = new int[] {0x0,0x3c03c005,0x0,0x3c03c005,0x20,0x20,0x0,0x0,0x0,0x3f00,0x3f00,0x3c000,0x3c000,0x3c000,0x3c0000,0xc00000,0xc00000,0x3c0000,0x40,0x38000000,0x4000005,0x10,0x4,0x10,0x3c03c005,0x80,0x4000000,0x80,0x3c03c005,0x80,0x3c03c005,0x80,0x80,0x20,0x14000020,0x14000000,}; + jj_la1_2 = new int[] {0x0,0x3c03c005,0x0,0x3c03c005,0x20,0x20,0x0,0x0,0x0,0x3f00,0x3f00,0x3c000,0x3c000,0x3c000,0x3c0000,0xc00000,0xc00000,0x3c0000,0x40,0x38000000,0x4000005,0x10,0x4,0x10,0x3c03c005,0x80,0x80,0x4000000,0x80,0x0,0x80,0x3c03c005,0x80,0x3c03c005,0x80,0x80,0x20,0x14000020,0x14000000,}; } final private JJCalls[] jj_2_rtns = new JJCalls[2]; private boolean jj_rescan = false; @@ -1131,7 +1222,7 @@ public class ExpressionParser implements ExpressionParserConstants { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 36; i++) jj_la1[i] = -1; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -1146,7 +1237,7 @@ public class ExpressionParser implements ExpressionParserConstants { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 36; i++) jj_la1[i] = -1; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -1157,7 +1248,7 @@ public class ExpressionParser implements ExpressionParserConstants { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 36; i++) jj_la1[i] = -1; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -1168,7 +1259,7 @@ public class ExpressionParser implements ExpressionParserConstants { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 36; i++) jj_la1[i] = -1; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -1178,7 +1269,7 @@ public class ExpressionParser implements ExpressionParserConstants { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 36; i++) jj_la1[i] = -1; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -1188,7 +1279,7 @@ public class ExpressionParser implements ExpressionParserConstants { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 36; i++) jj_la1[i] = -1; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -1305,7 +1396,7 @@ public class ExpressionParser implements ExpressionParserConstants { la1tokens[jj_kind] = true; jj_kind = -1; } - for (int i = 0; i < 36; i++) { + for (int i = 0; i < 39; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<> references = new HashMap>(); public HashMap> getReferences() { @@ -26,6 +28,20 @@ public class ExpressionParser { public HashMap>> getRanges() { return ranges; } + + List currentRange = null; + + HashMap> forIndices = new HashMap>(); + + public HashMap> getForIndices() { + return forIndices; + } + + HashMap> enumerationReferences = new HashMap>(); + + public HashMap> getEnumerationReferences() { + return enumerationReferences; + } } @@ -155,7 +171,7 @@ void primary() : { | "false" | "true" | LOOKAHEAD( name() "(" ) name() function_call_args() - | component_reference() + | component_reference(null) | "(" output_expression_list() ")" | "[" expression_list() ( ";" expression_list() )* "]" | "{" function_arguments() "}" @@ -167,19 +183,31 @@ void name() : { ( "." name() )? } -void component_reference() : { +void component_reference(Token prevToken) : { } { //IDENT [ array_subscripts ] [ "." component_reference ] { String name = token.image; - if(references.get(name) == null) { - references.put(name, new ArrayList()); + + // prevToken != null => this is the second part of an enumeration + if(forIndex == true && prevToken != null) { + if(enumerationReferences.get(prevToken.image) == null) { enumerationReferences.put(prevToken.image, new ArrayList()); + } + List list = enumerationReferences.get(prevToken.image); + list.add(token); + + // prevToken == null => this is a normal variable + } else { if(references.get(name) == null) { + references.put(name, new ArrayList()); + } + List list = references.get(name); + list.add(token); } - List list = references.get(name); - list.add(token); + + Token curToken = token; } - ( array_subscripts() )? ( "." component_reference() )? + ( array_subscripts() )? ( "." component_reference(curToken) )? } @@ -192,9 +220,26 @@ void function_arguments() : { } { //expression [ "," function_arguments | for for_indices ] //| named_arguments - LOOKAHEAD(2) expression() ( "," function_arguments())? + LOOKAHEAD(2) expression() ( "," function_arguments() | "for" for_indices() )? | named_arguments() -} +} + +void for_indices() : { +} { + //for_index {"," for_index} + for_index() ("," for_index())* +} + +void for_index() : { +} { + //IDENT [ in expression ] + { + forIndices.put(token, currentRange); + forIndex = true; } + ( "in" expression() )? + { forIndex = false; + } +} void named_arguments() : { } { @@ -221,7 +266,7 @@ void array_subscripts() : { if(ranges.get(token.image) == null) { ranges.put(token.image, new ArrayList>()); } List> rangesList = ranges.get(token.image); - List currentRange = new ArrayList(); + currentRange = new ArrayList(); } { "[" subscript(currentRange) ( "," subscript(currentRange) )* "]" { -- 2.47.1