internal override bool Parse(Token curToken, Lexer lexer) { if (index == null) { switch (curToken.Type) { case TokenTypes.Name: index = new NameExpression(((NameToken)curToken).Content); return(true); case TokenTypes.StringLiteral: index = new StringLiteralExpression(((StringLiteralToken)curToken).Content); return(true); default: return(false); } } else { if (!index.Completed) { return(index.Parse(curToken, lexer)); } else { if (!isCompleted) { switch (curToken.Type) { case TokenTypes.IndexEnd: isCompleted = true; return(true); case TokenTypes.MemberAccess: index = new MemberAcessExpression(index); return(true); case TokenTypes.IndexStart: index = new IndexAccessExpression(index); return(true); case TokenTypes.InvocationStart: index = new InvocationExpression(index); return(true); default: return(false); } } else { return(false); } } } }
public EvalExpression Parse() { var curToken = lexer.GetNextToken(); EvalExpression res = null; while (curToken.Type != TokenTypes.EOF) { if (res == null) { if (curToken.Type == TokenTypes.Name) { res = new NameExpression(((NameToken)curToken).Content); res.IsRoot = true; } else { throw new NotSupportedException("Unexpected token:" + curToken.Type); } } else { if (!res.Parse(curToken, lexer)) { switch (curToken.Type) { case TokenTypes.MemberAccess: res.IsRoot = false; res = new MemberAcessExpression(res); res.IsRoot = true; break; case TokenTypes.IndexStart: res.IsRoot = false; res = new IndexAccessExpression(res); res.IsRoot = true; break; case TokenTypes.InvocationStart: res.IsRoot = false; res = new InvocationExpression(res); res.IsRoot = true; break; default: throw new NotSupportedException("Unexpected token:" + curToken.Type); } } } curToken = lexer.GetNextToken(); } if (res != null && !res.Completed) { throw new NotSupportedException("Unexpected token: EOF"); } return(res); }
public MemberAcessExpression(EvalExpression body) { if (body is NameExpression || body is MemberAcessExpression || body is IndexAccessExpression || body is InvocationExpression) { this.body = body; } else { throw new NotSupportedException("Cannot retrive member for " + body); } }
internal override bool Parse(Token curToken, Lexer lexer) { if (curParam == null) { switch (curToken.Type) { case TokenTypes.Name: curParam = new NameExpression(((NameToken)curToken).Content); return(true); case TokenTypes.StringLiteral: curParam = new StringLiteralExpression(((StringLiteralToken)curToken).Content); return(true); default: return(false); } } else { if (!curParam.Completed) { return(curParam.Parse(curToken, lexer)); } else { if (!isCompleted) { switch (curToken.Type) { case TokenTypes.InvocationEnd: if (curParam != null) { parameters.Add(curParam); } isCompleted = true; return(true); case TokenTypes.MemberAccess: curParam = new MemberAcessExpression(curParam); return(true); case TokenTypes.IndexStart: curParam = new IndexAccessExpression(curParam); return(true); case TokenTypes.InvocationStart: curParam = new InvocationExpression(curParam); return(true); case TokenTypes.Comma: if (curParam != null) { parameters.Add(curParam); return(true); } else { return(false); } default: return(false); } } else { return(false); } } } }