本文整理汇总了C#中BnfTerm类的典型用法代码示例。如果您正苦于以下问题:C# BnfTerm类的具体用法?C# BnfTerm怎么用?C# BnfTerm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BnfTerm类属于命名空间,在下文中一共展示了BnfTerm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CollectTermsRecursive
private void CollectTermsRecursive(BnfTerm term) {
if (_grammarData.AllTerms.Contains(term)) return;
_grammarData.AllTerms.Add(term);
NonTerminal nt = term as NonTerminal;
if (nt == null) return;
if (string.IsNullOrEmpty(nt.Name)) {
if (nt.Rule != null && !string.IsNullOrEmpty(nt.Rule.Name))
nt.Name = nt.Rule.Name;
else
nt.Name = "Unnamed" + (_unnamedCount++);
}
if (nt.Rule == null)
_language.Errors.AddAndThrow(GrammarErrorLevel.Error, null, Resources.ErrNtRuleIsNull, nt.Name);
//check all child elements
foreach (BnfTermList elemList in nt.Rule.Data)
for (int i = 0; i < elemList.Count; i++) {
BnfTerm child = elemList[i];
if (child == null) {
_language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrRuleContainsNull, nt.Name, i);
continue; //for i loop
}
//Check for nested expression - convert to non-terminal
BnfExpression expr = child as BnfExpression;
if (expr != null) {
child = new NonTerminal(null, expr);
elemList[i] = child;
}
CollectTermsRecursive(child);
}//for i
}//method
示例2: ShiftParserAction
public ShiftParserAction(BnfTerm term, ParserState newState) {
if (newState == null)
throw new Exception("ParserShiftAction: newState may not be null. term: " + term.ToString());
Term = term;
NewState = newState;
}
示例3: PrecedenceBasedParserAction
public PrecedenceBasedParserAction(BnfTerm shiftTerm, ParserState newShiftState, Production reduceProduction)
{
_reduceAction = new ReduceParserAction(reduceProduction);
var reduceEntry = new ConditionalEntry(CheckMustReduce, _reduceAction, "(Precedence comparison)");
ConditionalEntries.Add(reduceEntry);
DefaultAction = _shiftAction = new ShiftParserAction(shiftTerm, newShiftState);
}
示例4: AstNodeArgs
public AstNodeArgs(BnfTerm term, CompilerContext context, SourceSpan span, AstNodeList childNodes)
{
Context = context;
Term = term;
Span = span;
ChildNodes = childNodes;
}
示例5: GetDefaultNodeType
protected virtual Type GetDefaultNodeType(BnfTerm term)
{
if (term is NumberLiteral || term is StringLiteral)
return Context.DefaultLiteralNodeType;
if (term is IdentifierTerminal)
return Context.DefaultIdentifierNodeType;
return Context.DefaultNodeType;
}
示例6: UnparsableAst
public UnparsableAst(BnfTerm bnfTerm, object astValue, Member astParentMember = null)
{
this.BnfTerm = bnfTerm;
this.AstValue = astValue;
this.AstParentMember = astParentMember;
this.IsLeftSiblingNeededForDeferredCalculation = false;
}
示例7: VerifyTerm
static void VerifyTerm(ParseTreeNode parseTreeNode, BnfTerm expectedTerm, params BnfTerm[] moreExpectedTerms)
{
var allExpected = new[] { expectedTerm }.Concat(moreExpectedTerms);
if (!allExpected.Where(node => parseTreeNode.Term == node).Any())
{
throw new InvalidOperationException("expected '{0}' to be a '{1}'".FormatString(parseTreeNode, allExpected.JoinString(", ")));
}
}
示例8: DebugWriteLineBnfTermKind
internal static ExpressionUnparser.BnfTermKind DebugWriteLineBnfTermKind(this ExpressionUnparser.BnfTermKind bnfTermKind, TraceSource ts, BnfTerm bnfTerm, string extraMessage = null)
{
ts.Debug(
"{0}, kind: {1}{2}",
bnfTerm,
bnfTermKind,
extraMessage != null ? extraMessage : string.Empty
);
return bnfTermKind;
}
示例9: Process
private void Process(BnfTerm term, ParseTreeNode node)
{
if (node.Term == term)
{
Visit(node);
return;
}
foreach (var childNode in node.ChildNodes)
{
Process(term, childNode);
}
}
示例10: ProcessParseTreeNode
static void ProcessParseTreeNode(BnfTerm node)
{
var nt = node as NonTerminal;
if (nt == null)
return;
if (node_names.ContainsKey (nt))
return;
string name = "AS" + ToPascalCase (nt.Name) + "AstNode";
node_names.Add (nt, name);
// process descendants
foreach (var p in nt.Productions)
foreach (var c in p.RValues)
ProcessParseTreeNode (c);
foreach (var p in nt.Productions)
Console.WriteLine ("\t// {0}", p.GetType ());
Console.WriteLine ("\tpublic partial class {0} : ActionScriptAstNode", name);
Console.WriteLine ("\t{");
Console.Write ("\t\t// {0} productions: ", nt.Productions.Count);
foreach (var p in nt.Productions)
foreach (var c in p.RValues) {
Console.Write (ToPascalCase (c.Name));
Console.Write (' ');
}
Console.WriteLine ();
if ((nt.Flags & TermFlags.IsList) != 0 && nt.Productions.Count > 0 && nt.Productions [0].RValues [0] == nt) {
var cnt = nt.Productions [0].RValues.Last () as NonTerminal;
if (cnt != null)
Console.WriteLine ("\t\tpublic {0} {1} {{ get; set; }}", node_names [cnt], ToPascalCase (cnt.Name));
} else {
foreach (var p in nt.Productions)
foreach (var c in p.RValues) {
var cnt = c as NonTerminal;
if (cnt == null)
continue;
Console.WriteLine ("\t\tpublic {0} {1} {{ get; set; }}", node_names [cnt], ToPascalCase (cnt.Name));
}
}
Console.WriteLine ("\t}");
}
示例11: CollectTermsRecursive
private void CollectTermsRecursive(BnfTerm term) {
// Do not add pseudo terminals defined as static singletons in Grammar class (Empty, Eof, etc)
// We will never see these terminals in the input stream.
// Filter them by type - their type is exactly "Terminal", not derived class.
if (term.GetType() == typeof(Terminal)) return;
if (_grammarData.AllTerms.Contains(term)) return;
_grammarData.AllTerms.Add(term);
NonTerminal nt = term as NonTerminal;
if (nt == null) return;
if (nt.Name == null) {
if (nt.Rule != null && !string.IsNullOrEmpty(nt.Rule.Name))
nt.Name = nt.Rule.Name;
else
nt.Name = "NT" + (_unnamedCount++);
}
if (nt.Rule == null) {
_language.Errors.Add("Non-terminal " + nt.Name + " has uninitialized Rule property.");
return;
}
//check all child elements
foreach (BnfTermList elemList in nt.Rule.Data)
for (int i = 0; i < elemList.Count; i++) {
BnfTerm child = elemList[i];
if (child == null) {
_language.Errors.Add("Rule for NonTerminal " + nt.Name + " contains null as an operand in position " + i.ToString() + " in one of productions.");
continue; //for i loop
}
//Check for nested expression - convert to non-terminal
BnfExpression expr = child as BnfExpression;
if (expr != null) {
child = new NonTerminal(null, expr);
elemList[i] = child;
}
CollectTermsRecursive(child);
}//for i
}//method
示例12: uniOpCreate
private ValueReader uniOpCreate(BnfTerm op, ValueReader value)
{
if (grammar.Not == op) return new NotOpReader(value);
if (grammar.Minus == op) return new NegOpReader(value);
Game.CurrentGame.Die("Error with implementation of operator " + op.Name);
return null;
}
示例13: MakeStarRule
public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember, TermListOptions options) {
bool allowTrailingDelimiter = (options & TermListOptions.AllowTrailingDelimiter) != 0;
if (delimiter == null) {
//it is much simpler case
listNonTerminal.SetFlag(TermFlags.IsList);
listNonTerminal.Rule = _currentGrammar.Empty | listNonTerminal + listMember;
return listNonTerminal.Rule;
}
//Note that deceptively simple version of the star-rule
// Elem* -> Empty | Elem | Elem* + delim + Elem
// does not work when you have delimiters. This simple version allows lists starting with delimiters -
// which is wrong. The correct formula is to first define "Elem+"-list, and then define "Elem*" list
// as "Elem* -> Empty|Elem+"
NonTerminal plusList = new NonTerminal(listMember.Name + "+");
plusList.Rule = MakePlusRule(plusList, delimiter, listMember);
plusList.SetFlag(TermFlags.NoAstNode); //to allow it to have AstNodeType not assigned
if (allowTrailingDelimiter)
listNonTerminal.Rule = _currentGrammar.Empty | plusList | plusList + delimiter;
else
listNonTerminal.Rule = _currentGrammar.Empty | plusList;
listNonTerminal.SetFlag(TermFlags.IsListContainer);
return listNonTerminal.Rule;
}
示例14: ResolveConflictByPrecedence
private bool ResolveConflictByPrecedence(ParserState state, BnfTerm conflict)
{
var stateData = state.BuilderData;
if (!conflict.IsSet(TermOptions.UsePrecedence)) return false;
if (!stateData.ShiftTerms.Contains(conflict)) return false; //it is not shift-reduce
//first find reduce items
var reduceItems = stateData.ReduceItems.SelectByLookahead(conflict);
if (reduceItems.Count > 1) return false; // if it is reduce-reduce conflict, we cannot fix it by precedence
var reduceItem = reduceItems.First();
//remove shift action and replace it with operator action
var oldAction = state.Actions[conflict];
var action = ParserAction.CreateOperator(oldAction.NewState, reduceItem.Core.Production);
state.Actions[conflict] = action;
stateData.ResolvedConflicts.Add(conflict);
return true;
}
示例15: Op_Plus
internal static BnfExpression Op_Plus(BnfTerm term1, BnfTerm term2)
{
return term1 + term2;
}