/// <returns> Returned value or null for statements </returns>
		public static Value Evaluate(string code, SupportedLanguage language, StackFrame context)
		{
			SnippetParser parser = new SnippetParser(language);
			INode astRoot = parser.Parse(code);
			if (parser.SnippetType == SnippetType.Expression ||
			    parser.SnippetType == SnippetType.Statements) {
				if (parser.Errors.Count > 0) {
					throw new GetValueException(parser.Errors.ErrorOutput);
				}
				try {
					EvaluateAstVisitor visitor = new EvaluateAstVisitor(context);
					
					return astRoot.AcceptVisitor(visitor, null) as Value;
				} catch (NotImplementedException e) {
					throw new GetValueException("Language feature not implemented: " + e.Message);
				}
			}
			throw new GetValueException("Code must be expression or statement");
		}
Beispiel #2
0
        /// <returns> Returned value or null for statements </returns>
        public static Value Evaluate(string code, SupportedLanguage language, StackFrame context)
        {
            SnippetParser parser  = new SnippetParser(language);
            INode         astRoot = parser.Parse(code);

            if (parser.SnippetType == SnippetType.Expression ||
                parser.SnippetType == SnippetType.Statements)
            {
                if (parser.Errors.Count > 0)
                {
                    throw new GetValueException(parser.Errors.ErrorOutput);
                }
                try {
                    EvaluateAstVisitor visitor = new EvaluateAstVisitor(context);

                    return(astRoot.AcceptVisitor(visitor, null) as Value);
                } catch (NotImplementedException e) {
                    throw new GetValueException("Language feature not implemented: " + e.Message);
                }
            }
            throw new GetValueException("Code must be expression or statement");
        }