YExpr ProcessExpr(AssignmentExpressionSyntax assignmentExpression) { YExpr left = ProcessExpr(assignmentExpression.Left); YExpr right = ProcessExpr(assignmentExpression.Right); return(new YAssign(left, right)); }
YStatement ProcessStatement(IfStatementSyntax ifStatement) { YExpr condition = ProcessExpr(ifStatement.Condition); YStatement statement = ProcessStatement(ifStatement.Statement); YStatement elseStatement = ProcessStatement(ifStatement.Else.Statement); return(new YIf(condition, statement, elseStatement)); }
YExpr ProcessExpr(MemberAccessExpressionSyntax memberAccessExpression) { YExpr expr = ProcessExpr(memberAccessExpression.Expression); return(new YMemberAccessExpr( expr, memberAccessExpression.Name.Identifier.ToString() )); }
/// <summary> /// Unwrap expression to string. /// </summary> static public void AppendEx(this StringBuilder builder, YExpr expr) { if (expr is YConstExpr) { builder.Append("" + expr); } else if (expr is YThisExpr) { builder.Append("this"); } else if (expr is YMemberAccessExpr) { var memberAccess = (YMemberAccessExpr)expr; AppendEx(builder, memberAccess.Expression); builder.Append("->"); // But what with "this."? builder.Append(memberAccess.Name); } else if (expr is YIdentifierExpr) { builder.Append(((YIdentifierExpr)expr).Name); } else if (expr is YBinaryExpr) { var binary = (YBinaryExpr)expr; AppendEx(builder, binary.Left); builder.Append(" "); AppendEx(builder, binary.Operator); builder.Append(" "); AppendEx(builder, binary.Right); } else if (expr is YLiteralExpr) { var literal = (YLiteralExpr)expr; if (literal == YLiteralExpr.Null) { builder.Append("nullptr"); } else { builder.Append(literal.Value); } } else if (expr is YPrefixUnaryExpr) { var prefixUnari = (YPrefixUnaryExpr)expr; AppendEx(builder, prefixUnari.Operator); AppendEx(builder, prefixUnari.Operand); } else if (expr is YInvocation) { var invocation = (YInvocation)expr; AppendEx(builder, invocation.Expression); // no arguments builder.Append("()"); } else if (expr is YAssign) { var assign = (YAssign)expr; AppendEx(builder, assign.Left); builder.Append("="); AppendEx(builder, assign.Right); } }
public YMemberAccessExpr(YExpr expression, string name) { Expression = expression; Name = name; }
public YIf(YExpr condition, YStatement statement, YStatement elseStatement) { Condition = condition; Statement = statement; ElseStatement = elseStatement; }
public YAssign(YExpr left, YExpr right) { Left = left; Right = right; }
public YPrefixUnaryExpr(YOperator @operator, YExpr operand) { Operator = @operator; Operand = operand; }
public YInvocation(YExpr expression) { Expression = expression; }
public YBinaryExpr(YExpr left, YExpr right, YOperator operation) { Left = left; Right = right; Operator = operation; }
public YReturn(YExpr value) { Value = value; }
public YExprStatement(YExpr expression) { Expression = expression; }