private void AddTerminalToLookupByFirstChar(TerminalLookupTable _lookup, Terminal term, char firstChar) { TerminalList currentList; if (!_lookup.TryGetValue(firstChar, out currentList)) { //if list does not exist yet, create it currentList = new TerminalList(); _lookup[firstChar] = currentList; } //add terminal to the list if (!currentList.Contains(term)) currentList.Add(term); }
private void AddTerminalToLookupByFirstChar(TerminalLookupTable lookup, Terminal term, char firstChar) { if (!lookup.TryGetValue(firstChar, out TerminalList currentList)) { //if list does not exist yet, create it currentList = new TerminalList(); lookup[firstChar] = currentList; } //add terminal to the list if (!currentList.Contains(term)) { currentList.Add(term); } }
private void AddTerminalToLookup(TerminalLookupTable _lookup, Terminal term, IList<string> firsts) { foreach (string prefix in firsts) { if(string.IsNullOrEmpty(prefix)) { _language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrTerminalHasEmptyPrefix, term.Name); continue; } //Calculate hash key for the prefix char firstChar = prefix[0]; if(_grammar.CaseSensitive) AddTerminalToLookupByFirstChar(_lookup, term, firstChar); else { AddTerminalToLookupByFirstChar(_lookup, term, char.ToLower(firstChar)); AddTerminalToLookupByFirstChar(_lookup, term, char.ToUpper(firstChar)); }//if }//foreach prefix }
} //method private void AddTerminalToLookup(TerminalLookupTable _lookup, Terminal term, IList <string> firsts) { foreach (string prefix in firsts) { if (string.IsNullOrEmpty(prefix)) { _language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrTerminalHasEmptyPrefix, term.Name); continue; } //Calculate hash key for the prefix char firstChar = prefix[0]; if (_grammar.CaseSensitive) { AddTerminalToLookupByFirstChar(_lookup, term, firstChar); } else { AddTerminalToLookupByFirstChar(_lookup, term, char.ToLower(firstChar)); AddTerminalToLookupByFirstChar(_lookup, term, char.ToUpper(firstChar)); } //if } //foreach prefix }