public List <RowInTable> CreateTable() { int position = 0; int row = 0; foreach (Rule currRule in grammarList) { foreach (string element in currRule.ruleСomposition) { RowInTable newRow = new RowInTable(); AddNameToRow(ref newRow, element); AddIsEndToRow(ref newRow, currRule, element); AddGuideSetToRow(ref newRow, currRule, element); AddErrorTransit(ref newRow, currRule, element, position, row); AddIsShiftToRow(ref newRow, currRule, element); AddIsStackToRow(ref newRow, currRule, element); AddGoToToRow(ref newRow, currRule, element, position); position++; table.Add(newRow); } row++; } return(table); }
private void AddIsEndToRow(ref RowInTable newRow, Rule currRule, string element) { newRow.isEnd = false; bool isEndInMainRule = (element == END) && (currRule.ruleName == "<Start>"); if (isEndInMainRule) { newRow.isEnd = true; } }
private void AddIsShiftToRow(ref RowInTable newRow, Rule currRule, string element) { newRow.isShift = false; string elementType = DefineStringType(element); if (elementType == NOT_TERMINAL) { newRow.isShift = true; } }
private void AddIsStackToRow(ref RowInTable newRow, Rule currRule, string element) { newRow.isStack = false; string elementType = DefineStringType(element); int elementIndex = currRule.ruleСomposition.FindIndex(x => x == element); int elementAmount = currRule.ruleСomposition.Count(); bool isEndInComPosition = (elementIndex == (elementAmount - 1)); if (!isEndInComPosition && (elementType == TERMINAL)) { newRow.isStack = true; } }
private void AddErrorTransit(ref RowInTable newRow, Rule currRule, string element, int position, int row) { int elementIndex = currRule.ruleСomposition.FindIndex(x => x == element); int elementAmount = currRule.ruleСomposition.Count(); bool isFirstElement = (elementIndex == 0); List <int> currList = indexOfTerminalList.Find(x => x.terminal == currRule.ruleName).rowIndex; int indexInTerminalList = currList.FindIndex(x => x == row); bool isLastRuleForTerminate = (indexInTerminalList == currList.Count() - 1); if (isFirstElement && !isLastRuleForTerminate) { newRow.errorTransit = position + elementAmount; } }
private void AddGoToToRow(ref RowInTable newRow, Rule currRule, string element, int position) { string elementType = DefineStringType(element); int elementIndex = currRule.ruleСomposition.FindIndex(x => x == element); int elementAmount = currRule.ruleСomposition.Count(); bool isEndInComPosition = (elementIndex == (elementAmount - 1)); if ((elementType == NOT_TERMINAL) && (!isEndInComPosition)) { newRow.goTo = position + 1; } if (elementType == TERMINAL) { List <int> currList = indexOfTerminalList.Find(x => x.terminal == element).startIndex; newRow.goTo = currList[0]; } }
private void AddGuideSetToRow(ref RowInTable newRow, Rule currRule, string element) { string elementType = DefineStringType(element); switch (elementType) { case TERMINAL: newRow.guideSet = guideSet.Find(x => x.ruleName == element).set; break; case NOT_TERMINAL: newRow.guideSet = new List <string>() { element }; break; case EMPTY: newRow.guideSet = currRule.guideSet; break; } }
public void PrintTable() { Console.WriteLine("-----------------------------------------------------------------------------------------------------------"); for (int i = 0; i < table.Count; i++) { RowInTable row = table[i]; Console.Write(" №:" + i); Console.Write(" Name:" + row.name); Console.Write(" IsEnd:" + row.isEnd); Console.Write(" GuideSet:"); foreach (string el in row.guideSet) { Console.Write(el + ", "); } Console.Write(" ErrorTransit:" + row.errorTransit); Console.Write(" IsShift:" + row.isShift); Console.Write(" IsStack:" + row.isStack); Console.WriteLine(" GoTo:" + row.goTo); } Console.WriteLine("-----------------------------------------------------------------------------------------------------------"); }
private void AddNameToRow(ref RowInTable newRow, string element) { newRow.name = element; }
private void AnalyzeEmptyString(ref List <RowInTable> table) { RowInTable currRow = table[0]; isOk = currRow.guideSet.Contains("[end]"); }