Exemple #1
0
 public IRuleBuilder Rule(params object[] symbols)
 {
     var symbolList = new List<ISymbol>();
     if (symbols != null)
     {
         foreach (var symbol in symbols)
         {
             if (symbol is char)
             {
                 var terminal = new Terminal((char)symbol);
                 var lexerRule = new TerminalLexerRule(
                     terminal,
                     new TokenType(terminal.ToString()));
                 symbolList.Add(lexerRule);
             }
             else if (symbol is ITerminal)
             {
                 var terminal = symbol as ITerminal;
                 var lexerRule = new TerminalLexerRule(
                     terminal,
                     new TokenType(terminal.ToString()));
                 symbolList.Add(lexerRule);
             }
             else if (symbol is ILexerRule)
             {
                 symbolList.Add(symbol as ILexerRule);
             }
             else if (symbol is string)
             {
                 var nonTerminal = new NonTerminal(symbol as string);
                 symbolList.Add(nonTerminal);
             }
             else if (symbol == null)
             { }
             else { throw new ArgumentException("unrecognized terminal or nonterminal"); }
         }
     }
     _rules.Add(symbolList);
     return this;
 }