本文整理汇总了C#中Rule.AddAlternative方法的典型用法代码示例。如果您正苦于以下问题:C# Rule.AddAlternative方法的具体用法?C# Rule.AddAlternative怎么用?C# Rule.AddAlternative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rule
的用法示例。
在下文中一共展示了Rule.AddAlternative方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NT_Alternative
private static void NT_Alternative(ref Rule rule)
{
String nonterminal = "";
String terminal = "";
Alternative alternative = new Alternative();
Rule groupRule = null;
Rule optionalRule = null;
Rule repetitionRule = null;
for (;;) {
switch (Syn.Interpret()) {
case 0:
return;
case 1: // SEM
rule.AddAlternative(alternative);
break;
case 2:
Lex.GETnonterminalAttr(out nonterminal);
break;
case 3: // SEM
alternative.AddSymbol(new Symbol(nonterminal, Symbol.Kind.NONTERMINAL));
break;
case 4:
Lex.GETterminalAttr(out terminal);
break;
case 5: // SEM
alternative.AddSymbol(new Symbol(terminal, Symbol.Kind.TERMINAL));
break;
case 6: // SEM
groupRule = new Rule();
groupRule.NonTerminal = symbolNameGenerator.Generate();
rules.Add(groupRule);
alternative.AddSymbol(new Symbol(groupRule.NonTerminal, Symbol.Kind.NONTERMINAL));
break;
case 7:
NT_Grouping(ref groupRule);
break;
case 8: // SEM
optionalRule = new Rule();
optionalRule.NonTerminal = symbolNameGenerator.Generate();
// add empty alternative
optionalRule.AddAlternative(new Alternative());
rules.Add(optionalRule);
alternative.AddSymbol(new Symbol(optionalRule.NonTerminal, Symbol.Kind.NONTERMINAL));
break;
case 9:
NT_Optional(ref optionalRule);
break;
case 10: // SEM
repetitionRule = new Rule();
repetitionRule.NonTerminal = symbolNameGenerator.Generate();
rules.Add(repetitionRule);
alternative.AddSymbol(new Symbol(repetitionRule.NonTerminal, Symbol.Kind.NONTERMINAL));
break;
case 11:
NT_Repetition(ref repetitionRule);
break;
case 12: // SEM
// add recursion to every alternative
foreach (Alternative a in repetitionRule.GetAlternatives()) {
a.AddSymbol(new Symbol(repetitionRule.NonTerminal, Symbol.Kind.NONTERMINAL));
}
// add empty alternative
repetitionRule.AddAlternative(new Alternative());
break;
} // switch
} // for
}