Пример #1
0
        /// <summary>
        /// return value;
        /// </summary>
        /// <returns></returns>
        public override Expr  Parse()
        {
            var stmt = new ReturnExpr();
            _tokenIt.Expect(Tokens.Return);
            if (_tokenIt.IsEndOfStmtOrBlock())
                return stmt;

            var exp = _parser.ParseExpression(Terminators.ExpStatementEnd, passNewLine: false);
            stmt.Exp = exp;
            return stmt;
        }
Пример #2
0
 /// <summary>
 /// Visits the try statement tree.
 /// </summary>
 /// <param name="tryExpr"></param>
 public object VisitReturn(ReturnExpr expr)
 {
     _callBackOnNodeStart(expr);
     return null;
 }
Пример #3
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;
        }
Пример #4
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;
        }