private void DoCommand(int key1, ref Rules r, ref ruleParameter rp) { if (getRule(key1, ref r) && position > -1 && position < line.Length) { if (r.get(line[position], ref rp)) { string tmp = new string(line); Console.Write(tmp + " " + line[position] + " " + rp.change + " " + rp.next + " " + c + '\n'); if (rp.change != '*') { line[position] = rp.change; } if (rp.step == 'R') { position++; } else { position--; } c++; } else { isRunning = false; Console.WriteLine("No symbol for the rule"); } } else { isRunning = false; Console.WriteLine("No symbol for the rule"); } }
public void add(char key, ruleParameter para) { if (r.ContainsKey(key)) { return; } r.Add(key, para); }
public bool get(char key, ref ruleParameter para) { if (!r.ContainsKey(key)) { if (r.ContainsKey('*')) { key = '*'; } else { return(false); } } para = r[key]; return(true); }
public bool ReadFromFile(string filename) { if (!File.Exists(filename)) { Console.WriteLine("Tokio failo nera"); return(false); } using (StreamReader sr = new StreamReader(filename)) { position = Int32.Parse(sr.ReadLine()); string temp = sr.ReadLine(); line = temp.ToCharArray(); int c = 0; string buffer; while (sr.Peek() > -1) { buffer = sr.ReadLine(); if (buffer.Length == 0) { continue; } ruleParameter rp = new ruleParameter(); int num = 999; int x = 0; string tmp = ""; while (buffer[x] != ' ') { tmp += buffer[x++]; } x -= 1; if (!Int32.TryParse(tmp, out num)) { continue; } int id = num; char current = buffer[2 + x]; rp.change = buffer[4 + x]; rp.step = buffer[6 + x]; int r = 8 + x; tmp = ""; while (buffer.Length > r) { tmp += buffer[r++]; } if (!Int32.TryParse(tmp, out num)) { continue; } rp.next = num; if (c == 0) { first = rp; } if (!rules.ContainsKey(id)) { rules.Add(id, new Rules()); } rules[id].add(current, rp); } } return(true); }