Esempio n. 1
0
        public object visitReturnStmt(Stmt.Return stmt)
        {
            object value = stmt.value == null ? null : Evaluate(stmt.value);

            throw new ReturnException {
                      value = value
            };
        }
Esempio n. 2
0
 object Stmt.IVisitor <object> .visitReturnStmt(Stmt.Return stmt)
 {
     if (currentFunction == FunctionType.NONE)
     {
         Lox.ReportError(stmt.keyword, "Can only return from functions or methods.");
     }
     else if (stmt.value != null)
     {
         if (currentFunction == FunctionType.INITIALIZER)
         {
             Lox.ReportError(stmt.keyword, "Cannot return value from an initializer.");
         }
         else
         {
             Resolve(stmt.value);
         }
     }
     return(null);
 }