本文整理汇总了C#中ParseTreeNode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ParseTreeNode.ToString方法的具体用法?C# ParseTreeNode.ToString怎么用?C# ParseTreeNode.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseTreeNode
的用法示例。
在下文中一共展示了ParseTreeNode.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddParseNodeRec
protected override void AddParseNodeRec(ParseTreeNode nodeInfo, bool skip)
{
if (nodeInfo == null || skip) return;
Token token = nodeInfo.AstNode as Token;
if (token != null)
{
if (token.Terminal.Category != TokenCategory.Content) return;
}
try
{
bool isClassDef = (String.Compare(nodeInfo.ToString(), "class_declaration") == 0);
bool isClassField = (String.Compare(nodeInfo.ToString(), "field_declaration") == 0);
bool isClassProperty = (String.Compare(nodeInfo.ToString(), "property_declaration") == 0);
if (isClassDef)
{
curCtrl = nodeInfo.ChildNodes[3].ToString();
curCtrl = curCtrl.Substring(0, curCtrl.Length - tail.Length);
controllerInfo.Add(new ControllerMetadata(curCtrl));
curbpi.controller = controllerInfo[controllerInfo.Count - 1];
curbpi.controller.Line = token.Location.Line;
curbpi.controller.FileName = this.FileName;
curFieldOrProp = String.Empty;
}
else if (isClassField)
{
//[0]<member_header>[1]<type_ref>[2]<variable_declarators>
ParseTreeNode varDeclarator = nodeInfo.ChildNodes[2];
while (varDeclarator.ChildNodes.Count > 0)
varDeclarator = varDeclarator.ChildNodes[0];
curFieldOrProp = varDeclarator.ToString();
curFieldOrProp = curFieldOrProp.Substring(0, curFieldOrProp.Length - tail.Length);
}
else if (isClassProperty)
{
//[0]<member_header>[1]<type_ref>[2]<qual_name_with_targs>[3]<accessor_declaration>
ParseTreeNode qual_name = nodeInfo.ChildNodes[2];
if (qual_name.ChildNodes[1].ChildNodes.Count > 0)
{
//property name is full,like N1.I.PropName
//go down until we reach '.<Name>'
while (qual_name.ChildNodes.Count > 0)
qual_name = qual_name.ChildNodes[qual_name.ChildNodes.Count - 1];
curFieldOrProp = qual_name.ToString();
}
else
//property name is identifier_or_builtin -> identifier
curFieldOrProp = qual_name.ChildNodes[0].ChildNodes[0].ToString();
curFieldOrProp = curFieldOrProp.Substring(0, curFieldOrProp.Length - tail.Length);
}
AnalyzeTree(nodeInfo);
}
catch (Exception ex)
{
}
}
示例2: AddParseNodeRec
protected override void AddParseNodeRec(ParseTreeNode nodeInfo, bool skip)
{
if (nodeInfo == null || skip) return;
Token token = nodeInfo.AstNode as Token;
if (token != null)
{
if (token.Terminal.Category != TokenCategory.Content) return;
}
try
{
//bool isFuncDef = (String.Compare(nodeInfo.ToString(), "FunctionDef") == 0);
if (String.Compare(nodeInfo.ToString(), "FunctionDef") == 0)
{
//Trace.WriteLine(txt + " of " + nodeInfo.ChildNodes[2] + " :");
curCtrl = nodeInfo.ChildNodes[2].ToString();
curCtrl = curCtrl.Substring(0, curCtrl.Length - tail.Length);
controllerInfo.Add(new ControllerMetadata(curCtrl));
curbpi.controller = controllerInfo[controllerInfo.Count - 1];
}
AnalyzeTree(nodeInfo);
}
catch (Exception ex)
{
}
}
示例3: AddParseNodeRec
private void AddParseNodeRec(int depth, ParseTreeNode node)
{
if (node == null) return;
BnfTerm term = node.Term;
string txt = node.ToString();
if (term == null) {
txt = "NullTerm";
}
else {
txt = term.GetParseNodeCaption(node);
}
//var t = " "*6;
for (int i = 0; i < depth; i++) Console.Write(" ");
if (node.Token != null) {
Console.WriteLine(node.Token.Value + " " + node.Token.Terminal.ToString());
}
else
Console.WriteLine(node.Term.Name);
// Console.WriteLine(node.ToString());
foreach (var child in node.ChildNodes)
AddParseNodeRec(depth + 1, child);
}
示例4: AddParseNode
private void AddParseNode(TreeNode parent, ParseTreeNode node)
{
if (node == null) return;
string txt = node.ToString();
TreeNode tvNode = (parent == null ? tvParse.Nodes.Add(txt) : parent.Nodes.Add(txt));
tvNode.Tag = node;
foreach (var child in node.ChildNodes)
{
AddParseNode(tvNode, child);
}
}
示例5: Get
public static FileRedirectionOperator Get(ParseTreeNode parseTreeNode)
{
switch (parseTreeNode.Token.ValueString)
{
case ">":
return new FileRedirectionOperator(RedirectionStream.Output);
case ">>":
return new FileRedirectionOperator(RedirectionStream.Output, true);
case "2>":
return new FileRedirectionOperator(RedirectionStream.Error);
case "2>>":
return new FileRedirectionOperator(RedirectionStream.Error, true);
default:
throw new NotImplementedException(parseTreeNode.ToString());
}
}
示例6: BuildStatementAst
StatementAst BuildStatementAst(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, this._grammar.statement);
parseTreeNode = parseTreeNode.ChildNodes.Single();
if (parseTreeNode.Term == this._grammar.if_statement)
{
return BuildIfStatementAst(parseTreeNode);
}
if (parseTreeNode.Term == this._grammar._statement_labeled_statement)
{
return BuildLabeledStatementAst(parseTreeNode);
}
if (parseTreeNode.Term == this._grammar.function_statement)
{
return BuildFunctionStatementAst(parseTreeNode);
}
if (parseTreeNode.Term == this._grammar.flow_control_statement)
{
return BuildFlowControlStatementAst(parseTreeNode);
}
if (parseTreeNode.Term == this._grammar.trap_statement)
{
return BuildTrapStatementAst(parseTreeNode);
}
if (parseTreeNode.Term == this._grammar.try_statement)
{
return BuildTryStatementAst(parseTreeNode);
}
if (parseTreeNode.Term == this._grammar.data_statement)
{
return BuildDataStatementAst(parseTreeNode);
}
if (parseTreeNode.Term == this._grammar.pipeline)
{
return BuildPipelineAst(parseTreeNode);
}
throw new InvalidOperationException(parseTreeNode.ToString());
}
示例7: BuildScriptBlockBodyAst
StatementBlockAst BuildScriptBlockBodyAst(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, this._grammar.script_block_body);
parseTreeNode = parseTreeNode.ChildNodes.Single();
if (parseTreeNode.Term == this._grammar.named_block_list)
{
return BuildNamedBlockListAst(parseTreeNode);
}
if (parseTreeNode.Term == this._grammar.statement_list)
{
return BuildStatementListAst(parseTreeNode);
}
throw new InvalidOperationException(parseTreeNode.ToString());
}
示例8: ejecutar
public Object ejecutar(ParseTreeNode raiz)
{
string I = raiz.ToString();
ParseTreeNode[] hijos = null;
if (raiz.ChildNodes.Count > 0)
{
hijos = raiz.ChildNodes.ToArray();
}
switch (I)
{
case "S":
{
return ejecutar(hijos[0]);
}
case "DECLA":
{
String[] n1 = hijos[1].ToString().Split(new Char[] { ' ' });
NodoVar v = frmCompi.variables.buscar(n1[0]);
if (v == null)
{
NodoVar var = new NodoVar("var", n1[0]);
var.valor = ejecutar(hijos[3]);
frmCompi.variables.insertar(var);
return var.valor;
}
else
{
MessageBox.Show("variable ya existe");
}
return null;
}
case "E":
{
return ejecutar(hijos[0]);
}
case "T":
{
if (hijos.Count() == 1)
{
return ejecutar(hijos[0]);
}
else
{
Object iz = ejecutar(hijos[0]);
Object de = ejecutar(hijos[2]);
if (hijos[1].ToString().Contains("+"))
{
return Convert.ToDouble(iz) + Convert.ToDouble(de);
}
else
{
return Convert.ToDouble(iz) + Convert.ToDouble(de);
}
}
}
case "F":
{
if (hijos.Count() == 1)
{
return ejecutar(hijos[0]);
}
else
{
Object iz = ejecutar(hijos[0]);
Object de = ejecutar(hijos[2]);
if (hijos[1].ToString().Contains("/"))
{
return Convert.ToDouble(iz) / Convert.ToDouble(de);
}
else
{
return Convert.ToDouble(iz) * Convert.ToDouble(de);
}
}
}
case "G":
{
if (hijos.Count() == 1)
{
return ejecutar(hijos[0]);
}
else
{
Object iz = ejecutar(hijos[0]);
Object de = ejecutar(hijos[2]);
return Math.Pow(Convert.ToDouble(iz), Convert.ToDouble(de));
}
}
case "H":
{
if (hijos.Count() == 1)
{
return ejecutar(hijos[0]);
}
else
{
Object de = ejecutar(hijos[1]);
return (-1 * Convert.ToDouble(de));
//.........这里部分代码省略.........
示例9: BuildGenericTokenAst
StringConstantExpressionAst BuildGenericTokenAst(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, this._grammar.generic_token);
// I'm confused by the idea that a generic_token could have several of these things smushed together, like this:
// PS> g"et-childite"m # OK!
var match = this._grammar.generic_token.Expression.Match(parseTreeNode.Token.Text);
if (match.Groups[this._grammar.expandable_string_literal.Name].Success) throw new NotImplementedException(parseTreeNode.ToString());
//if (match.Groups[this._grammar.verbatim_here_string_literal.Name].Success) throw new NotImplementedException(parseTreeNode.ToString());
if (match.Groups[this._grammar.variable.Name].Success) throw new NotImplementedException(parseTreeNode.ToString());
return new StringConstantExpressionAst(new ScriptExtent(parseTreeNode), parseTreeNode.Token.Text, StringConstantType.BareWord);
}
示例10: BuildCommandElementAst
CommandElementAst BuildCommandElementAst(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, this._grammar.command_element);
var childNode = parseTreeNode.ChildNodes.Single();
if (childNode.Term == this._grammar.command_parameter)
{
return BuildCommandParameterAst(childNode);
}
if (childNode.Term == this._grammar.command_argument)
{
return BuildCommandArgumentAst(childNode);
}
if (childNode.Term == this._grammar.redirection) throw new NotImplementedException(childNode.ToString());
throw new InvalidOperationException(parseTreeNode.ToString());
}
示例11: ParseMultiplicativeOperator
private TokenKind ParseMultiplicativeOperator(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, _grammar._multiplicative_expression_operator);
KeyTerm keyTerm = (KeyTerm) parseTreeNode.ChildNodes.Single().Term as KeyTerm;
if (keyTerm != null)
{
string symbol = keyTerm.Text;
if (symbol.Equals("*"))
{
return TokenKind.Multiply;
}
else if (symbol.Equals("/"))
{
return TokenKind.Divide;
}
else if (symbol.Equals("%"))
{
return TokenKind.Rem;
}
}
throw new NotSupportedException(String.Format("Unsupported operator node '{0}'",
parseTreeNode.ToString()));
}
示例12: BuildUnaryDashExpressionAst
ExpressionAst BuildUnaryDashExpressionAst(ParseTreeNode parseTreeNode)
{
var expression = BuildUnaryExpressionAst(parseTreeNode.ChildNodes[1]);
var constantExpressionAst = expression as ConstantExpressionAst;
var type = constantExpressionAst.StaticType;
if (constantExpressionAst == null)
{
throw new NotImplementedException(parseTreeNode.ToString());
}
else
{
// From the spec (2.3.5.1.1 Integer literals):
// “In the twos-complement representation of integer values,
// there is one more negative value than there is positive.
// For the int type, that extra value is -2147483648. For the
// long type, that extra value is -9223372036854775808. Even
// though the token 2147483648 would ordinarily be treated as
// a literal of type long, if it is preceded immediately by
// the unary - operator, that operator and literal are treated
// as a literal of type int having the smallest value.
// Similarly, even though the token 9223372036854775808 would
// ordinarily be treated as a real literal of type decimal,
// if it is immediately preceded by the unary - operator, that
// operator and literal are treated as a literal of type long
// having the smallest value.”
// The following code deals both with conflating unary minus
// and a constant expression into a single constant expression
// as well as the type juggling the above quote from the
// specification entails.
// TODO: The wording of the specification only refers to
// int.MinValue and long.MinValue, which should be parsed as a
// single literal. Would we normally have to treat everything
// else as the combination of an unary minus and a constant
// expression?
if (type == typeof(int))
{
var value = (int)constantExpressionAst.Value;
return new ConstantExpressionAst(new ScriptExtent(parseTreeNode), 0 - value);
}
else if (type == typeof(long))
{
var value = (long)constantExpressionAst.Value;
if (value == -(long)int.MinValue)
return new ConstantExpressionAst(new ScriptExtent(parseTreeNode), int.MinValue);
else
return new ConstantExpressionAst(new ScriptExtent(parseTreeNode), 0L - value);
}
else if (type == typeof(decimal))
{
var value = (decimal)constantExpressionAst.Value;
if (value == -(decimal)long.MinValue)
return new ConstantExpressionAst(new ScriptExtent(parseTreeNode), long.MinValue);
else
return new ConstantExpressionAst(new ScriptExtent(parseTreeNode), 0m - value);
}
else if (type == typeof(double))
{
var value = (double)constantExpressionAst.Value;
return new ConstantExpressionAst(new ScriptExtent(parseTreeNode), 0d - value);
}
else
{
throw new NotImplementedException(parseTreeNode.ToString());
}
}
}
示例13: BuildMemberAccessOrInvocationExpressionAst
MemberExpressionAst BuildMemberAccessOrInvocationExpressionAst(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, this._grammar._member_access_or_invocation_expression);
var typeExpressionAst = BuildPrimaryExpressionAst(parseTreeNode.ChildNodes[0]);
bool @static = parseTreeNode.ChildNodes[1].FindTokenAndGetText() == "::";
var memberName = BuildMemberNameAst(parseTreeNode.ChildNodes[2]);
if (parseTreeNode.ChildNodes.Count == 3)
{
return new MemberExpressionAst(new ScriptExtent(parseTreeNode), typeExpressionAst, memberName, @static);
}
else if (parseTreeNode.ChildNodes.Count == 5)
{
return new InvokeMemberExpressionAst(
new ScriptExtent(parseTreeNode),
typeExpressionAst,
memberName,
null,
@static
);
}
else if (parseTreeNode.ChildNodes.Count == 6)
{
return new InvokeMemberExpressionAst(
new ScriptExtent(parseTreeNode),
typeExpressionAst,
memberName,
BuildArgumentExpressionList(parseTreeNode.ChildNodes[4]),
@static
);
}
throw new NotImplementedException(parseTreeNode.ToString());
}
示例14: BuildCommandOptElementAsts
IEnumerable<CommandElementAst> BuildCommandOptElementAsts(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, this._grammar.command_elements);
var elementAsts = new List<CommandElementAst>();
CommandParameterAst lastParameter = null;
var commandElements = from child in parseTreeNode.ChildNodes select child.ChildNodes.Single();
foreach (var cmdElementTree in commandElements)
{
// first check if a parameter is waiting for its argument
if (lastParameter != null && lastParameter.RequiresArgument)
{
// lastParameter is already in elementAsts list, only set the Argument property
lastParameter.Argument = BuildCommandArgumentAstFromCommandElement(cmdElementTree,
lastParameter.ParameterName);
lastParameter = null; // makes sure we don't set it twice
continue;
}
// otherwise check for parameters, arguments, and redirection
if (cmdElementTree.Term == this._grammar.command_parameter)
{
lastParameter = BuildCommandParameterAst(cmdElementTree);
elementAsts.Add(lastParameter);
}
else if (cmdElementTree.Term == this._grammar.command_argument)
{
elementAsts.Add(BuildCommandArgumentAst(cmdElementTree));
}
else if (cmdElementTree.Term == this._grammar.redirection)
{
// Redirections are built separately.
}
else
{
throw new InvalidOperationException(parseTreeNode.ToString());
}
}
// make sure the last parameter didn't expect an argument that was not provided
if (lastParameter != null && lastParameter.RequiresArgument)
{
throw new ParseException(String.Format("The parameter \"-{0}\" requires an argument",
lastParameter.ParameterName));
}
return PostprocessCommandElements(elementAsts);
}
示例15: BuildStringLiteralWithSubexpressionAst
ExpressionAst BuildStringLiteralWithSubexpressionAst(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, this._grammar.string_literal_with_subexpression);
parseTreeNode = parseTreeNode.ChildNodes.Single();
if (parseTreeNode.Term == this._grammar.expandable_string_literal_with_subexpr)
{
return BuildExpandableStringLiteralWithSubexpressionAst(parseTreeNode);
}
throw new InvalidOperationException(parseTreeNode.ToString());
}