MAXScript Compiler and Interpreter

The MAXScript engine executes MAXScript code using the following steps:

The following code snippet demonstrates these steps:

Value* file_in(CharStream* source, int quiet)
{
   // declare a thread-safe local variable called vl with three fields
   three_typed_value_locals(Parser* parser, Value* code, Value* result);
 
   CharStream* out = thread_local(current_stdout);  
  
   vl.parser = new Parser (out);  
   if (!quiet)  
     source->log_to(out);  
  
   // loop through file compiling and evaluating all expressions  
   try  
   {  
     source->flush_whitespace();  
     while (!source->at_eos())  
     {  
       vl.code = vl.parser->compile(source);  
       vl.result = vl.code->eval();
  
       if (!quiet)  
         vl.result->print();  
  
        source->flush_whitespace();  
     }  
     source->close();  
   }  
   catch (...)  
   {  
     // catch any errors and tell what file we are in if any  
     out->puts("Error occurred during fileIn: ");  
     source->sprin1(out);  
     out->puts("\n");  
     throw;  
   }  
  
   //return last expression in stream as result
   if (vl.result == NULL)
   vl.result = &ok;  
   return_value(vl.result);  
}