public void updateSet() { SetC set = Sets.Last(); List <Token> symbols = new List <Token>(); for (int i = 0; i < set.Value.Count(); i++) { if (set.Value[i].TypeToken == Token.Type.SET_SIGN) { for (int j = (int)set.Value[i - 1].Value[0]; j <= (int)set.Value[i + 1].Value[0]; j++) { symbols.Add(new Token(0, 0, 0, Token.Type.SYMBOL, Convert.ToChar(j).ToString())); } set.Value.RemoveRange(i - 1, i + 2); } else if (set.Value[i].TypeToken == Token.Type.SYMBOL_COMMA) { set.Value.RemoveAt(i); } else if (set.Value[i].TypeToken == Token.Type.CHARACTER_SET) { string str = set.Value[i].Value.Replace("[:", "").Replace(":]", ""); for (int j = 0; j < str.Length; j++) { symbols.Add(new Token(0, 0, 0, Token.Type.SYMBOL, str[j].ToString())); } set.Value.RemoveAt(i); } } set.Value.AddRange(symbols); }
private State Evaluation(State state) { if (state != null && indexChar < charsList.Count()) { List <Transition> statetransitions = transitions.FindAll(s => s.From.StateName == state.StateName); char character = charsList[indexChar]; State toState = null; /*if (char.IsWhiteSpace(character)) * { * if (character.CompareTo('\n') != 0 && character.CompareTo('\t') != 0) * { * indexChar++; * character = charsList[indexChar]; * } * }*/ foreach (Transition transition in statetransitions) { bool exitLoop = false; string tokenValue = transition.Token.Value; StringBuilder entry = new StringBuilder(); switch (transition.Token.TypeToken) { case Token.Type.LINE_BREAK: if (character.CompareTo('\n') == 0) { toState = transition.To; exitLoop = true; break; } break; case Token.Type.SINGLE_QUOTE: if (character.CompareTo('\'') == 0) { toState = transition.To; exitLoop = true; break; } break; case Token.Type.DOUBLE_QUOTE: if (character.CompareTo('\"') == 0) { toState = transition.To; exitLoop = true; break; } break; case Token.Type.TABULATION: if (character.CompareTo('\t') == 0) { toState = transition.To; exitLoop = true; break; } break; case Token.Type.ID: SetC set = sets.Find(x => x.Name == tokenValue); if (set != null) { if (set.Value.Find(x => x.Value.Equals(character.ToString())) != null) { toState = transition.To; exitLoop = true; break; } } break; case Token.Type.NUMBER: if (char.IsDigit(character)) { toState = transition.To; exitLoop = true; break; } break; case Token.Type.STR: string str = tokenValue.Substring(1, tokenValue.Length - 2); for (int i = 0; i < str.Length; i++) { entry.Append(charsList[indexChar + i]); } if (str.Equals(entry.ToString())) { indexChar += str.Length - 1; toState = transition.To; exitLoop = true; break; } break; case Token.Type.SYMBOL: if (tokenValue.Equals(character)) { toState = transition.To; exitLoop = true; break; } break; } if (exitLoop == true) { break; } } if (toState != null) { indexChar++; toState = Evaluation(toState); } return(toState); } return(state); }