Example #1
0
        /// <summary>
        /// Searches for every symbol from terminal in classes.
        /// Modifies existing classes and adds new ones if needed.
        /// </summary>
        /// <param name="terminal">Terminal to be processed.</param>
        /// <returns>SymbolClasses of terminal.</returns>
        private List <string> GetClassesOfTerminalSymbols(string terminal)
        {
            // Dictionary of created or used classes.
            List <string> terminalClasses = new List <string>();


            // Check each character.
            foreach (char ch in terminal)
            {
                // Get info about symbol.
                var symbolInfo = ClassTable.GetSymbolInfo(ch);

                // String representation of character.
                string stringChar = ch.ToString();

                // If symbol is classified then there is a class for it created.
                if (symbolInfo.category == SymbolCategory.Classified)
                {
                    // Get symbol class characters.
                    var classCharacters = ClassTable.SymbolClasses[symbolInfo.@class];

                    // If there are more then 1 character in the class
                    // then remove the character from the class and create a new one.
                    if (classCharacters.Count() > 1)
                    {
                        // Find position of the symbol in the class.
                        int pos = classCharacters.IndexOf(ch);

                        // Remove the symbol from the class.
                        ClassTable.SymbolClasses[symbolInfo.@class] = classCharacters.Remove(pos, 1);

                        // Add symbol as separate terminal to unclassified terminals.
                        UnclassifiedTerminals = UnclassifiedTerminals.Append(stringChar);

                        // Create dedicated class.
                        ClassTable.SymbolClasses[stringChar] = stringChar;


                        // If classesWithRemovedSymbols does not contain class name then
                        // must create one.
                        if (!classesWithRemovedSymbols.ContainsKey(symbolInfo.@class))
                        {
                            classesWithRemovedSymbols[symbolInfo.@class] = new List <char>();
                        }

                        // Add symbol to list fo removed symbols.
                        classesWithRemovedSymbols[symbolInfo.@class].Add(ch);

                        terminalClasses.Add(stringChar);
                    }
                    else if (classCharacters.Count() == 1)
                    {
                        terminalClasses.Add(symbolInfo.@class);
                    }
                }
                else if (symbolInfo.category == SymbolCategory.Undefined)
                {
                    ClassTable.SymbolClasses[stringChar] = stringChar;

                    terminalClasses.Add(stringChar);
                }
            }


            return(terminalClasses);
        }