private object DereferenceLeft(LexObject lexObject, int x, ArrayList LeftItems, ArrayList leftlex, LexObject rlex, ArrayList MidItems, LexObject midlex) { ArrayList al = new ArrayList(); if (lexObject.isText) { for (int i = 0; i < x; i++) { al.Add(lexObject.text); } return(al); } else { if (lexObject.index == -1) { for (int i = 0; i < MidItems.Count; i++) { al.Add(TranslateArray(MidItems[i].ToString(), midlex, rlex)); } } else { int lindex = getRealIndex(lexObject.index, leftlex); ArrayList cutitem = (ArrayList)LeftItems[lindex]; for (int i = 0; i < cutitem.Count; i++) { al.Add(TranslateArray(cutitem[i].ToString(), (LexObject)leftlex[lindex], rlex)); } } } return(al); }
private string TranslateArray(string s, LexObject lex, LexObject rlex) { TLArray tl = (TLArray)Arrays[lex.pointer]; TLArray tx = (TLArray)Arrays[rlex.pointer]; for (int i = 0; i < tl.content.Count; i++) { if (s == tl.content[i].ToString()) { return(tx.content[i].ToString()); } } return(null); }
private int getNumbers(ArrayList leftlex) { int x = 1; for (int i = 0; i < leftlex.Count; i++) { LexObject lex = (LexObject)leftlex[i]; if (!lex.isText) { TLArray ta = (TLArray)Arrays[lex.pointer]; x *= ta.content.Count; } } return(x); }
private int getFactor(ArrayList leftlex, int ind) { int factor = 1; for (int i = 0; i <= ind; i++) { LexObject lex = (LexObject)leftlex[i]; if (!lex.isText) { TLArray tl = (TLArray)Arrays[lex.pointer]; factor *= tl.content.Count; } } return(factor); }
private int getRealIndex(int index, ArrayList leftlex) { int x = 0; for (int i = 0; i < leftlex.Count; i++) { LexObject lx = (LexObject)leftlex[i]; if (!lx.isText) { x++; if (x == index) { return(i); } } } return(-1); }
private ArrayList GenerateLex(LexObject L, int x, int ind, ArrayList leftlex) { ArrayList al = new ArrayList(); if (L.isText) { for (int i = 0; i < x; i++) { al.Add(L.text); } return(al); } else { TLArray tl = (TLArray)Arrays[L.pointer]; int fx = getFactor(leftlex, ind); int factor = x / fx; int h = 0; int y = 0; while (al.Count < x) { al.Add(tl.content[y]); h++; if (h == factor) { h = 0; y++; if (y == tl.content.Count) { y = 0; } } } return(al); } return(null); }
private ArrayList GenerateLex(LexObject L, int x, int ind, ArrayList leftlex) { ArrayList al = new ArrayList(); if (L.isText) { for (int i = 0; i < x; i++) { al.Add(L.text); } return al; } else { TLArray tl = (TLArray)Arrays[L.pointer]; int fx = getFactor(leftlex, ind); int factor = x / fx; int h = 0; int y = 0; while ( al.Count<x) { al.Add(tl.content[y]); h++; if (h == factor) { h = 0; y++; if (y == tl.content.Count) y = 0; } } return al; } return null; }
private string TranslateArray(string s,LexObject lex,LexObject rlex) { TLArray tl = (TLArray)Arrays[lex.pointer]; TLArray tx = (TLArray)Arrays[rlex.pointer]; for (int i = 0; i < tl.content.Count; i++) { if (s == tl.content[i].ToString()) { return tx.content[i].ToString(); } } return null; }
private object DereferenceLeft(LexObject lexObject, int x, ArrayList LeftItems, ArrayList leftlex,LexObject rlex,ArrayList MidItems,LexObject midlex) { ArrayList al = new ArrayList(); if (lexObject.isText) { for (int i = 0; i < x; i++) { al.Add(lexObject.text); } return al; } else { if (lexObject.index == -1) { for (int i = 0; i < MidItems.Count; i++) { al.Add(TranslateArray(MidItems[i].ToString(),midlex,rlex)); } } else { int lindex = getRealIndex(lexObject.index, leftlex); ArrayList cutitem = (ArrayList)LeftItems[lindex]; for (int i = 0; i < cutitem.Count; i++) { al.Add(TranslateArray(cutitem[i].ToString(), (LexObject)leftlex[lindex], rlex)); } } } return al; }
private void ProcessLex(ArrayList leftlex, LexObject midlex, ArrayList rightlex) { ArrayList LeftItems = new ArrayList(); int x = getNumbers(leftlex); if (!midlex.isText) { TLArray ta = (TLArray)Arrays[midlex.pointer]; x *= ta.content.Count; } for (int i = 0; i < leftlex.Count; i++) { LeftItems.Add(GenerateLex((LexObject)leftlex[i], x, i, leftlex)); } ArrayList MidItems = new ArrayList(); if (midlex.isText) { for (int i = 0; i < x; i++) { if (midlex.pointer == 98761197) MidItems.Add("delete"); else MidItems.Add(midlex.text); } } else { int h = 0; TLArray tl = (TLArray)Arrays[midlex.pointer]; while (MidItems.Count < x) { MidItems.Add(tl.content[h]); h++; if (h == tl.content.Count) { h = 0; } } } ArrayList RightItems = new ArrayList(); for (int i = 0; i < rightlex.Count; i++) { RightItems.Add(DereferenceLeft( (LexObject)rightlex[i], x,LeftItems,leftlex,(LexObject)rightlex[i],MidItems,midlex)); } for (int i = 0; i < x; i++) { string left = ""; string right = ""; for (int j = 0; j < LeftItems.Count; j++) { left += ((ArrayList)LeftItems[j])[i].ToString(); } for (int j = 0; j < RightItems.Count; j++) { right += ((ArrayList)RightItems[j])[i].ToString(); } ENI.Add(left); Lines.Add(line.ToString()); ENM.Add(MidItems[i]); ENO.Add(right); } }
private string ProcessContext(string currentline) { int state = 0; string tmp = ""; ArrayList leftlex = new ArrayList(); LexObject midlex = null; ArrayList rightlex = new ArrayList(); bool isleft = true; bool ismid = false; int point = 0; foreach (char c in currentline.ToCharArray()) { switch (state) { case 0: if (c == '\'') { state = 1; } else if (c == 'U') { state = 4; tmp = ""; } else if (c == ' ' || c == '\t') { } else if (c == '>') { isleft = false; tmp = ""; } else if (c == '+') { ismid = true; tmp = ""; //mid processing } else { tmp += c; state = 2; } break; case 1: if (c == '\\') { state = 3; } else if (c == '\'') { LexObject lex = new LexObject(); lex.isText = true; lex.text = tmp; if (isleft) { if (ismid) { midlex = lex; } else { leftlex.Add(lex); } } else { rightlex.Add(lex); } tmp = ""; state = 0; } else { tmp += c; } break; case 2: if (c == ' ' || c == '\t') { state = 0; if (isleft) { int pt = FindArray(tmp); if (pt < 0) { return "Error No Such Array - " + tmp; } else { if (ismid) { if (midlex == null) { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = -1; if (pt > 98761190) lex.isText = true; midlex = lex; } else { return "Error Input Key"; } } else { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; point++; lex.index = point; leftlex.Add(lex); } } } else { if (tmp[tmp.Length - 2] == '@') { string s = tmp.Substring(0, tmp.Length - 2); int pt = FindArray(s); if (pt >= 0) { string ind = tmp[tmp.Length - 1].ToString(); bool found = false; if (ind == "i") { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = -1; lex.text = s; rightlex.Add(lex); tmp = ""; state = 0; } else { for (int i = 0; i < leftlex.Count; i++) { LexObject tmplex = (LexObject)leftlex[i]; if (tmplex.index.ToString() == ind) { if (((TLArray)Arrays[pt]).content.Count == ((TLArray)Arrays[tmplex.pointer]).content.Count) { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = tmplex.index; lex.text = s; rightlex.Add(lex); found = true; tmp = ""; state = 0; } else { return "Error Array Length Mismatch"; } } } if (!found) return "Error Reference Pointer in Array - " + s; } }else{ return "Error No Such Array - " + s; } } else if (tmp == "null" || tmp == "beep") { LexObject lex = new LexObject(); lex.isText = true; lex.pointer = 98761190; lex.index = (tmp == "null") ? 98761199 : 98761198; lex.text = "_#_" + tmp; rightlex.Add(lex); tmp = ""; state = 0; } else { return "Error no pointer @ in Array - " + tmp; } } tmp = ""; } else { tmp += c; } break; case 3: if (c == '\\' || c == '\'') tmp += c; else return "Error Invalid Escape Character"; break; case 4: if (c == '+') state = 5; else return "Error Invalid Character"; break; case 5: if (checkHex(c)) { tmp += c; } else if (c == ' ' || c == '\t') { if (tmp.Length == 4) { int chx = Convert.ToInt32(tmp, 16); LexObject lex = new LexObject(); lex.isText = true; lex.text = ((char)chx).ToString(); if (isleft) { leftlex.Add(lex); } else rightlex.Add(lex); state = 0; tmp = ""; } else { return "Error Invalid Unicode Character"; } } else { return "Error Invalid Unicode Character"; } break; } } if (tmp.Length != 0) { if (state == 2) { if (tmp[tmp.Length - 2] == '@') { string s = tmp.Substring(0, tmp.Length - 2); int pt = FindArray(s); if (pt >= 0) { string ind = tmp[tmp.Length - 1].ToString(); bool found = false; if (ind == "i") { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = -1; lex.text = s; rightlex.Add(lex); tmp = ""; state = 0; } else { for (int i = 0; i < leftlex.Count; i++) { LexObject tmplex = (LexObject)leftlex[i]; if (tmplex.index.ToString() == ind) { if (((TLArray)Arrays[pt]).content.Count == ((TLArray)Arrays[tmplex.pointer]).content.Count) { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = tmplex.index; lex.text = s; rightlex.Add(lex); found = true; tmp = ""; state = 0; } else { return "Error Array Length Mismatch"; } } } if (!found) return "Error Reference Pointer in Array - " + s; } } else { return "Error No Such Array - " + s; } } else if (tmp == "null" || tmp == "beep") { LexObject lex = new LexObject(); lex.isText = true; lex.pointer = 98761190; lex.index = (tmp == "null") ? 98761199 : 98761198; lex.text = "_#_" + tmp; rightlex.Add(lex); tmp = ""; state = 0; } else { return "Error no pointer @ in Array - " + tmp; } } else if (state == 5) { if (tmp.Length == 4) { int chx = Convert.ToInt32(tmp, 16); LexObject lex = new LexObject(); lex.isText = true; lex.text = ((char)chx).ToString(); if (isleft) { leftlex.Add(lex); } else rightlex.Add(lex); state = 0; tmp = ""; } else { return "Error Invalid Unicode Character"; } } } ProcessLex(leftlex, midlex, rightlex); return "OK"; }
private void ProcessLex(ArrayList leftlex, LexObject midlex, ArrayList rightlex) { ArrayList LeftItems = new ArrayList(); int x = getNumbers(leftlex); if (!midlex.isText) { TLArray ta = (TLArray)Arrays[midlex.pointer]; x *= ta.content.Count; } for (int i = 0; i < leftlex.Count; i++) { LeftItems.Add(GenerateLex((LexObject)leftlex[i], x, i, leftlex)); } ArrayList MidItems = new ArrayList(); if (midlex.isText) { for (int i = 0; i < x; i++) { if (midlex.pointer == 98761197) { MidItems.Add("delete"); } else { MidItems.Add(midlex.text); } } } else { int h = 0; TLArray tl = (TLArray)Arrays[midlex.pointer]; while (MidItems.Count < x) { MidItems.Add(tl.content[h]); h++; if (h == tl.content.Count) { h = 0; } } } ArrayList RightItems = new ArrayList(); for (int i = 0; i < rightlex.Count; i++) { RightItems.Add(DereferenceLeft((LexObject)rightlex[i], x, LeftItems, leftlex, (LexObject)rightlex[i], MidItems, midlex)); } for (int i = 0; i < x; i++) { string left = ""; string right = ""; for (int j = 0; j < LeftItems.Count; j++) { left += ((ArrayList)LeftItems[j])[i].ToString(); } for (int j = 0; j < RightItems.Count; j++) { right += ((ArrayList)RightItems[j])[i].ToString(); } ENI.Add(left); Lines.Add(line.ToString()); ENM.Add(MidItems[i]); ENO.Add(right); } }
private string ProcessContext(string currentline) { int state = 0; string tmp = ""; ArrayList leftlex = new ArrayList(); LexObject midlex = null; ArrayList rightlex = new ArrayList(); bool isleft = true; bool ismid = false; int point = 0; foreach (char c in currentline.ToCharArray()) { switch (state) { case 0: if (c == '\'') { state = 1; } else if (c == 'U') { state = 4; tmp = ""; } else if (c == ' ' || c == '\t') { } else if (c == '>') { isleft = false; tmp = ""; } else if (c == '+') { ismid = true; tmp = ""; //mid processing } else { tmp += c; state = 2; } break; case 1: if (c == '\\') { state = 3; } else if (c == '\'') { LexObject lex = new LexObject(); lex.isText = true; lex.text = tmp; if (isleft) { if (ismid) { midlex = lex; } else { leftlex.Add(lex); } } else { rightlex.Add(lex); } tmp = ""; state = 0; } else { tmp += c; } break; case 2: if (c == ' ' || c == '\t') { state = 0; if (isleft) { int pt = FindArray(tmp); if (pt < 0) { return("Error No Such Array - " + tmp); } else { if (ismid) { if (midlex == null) { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = -1; if (pt > 98761190) { lex.isText = true; } midlex = lex; } else { return("Error Input Key"); } } else { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; point++; lex.index = point; leftlex.Add(lex); } } } else { if (tmp[tmp.Length - 2] == '@') { string s = tmp.Substring(0, tmp.Length - 2); int pt = FindArray(s); if (pt >= 0) { string ind = tmp[tmp.Length - 1].ToString(); bool found = false; if (ind == "i") { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = -1; lex.text = s; rightlex.Add(lex); tmp = ""; state = 0; } else { for (int i = 0; i < leftlex.Count; i++) { LexObject tmplex = (LexObject)leftlex[i]; if (tmplex.index.ToString() == ind) { if (((TLArray)Arrays[pt]).content.Count == ((TLArray)Arrays[tmplex.pointer]).content.Count) { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = tmplex.index; lex.text = s; rightlex.Add(lex); found = true; tmp = ""; state = 0; } else { return("Error Array Length Mismatch"); } } } if (!found) { return("Error Reference Pointer in Array - " + s); } } } else { return("Error No Such Array - " + s); } } else if (tmp == "null" || tmp == "beep") { LexObject lex = new LexObject(); lex.isText = true; lex.pointer = 98761190; lex.index = (tmp == "null") ? 98761199 : 98761198; lex.text = "_#_" + tmp; rightlex.Add(lex); tmp = ""; state = 0; } else { return("Error no pointer @ in Array - " + tmp); } } tmp = ""; } else { tmp += c; } break; case 3: if (c == '\\' || c == '\'') { tmp += c; } else { return("Error Invalid Escape Character"); } break; case 4: if (c == '+') { state = 5; } else { return("Error Invalid Character"); } break; case 5: if (checkHex(c)) { tmp += c; } else if (c == ' ' || c == '\t') { if (tmp.Length == 4) { int chx = Convert.ToInt32(tmp, 16); LexObject lex = new LexObject(); lex.isText = true; lex.text = ((char)chx).ToString(); if (isleft) { leftlex.Add(lex); } else { rightlex.Add(lex); } state = 0; tmp = ""; } else { return("Error Invalid Unicode Character"); } } else { return("Error Invalid Unicode Character"); } break; } } if (tmp.Length != 0) { if (state == 2) { if (tmp[tmp.Length - 2] == '@') { string s = tmp.Substring(0, tmp.Length - 2); int pt = FindArray(s); if (pt >= 0) { string ind = tmp[tmp.Length - 1].ToString(); bool found = false; if (ind == "i") { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = -1; lex.text = s; rightlex.Add(lex); tmp = ""; state = 0; } else { for (int i = 0; i < leftlex.Count; i++) { LexObject tmplex = (LexObject)leftlex[i]; if (tmplex.index.ToString() == ind) { if (((TLArray)Arrays[pt]).content.Count == ((TLArray)Arrays[tmplex.pointer]).content.Count) { LexObject lex = new LexObject(); lex.isText = false; lex.pointer = pt; lex.index = tmplex.index; lex.text = s; rightlex.Add(lex); found = true; tmp = ""; state = 0; } else { return("Error Array Length Mismatch"); } } } if (!found) { return("Error Reference Pointer in Array - " + s); } } } else { return("Error No Such Array - " + s); } } else if (tmp == "null" || tmp == "beep") { LexObject lex = new LexObject(); lex.isText = true; lex.pointer = 98761190; lex.index = (tmp == "null") ? 98761199 : 98761198; lex.text = "_#_" + tmp; rightlex.Add(lex); tmp = ""; state = 0; } else { return("Error no pointer @ in Array - " + tmp); } } else if (state == 5) { if (tmp.Length == 4) { int chx = Convert.ToInt32(tmp, 16); LexObject lex = new LexObject(); lex.isText = true; lex.text = ((char)chx).ToString(); if (isleft) { leftlex.Add(lex); } else { rightlex.Add(lex); } state = 0; tmp = ""; } else { return("Error Invalid Unicode Character"); } } } ProcessLex(leftlex, midlex, rightlex); return("OK"); }