public void doActions(CSemiExp semi) { foreach (IAction action in actions) { action.doAction(semi); } }
//----< collect semiExpression from filtered token stream >---------- public bool getSemi() { semiExp.RemoveRange(0, semiExp.Count); // empty container do { get(); if (currTok == "") { return(false); // end of file } if (returnNewLines || currTok != "\n") { semiExp.Add(currTok); } } while (!isTerminator(currTok) || count == 0); // if for then append next two semiExps, e.g., for(int i=0; i<se.count; ++i) { if (semiExp.Contains("for")) { CSemiExp se = clone(); getSemi(); se.Add(semiExp.ToArray()); getSemi(); se.Add(semiExp.ToArray()); semiExp.Clear(); for (int i = 0; i < se.count; ++i) { semiExp.Add(se[i]); } } return(semiExp.Count > 0); }
public virtual void display(CSemiExp semi) { if (displaySemi) { for (int i = 0; i < semi.count; ++i) { Console.Write("{0} ", semi[i]); } } }
// //----< make a copy of semiEpression >------------------------------- public CSemiExp clone() { CSemiExp copy = new CSemiExp(); for (int i = 0; i < count; ++i) { copy.Add(this[i]); } return(copy); }
public void parse(CSemiExp semi) { // Note: rule returns true to tell parser to stop // processing the current semiExp Display.Display.displaySemiString(semi.displayStr()); foreach (IRule rule in Rules) { if (rule.test(semi)) { break; } } }
public int indexOfType(CSemiExp semi) { int indexCL = semi.Contains("class"); int indexIF = semi.Contains("interface"); int indexST = semi.Contains("struct"); int indexEN = semi.Contains("enum"); int indexDE = semi.Contains("delegate"); int index = Math.Max(indexCL, indexIF); index = Math.Max(index, indexST); index = Math.Max(index, indexEN); index = Math.Max(index, indexDE); return(index); }
//----< test for equality >------------------------------------------ override public bool Equals(Object semi) { CSemiExp temp = (CSemiExp)semi; if (temp.count != count) { return(false); } for (int i = 0; i < temp.count && i < count; ++i) { if (this[i] != temp[i]) { return(false); } } return(true); }
public abstract void doAction(CSemiExp semi);
abstract public bool test(CSemiExp semi);
static void Main(string[] args) { Console.Write("\n Testing semiExp Operations"); Console.Write("\n ============================\n"); CSemiExp test = new CSemiExp(); test.returnNewLines = true; test.displayNewLines = true; string testFile = "../../testSemi.txt"; if (!test.open(testFile)) { Console.Write("\n Can't open file {0}", testFile); } while (test.getSemi()) { test.display(); } test.initialize(); test.insert(0, "this"); test.insert(1, "is"); test.insert(2, "a"); test.insert(3, "test"); test.display(); Console.Write("\n 2nd token = \"{0}\"\n", test[1]); Console.Write("\n removing first token:"); test.remove(0); test.display(); Console.Write("\n"); Console.Write("\n removing token \"test\":"); test.remove("test"); test.display(); Console.Write("\n"); Console.Write("\n making copy of semiExpression:"); CSemiExp copy = test.clone(); copy.display(); Console.Write("\n"); if (args.Length == 0) { Console.Write("\n Please enter name of file to analyze\n\n"); return; } CSemiExp semi = new CSemiExp(); semi.returnNewLines = true; if (!semi.open(args[0])) { Console.Write("\n can't open file {0}\n\n", args[0]); return; } Console.Write("\n Analyzing file {0}", args[0]); Console.Write("\n ----------------------------------\n"); while (semi.getSemi()) { semi.display(); } semi.close(); }