示例#1
0
		public Expr OnParseReturn()
		{
            var tokenIt = this._parser.TokenIt;
            var initiatorToken = tokenIt.NextToken;
            var expr = new ReturnExpr();
            // <codeReturn>

            tokenIt.Expect(Tokens.Return);
            if (tokenIt.IsEndOfStmtOrBlock())
                return expr;

            var exp = this._parser.ParseExpression(Terminators.ExpStatementEnd, passNewLine: false);
            expr.Exp = exp;

            // </codeReturn>
			this._parser.SetupContext(expr, initiatorToken);
			return expr;
		}
示例#2
0
        /// <summary>
        /// Execute the statement.
        /// </summary>
        public object VisitReturn(ReturnExpr expr)
        {
            var parent = expr.FindParent<FunctionExpr>();
            if (parent == null) throw new LangException("syntax error", "unable to return, parent not found", string.Empty, 0);

            object result = expr.Exp == null ? LObjects.Null : expr.Exp.Evaluate(this);
            bool hasReturnVal = expr.Exp != null;
            parent.HasReturnValue = hasReturnVal;
            parent.ReturnValue = result;
            parent.ContinueRunning = false;
            return LObjects.Null;
        }
示例#3
0
 /// <summary>
 /// Visits the try statement tree.
 /// </summary>
 /// <param name="tryExpr"></param>
 public object VisitReturn(ReturnExpr expr)
 {
     _callBackOnNodeStart(expr);
     return null;
 }