private Expression ParseReferenceExpression(Expression hint) { var references = new List <Expression>(); references.Add(hint); do { Take(TokenKind.Dot); if (current == TokenKind.Identifier) { var expr = ParseIdentiferExpression(); references.Add(expr); } if (current == TokenKind.LeftParenthesis) { var expr = new ReferenceExpression(CreateSpan(hint), references); return(ParseFuncCallExpression(expr)); } } while (current == TokenKind.Dot); ReferenceExpression r = new ReferenceExpression(CreateSpan(hint), references); statm.Add(r); return(r); }
public bool IsIdentifier(Expression expr) { if (expr.Kind == SyntaxKind.IdentifierExpression) { IdentifierExpression id = (IdentifierExpression)expr; foreach (var v in FindVariable()) { if (v.Name == id.Identifier) { return(true); } } foreach (var v in FindFunction()) { if (v.Name == id.Identifier) { return(true); } } foreach (var v in FindParam()) { if (v.Name == id.Identifier) { return(true); } } return(false); } return(true); }
private Expression ParseFuncCallExpression(Expression reference) { var arguments = new List <Expression>(); MakeBlock(() => { if (current != TokenKind.RightParenthesis) { arguments.Add(ParseExpression()); while (current == TokenKind.Comma) { Take(TokenKind.Comma); arguments.Add(ParseExpression()); } } }, TokenKind.LeftParenthesis, TokenKind.RightParenthesis); var expr = new FuncCallExpression(CreateSpan(reference), reference, arguments); if (current == TokenKind.Dot) { return(ParseReferenceExpression(expr)); } statm.Add(expr); return(expr); }
protected void VisitExpression(Expression expression) { switch (expression.Kind) { case SyntaxKind.BinaryExpression: VisitBinary(expression as BinaryExpression); break; case SyntaxKind.ConstantExpression: VisitConstant(expression as ConstantExpression); break; case SyntaxKind.IdentifierExpression: VisitIdentifier(expression as IdentifierExpression); break; case SyntaxKind.LambdaExpression: VisitLambda(expression as LambdaExpression); break; case SyntaxKind.FuncCallExpression: VisitFuncCall(expression as FuncCallExpression); break; case SyntaxKind.ReferenceExpression: VisitReference(expression as ReferenceExpression); break; } }
/* private Expression ParseOverrideExpression() * { * var start = Take(TokenKind.LeftParenthesis).Span.Start; * * if (current == TokenKind.RightParenthesis) * { * Take(TokenKind.RightParenthesis); * return ParseLambdaExpression(start, new ParameterDeclaration[0]); * } * * if (current == TokenKind.Identifier * && (next == TokenKind.Comma || next == TokenKind.Colon)) || { || index--; || var parameters = ParseParameterList(); || return ParseLambdaExpression(start, parameters); || } || || var expr = ParseExpression(); || || Take(TokenKind.RightParenthesis); || || if (current == TokenKind.LeftParenthesis) || { || return ParseMethodCallExpression(expr); || } || else if (current == TokenKind.Dot) || { || return ParseReferenceExpression(expr); || } || || return expr; ||}*/ private Expression ParsePredicate() { Expression expr = null; MakeBlock(() => { expr = ParseLogicalExpression(); }, TokenKind.LeftParenthesis, TokenKind.RightParenthesis); statm.Add(expr); return(expr); }
private Expression ParseLogicalExpression() { Expression left = ParseEqualityExpression(); while (IsLogicalOperator()) { var op = ParseBinaryOperator(); var right = ParseEqualityExpression(); left = new BinaryExpression(CreateSpan(left), left, right, op); statm.Add(left); } return(left); }
private Expression ParseAssignmentExpression() { // Console.WriteLine($" start in assign"); Expression left = ParsePrimaryExpression(); Token lasts = last; if (IsAssignmentOperator()) { // Assignment is right-associative. var op = ParseBinaryOperator(); Expression right = ParseAssignmentExpression(); // Console.WriteLine($"in assign"); BinaryExpression b = new BinaryExpression(CreateSpan(left), left, right, op); statm.Add(b); return(b); } return(left); }