本文整理汇总了C#中BnfTerm类的典型用法代码示例。如果您正苦于以下问题:C# BnfTerm类的具体用法?C# BnfTerm怎么用?C# BnfTerm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BnfTerm类属于命名空间,在下文中一共展示了BnfTerm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:anukat2015,项目名称:sones,代码行数:31,代码来源:GrammarDataBuilder.cs
示例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;
}
开发者ID:androdev4u,项目名称:XLParser,代码行数:7,代码来源:ShiftParserAction.cs
示例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);
}
开发者ID:HyperSharp,项目名称:Hyperspace.DotLua,代码行数:7,代码来源:PrecedenceBasedParserAction.cs
示例4: AstNodeArgs
public AstNodeArgs(BnfTerm term, CompilerContext context, SourceSpan span, AstNodeList childNodes)
{
Context = context;
Term = term;
Span = span;
ChildNodes = childNodes;
}
开发者ID:Temperament,项目名称:FiestaShark,代码行数:7,代码来源:AstNodeArgs.cs
示例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;
}
开发者ID:HyperSharp,项目名称:Hyperspace.DotLua,代码行数:8,代码来源:AstBuilder.cs
示例6: UnparsableAst
public UnparsableAst(BnfTerm bnfTerm, object astValue, Member astParentMember = null)
{
this.BnfTerm = bnfTerm;
this.AstValue = astValue;
this.AstParentMember = astParentMember;
this.IsLeftSiblingNeededForDeferredCalculation = false;
}
开发者ID:davidnemeti,项目名称:Sarcasm,代码行数:8,代码来源:UnparsableAst.cs
示例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(", ")));
}
}
开发者ID:Ventero,项目名称:Pash,代码行数:9,代码来源:AstBuilder.cs
示例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;
}
开发者ID:davidnemeti,项目名称:Sarcasm,代码行数:11,代码来源:Misc.cs
示例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);
}
}
开发者ID:henritersteeg,项目名称:cuke4vs,代码行数:12,代码来源:ParseTreeVisitor.cs
示例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}");
}
开发者ID:atsushieno,项目名称:asparser,代码行数:41,代码来源:Driver.cs
示例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
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:37,代码来源:GrammarDataBuilder.cs
示例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;
}
开发者ID:kinectitude,项目名称:kinectitude,代码行数:7,代码来源:KGLBase.cs
示例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;
}
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:23,代码来源:Grammar.cs
示例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;
}
开发者ID:TheByte,项目名称:sones,代码行数:16,代码来源:ParserDataBuilder.cs
示例15: Op_Plus
internal static BnfExpression Op_Plus(BnfTerm term1, BnfTerm term2)
{
return term1 + term2;
}
开发者ID:davidnemeti,项目名称:Sarcasm,代码行数:4,代码来源:BnfiExpression.cs
示例16: IsMainChild
private static bool IsMainChild(BnfTerm bnfTerm)
{
return !(bnfTerm is KeyTerm) && !(bnfTerm is GrammarHint);
}
开发者ID:davidnemeti,项目名称:Sarcasm,代码行数:4,代码来源:BnfiTermChoice.cs
示例17: MakeStarRule
public BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember)
{
return MakeListRule(listNonTerminal, delimiter, listMember, TermListOptions.StarList);
}
开发者ID:adrobyazko-softheme,项目名称:PQL,代码行数:4,代码来源:Grammar.cs
示例18: MakePlusRule
public BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm listMember)
{
return MakeListRule(listNonTerminal, null, listMember);
}
开发者ID:adrobyazko-softheme,项目名称:PQL,代码行数:4,代码来源:Grammar.cs
示例19: MakeStarRule
public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember) {
if (delimiter == null) {
//it is much simpler case
listNonTerminal.SetOption(TermOptions.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 tmp = new NonTerminal(listMember.Name + "+");
tmp.SetOption(TermOptions.IsTransient); //important - mark it as Transient so it will be eliminated from AST tree
MakePlusRule(tmp, delimiter, listMember);
listNonTerminal.Rule = _currentGrammar.Empty | tmp;
//listNonTerminal.SetOption(TermOptions.IsStarList);
return listNonTerminal.Rule;
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:19,代码来源:Grammar.cs
示例20: MakeListRule
protected BnfExpression MakeListRule(NonTerminal list, BnfTerm delimiter, BnfTerm listMember, TermListOptions options = TermListOptions.PlusList)
{
//If it is a star-list (allows empty), then we first build plus-list
var isStarList = options.IsSet(TermListOptions.AllowEmpty);
NonTerminal plusList = isStarList ? new NonTerminal(listMember.Name + "+") : list;
//"list" is the real list for which we will construct expression - it is either extra plus-list or original listNonTerminal.
// In the latter case we will use it later to construct expression for listNonTerminal
plusList.Rule = plusList; // rule => list
if (delimiter != null)
plusList.Rule += delimiter; // rule => list + delim
if (options.IsSet(TermListOptions.AddPreferShiftHint))
plusList.Rule += PreferShiftHere(); // rule => list + delim + PreferShiftHere()
plusList.Rule += listMember; // rule => list + delim + PreferShiftHere() + elem
plusList.Rule |= listMember; // rule => list + delim + PreferShiftHere() + elem | elem
//trailing delimiter
if (options.IsSet(TermListOptions.AllowTrailingDelimiter) & delimiter != null)
plusList.Rule |= list + delimiter; // => list + delim + PreferShiftHere() + elem | elem | list + delim
// set Rule value
plusList.SetFlag(TermFlags.IsList);
//If we do not use exra list - we're done, return list.Rule
if (plusList == list)
return list.Rule;
// Let's setup listNonTerminal.Rule using plus-list we just created
//If we are here, TermListOptions.AllowEmpty is set, so we have star-list
list.Rule = Empty | plusList;
plusList.SetFlag(TermFlags.NoAstNode);
list.SetFlag(TermFlags.IsListContainer); //indicates that real list is one level lower
return list.Rule;
}
开发者ID:201123065,项目名称:Irony,代码行数:29,代码来源:Grammar.cs
注:本文中的BnfTerm类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论