本文整理汇总了C#中Rule.GetFirstTerminals方法的典型用法代码示例。如果您正苦于以下问题:C# Rule.GetFirstTerminals方法的具体用法?C# Rule.GetFirstTerminals怎么用?C# Rule.GetFirstTerminals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rule
的用法示例。
在下文中一共展示了Rule.GetFirstTerminals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateProductionRuleCode
// generates the rule logic inside the method body
private string GenerateProductionRuleCode(Rule r, int indent)
{
int i = 0;
Symbols firsts = null;
StringBuilder sb = new StringBuilder();
string Indent = IndentTabs(indent);
switch (r.Type)
{
case RuleType.Terminal:
// expecting terminal, so scan it.
sb.AppendLine(Indent + "tok = m_scanner.Scan(TokenType." + r.Symbol.Name + ")" + Helper.AddComment("'", "Terminal Rule: " + r.Symbol.Name));
sb.AppendLine(Indent + "n = node.CreateNode(tok, tok.ToString() )");
sb.AppendLine(Indent + "node.Token.UpdateRange(tok)");
sb.AppendLine(Indent + "node.Nodes.Add(n)");
sb.AppendLine(Indent + "If tok.Type <> TokenType." + r.Symbol.Name + " Then");
sb.AppendLine(Indent + " m_tree.Errors.Add(New ParseError(\"Unexpected token '\" + tok.Text.Replace(\"\\n\", \"\") + \"' found. Expected \" + TokenType." + r.Symbol.Name + ".ToString(), &H1001, tok))");
sb.AppendLine(Indent + " Return\r\n");
sb.AppendLine(Indent + "End If\r\n");
break;
case RuleType.NonTerminal:
sb.AppendLine(Indent + "Parse" + r.Symbol.Name + "(node)" + Helper.AddComment("'", "NonTerminal Rule: " + r.Symbol.Name));
break;
case RuleType.Concat:
foreach (Rule rule in r.Rules)
{
sb.AppendLine();
sb.AppendLine(Indent + Helper.AddComment("'", "Concat Rule"));
sb.Append(GenerateProductionRuleCode(rule, indent));
}
break;
case RuleType.ZeroOrMore:
firsts = r.GetFirstTerminals();
i = 0;
sb.Append(Indent + "tok = m_scanner.LookAhead(");
foreach (TerminalSymbol s in firsts)
{
if (i == 0)
sb.Append("TokenType." + s.Name);
else
sb.Append(", TokenType." + s.Name);
i++;
}
sb.AppendLine(")" + Helper.AddComment("'", "ZeroOrMore Rule"));
i = 0;
foreach (TerminalSymbol s in firsts)
{
if (i == 0)
sb.Append(Indent + "While tok.Type = TokenType." + s.Name);
else
sb.Append(" Or tok.Type = TokenType." + s.Name);
i++;
}
sb.AppendLine("");
foreach (Rule rule in r.Rules)
{
sb.Append(GenerateProductionRuleCode(rule, indent + 1));
}
i = 0;
sb.Append(Indent + "tok = m_scanner.LookAhead(");
foreach (TerminalSymbol s in firsts)
{
if (i == 0)
sb.Append("TokenType." + s.Name);
else
sb.Append(", TokenType." + s.Name);
i++;
}
sb.AppendLine(")" + Helper.AddComment("'", "ZeroOrMore Rule"));
sb.AppendLine(Indent + "End While");
break;
case RuleType.OneOrMore:
sb.AppendLine(Indent + "Do" + Helper.AddComment("'", "OneOrMore Rule"));
foreach (Rule rule in r.Rules)
{
sb.Append(GenerateProductionRuleCode(rule, indent + 1));
}
i = 0;
firsts = r.GetFirstTerminals();
sb.Append(Indent + " tok = m_scanner.LookAhead(");
foreach (TerminalSymbol s in firsts)
{
if (i == 0)
sb.Append("TokenType." + s.Name);
else
sb.Append(", TokenType." + s.Name);
i++;
}
sb.AppendLine(")" + Helper.AddComment("'", "OneOrMore Rule"));
i = 0;
foreach (TerminalSymbol s in r.GetFirstTerminals())
{
if (i == 0)
//.........这里部分代码省略.........