예제 #1
0
파일: Interpreter.cs 프로젝트: sirgru/CsLox
        public Void Visit_ReturnStmt(ReturnStmt stmt)
        {
            Object value = null;

            if (stmt.value != null)
            {
                value = Evaluate(stmt.value);
            }

            throw new Return(value);
        }
예제 #2
0
        public Void Visit_ReturnStmt(ReturnStmt stmt)
        {
            if (_currentFunctionType == FunctionType.None)
            {
                _errors.Add(new Error(stmt.keyword, ErrorType.InvalidReturnUsage, "Cannot return from top-level code."));
            }

            if (stmt.value != null)
            {
                if (_currentFunctionType == FunctionType.Initializer)
                {
                    _errors.Add(new Error(stmt.keyword, ErrorType.InvalidReturnUsage, "Can't use 'return' inside a constructor"));
                }

                Resolve(stmt.value);
            }
            return(null);
        }
예제 #3
0
        public object VisitReturnStmt(ReturnStmt stmt)
        {
            if (_currentFuncType == FunctionType.NONE)
            {
                Lox.Error(stmt.Keyword, "Cannot return from top-level code.");
            }

            if (stmt.Value != null)
            {
                if (_currentFuncType == FunctionType.INITIALIZER)
                {
                    Lox.Error(stmt.Keyword, "Cannot return a value from an initializer.");
                }

                Resolve(stmt.Value);
            }

            return(null);
        }
예제 #4
0
 public object VisitReturnStmt(ReturnStmt stmt)
 {
     throw new Return(stmt.Value != null
         ? Evaluate(stmt.Value)
         : null);
 }
예제 #5
0
파일: AST_Printer.cs 프로젝트: sirgru/CsLox
 public string Visit_ReturnStmt(ReturnStmt stmt)
 {
     return(Parenthesize("Return", stmt.value));
 }