本文整理汇总了C#中Grammar.Follow方法的典型用法代码示例。如果您正苦于以下问题:C# Grammar.Follow方法的具体用法?C# Grammar.Follow怎么用?C# Grammar.Follow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grammar
的用法示例。
在下文中一共展示了Grammar.Follow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Extract
public override void Extract(Grammar grammar)
{
_Grammar = grammar;
EntityCol = grammar.Entities;
TerminalCol = grammar.Terminals;
NonTerminalCol = grammar.NonTerminals;
// removing augmented entity
var augment = EntityCol[0];
_EntityColO = EntityCol - augment;
NonTerminalCol.Remove((NonTerminal) augment);
//Cloure_GoToTable
_Production = new CLRProduction(grammar[0].Producer, grammar[0].Product,
new EntityCollection<Terminal>(new[] { (Terminal) "$" }));
_GotoCount = 0;
_DotCount = 0;
_ClosureCol =
new ClosureCollection(new Closure[] { new CLRClosure(GotoTitle(), grammar, new SLRProduction[] { _Production }) });
++_GotoCount;
_GotoEntries = new GotoEntry[0];
for (var c = 0; c < _ClosureCol.Count; ++c)
{
var closure = (SLRClosure) _ClosureCol[c];
var tmp = _EntityColO - (Terminal) "$";
for (var e = 0; e < tmp.Count; ++e) //foreach (var entity in _entityColO - (Terminal) "$")
{
var entity = tmp[e];
var gotoClosure = closure.GoToEntity(entity);
if (!gotoClosure.IsEmpty)
{
var index =
//_closureCol.List.FindIndex((Closure clr) => (clr == gotoClosure));
_ClosureCol.Closures.IndexOf(gotoClosure);
if (-1 == index)
{
// add new Goto State
gotoClosure.Title = GotoTitle();
_ClosureCol += gotoClosure;
++_GotoCount;
}
else
{
// error here
//CLRClosure closureC = gotoClosure as CLRClosure;
//closureC.AddLookAhead(_ClosureCol[ index ].SLRProductions.ToArray());
//gotoClosure = closureC;
var closureC = gotoClosure as CLRClosure;
if (default(Closure) != closureC) closureC.AddLookAhead(_ClosureCol[index].SLRProductions.ToArray());
gotoClosure.Title = _ClosureCol[index].Title;
}
var length = _GotoEntries.Length;
var newGotoEntries = new GotoEntry[length + 1];
Array.Copy(_GotoEntries, newGotoEntries, length);
newGotoEntries[length] = new GotoEntry(closure, entity, gotoClosure);
_GotoEntries = newGotoEntries;
}
++_DotCount;
}
}
// LR Table
_GoTotable = new String[EntityCol.Count, _ClosureCol.Count];
for (var c = 0; c < _ClosureCol.Count; ++c)
{
var terminalLength = TerminalCol.Count;
//Shift
for (var t = 0; t < terminalLength; ++t)
foreach (var gotoEntity in _GotoEntries)
{
if (gotoEntity.X != TerminalCol[t] || gotoEntity.I != _ClosureCol[c]) continue;
_GoTotable[t, c] = "s" + gotoEntity.Goto.Title.Split('[', ']')[1];
break;
}
//Reduce
for (var p = 0; p < _ClosureCol[c].Count; ++p)
{
var production = _ClosureCol[c][p];
if (production.DotPosition == (production.Count - 1)
&& production == _ClosureCol[1][0] // S' --> S .$
) // Accepted
_GoTotable[TerminalCol & (Terminal) "$", 1] = "!!";
if (production.DotPosition != production.Count) continue;
var followCol = grammar.Follow(production.Producer);
if (default(EntityCollection<Terminal>) == followCol) continue;
//followCol.Remove( (Terminal)"$" );
foreach (var follow in followCol) _GoTotable[TerminalCol & follow, c] = "r" + (grammar & production);
}
//.........这里部分代码省略.........