本文整理汇总了C#中ExpressionStatement.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionStatement.AddChild方法的具体用法?C# ExpressionStatement.AddChild怎么用?C# ExpressionStatement.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionStatement
的用法示例。
在下文中一共展示了ExpressionStatement.AddChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CSharpGrammar
// IMPORTANT NOTE:
// The grammar consists of a few LALR(1) conflicts. These issues are, however, correctly handled, due to the fact that the grammar
// is defined in a specific order making the already added parser actions have precedence over the other.
//
// Known conflicts that are correctly handled:
//
// - ELSE: Shift/Reduce conflict Dangling ELSE problem. Lots of articles are around on the internet.
// The shift action is taken here.
//
// - CLOSE_PARENS: Shift/Reduce conflict. This is due to the fact that the explicit cast expression is like the parenthesized
// expression. The shift action is taken here.
//
// - STAR: Reduce/Reduce conflict, between VariableType -> TypeNameExpression and PrimaryExpression -> TypeNameExpression,
// due to the fact variable types can have '*', and look therefore like a binary operator expression.
// The first reduce action is taken here.
public CSharpGrammar()
{
// Please let me know if there is a better way of tidying this :s
TokenMapping.Add((int)ERROR, Error);
#region Definitions to use later
var statementList = new GrammarDefinition("StatementList");
var statementListOptional = new GrammarDefinition("StatementListOptional",
rule: null
| statementList);
var blockStatement = new GrammarDefinition("BlockStatement");
var variableDeclarator = new GrammarDefinition("VariableDeclarator");
var variableDeclaratorList = new GrammarDefinition("VariableDeclaratorList");
variableDeclaratorList.Rule = variableDeclarator
| variableDeclaratorList
+ ToElement(COMMA)
+ variableDeclarator;
var variableDeclaration = new GrammarDefinition("VariableDeclaration");
var variableInitializer = new GrammarDefinition("VariableInitializer");
var arrayInitializer = new GrammarDefinition("ArrayInitializer");
var arrayInitializerOptional = new GrammarDefinition("ArrayInitializerOptional",
rule: null | arrayInitializer);
var identifierInsideBody = new GrammarDefinition("IdentifierInsideBody",
rule: ToElement(IDENTIFIER),
createNode: node => ToIdentifier(node.Children[0].Result));
var identifierInsideBodyOptional = new GrammarDefinition("IdentifierInsideBodyOptional",
rule: null | identifierInsideBody);
variableDeclarator.Rule = identifierInsideBody
| identifierInsideBody
+ ToElement(EQUALS)
+ variableInitializer;
variableDeclarator.ComputeResult = node =>
{
var result = new VariableDeclarator((Identifier) node.Children[0].Result);
if (node.Children.Count > 1)
{
result.OperatorToken = (AstToken) node.Children[1].Result;
result.Value = (Expression) node.Children[2].Result;
}
return result;
};
var typeReference = new GrammarDefinition("TypeReference");
var identifierExpression = new GrammarDefinition("IdentifierExpression",
rule: identifierInsideBody,
createNode: node => new IdentifierExpression((Identifier) node.Children[0].Result));
var usingDirectiveListOptional = new GrammarDefinition("UsingDirectiveListOptional");
#endregion
#region Type References
var namespaceOrTypeExpression = new GrammarDefinition("NamespaceOrTypeExpression");
namespaceOrTypeExpression.Rule = identifierExpression |
namespaceOrTypeExpression
+ ToElement(DOT)
+ ToElement(IDENTIFIER);
namespaceOrTypeExpression.ComputeResult = node =>
{
if (node.Children.Count == 1)
return ToTypeReference((IConvertibleToType) node.Children[0].Result);
var result = new MemberTypeReference();
result.Target = (TypeReference) node.Children[0].Result;
result.AddChild(AstNodeTitles.Accessor, node.Children[1].Result);
result.Identifier = ToIdentifier(node.Children[2].Result);
return result;
};
ComputeResultDelegate createPrimitiveTypeExpression = node =>
{
if (node.Children[0].Result is PrimitiveTypeReference)
return node.Children[0].Result;
return new PrimitiveTypeReference
{
Identifier = ToIdentifier(node.Children[0].Result),
//.........这里部分代码省略.........
示例2: Visit
public override object Visit (InvalidStatementExpression statementExpression)
{
var result = new ExpressionStatement ();
if (statementExpression.Expression == null)
return result;
var expr = statementExpression.Expression.Accept (this) as Expression;
if (expr != null)
result.AddChild (expr, Roles.Expression);
var location = LocationsBag.GetLocations (statementExpression);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.Semicolon), Roles.Semicolon);
return result;
}