コード例 #1
0
        protected static void AddTerminalTo(ref Grammar.Grammar grammar, string line)
        {
            string _line = line;
            LiteralGrammarElement addKeyword = new LiteralGrammarElement("Add");

            if (addKeyword.Validate(ref _line, true).Result)
            {
                if (_line.IndexOf(" To ") != -1)
                {
                    string to = _line.Substring(_line.IndexOf("To") + 2).Trim();
                    if (!grammar.Terminals.ContainsKey(to))
                    {
                        throw new InfinityGrammarScriptParseError("Terminal not found to perform addition of terminals - " + to, _line);
                    }
                    _line = _line.Substring(0, _line.IndexOf("To")).Trim();
                    string[] _terminals = _line.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string _terminal in _terminals)
                    {
                        if (grammar.Terminals.ContainsKey(_terminal))
                        {
                            grammar.AddTerminalTo(_terminal, to);
                        }
                        else
                        {
                            throw new InfinityGrammarScriptParseError("No such terminal to add to - " + to + " : " + _terminal, _line);
                        }
                    }
                }
                else
                {
                    throw new InfinityGrammarScriptParseError("Add statement improperly formed. Missing 'To' keyword.", _line);
                }
            }
            else
            {
                throw new InfinityGrammarScriptParseError("Please check whether you have typed the correct syntax.", _line);
            }
        }