Run interactively. (printing prompts, etc.)
()
| 431 | Run interactively. (printing prompts, etc.) |
| 432 | */ |
| 433 | public void run() |
| 434 | { |
| 435 | if(evalOnly) |
| 436 | throw new RuntimeException("bsh Interpreter: No stream"); |
| 437 | |
| 438 | /* |
| 439 | We'll print our banner using eval(String) in order to |
| 440 | exercise the parser and get the basic expression classes loaded... |
| 441 | This ameliorates the delay after typing the first statement. |
| 442 | */ |
| 443 | if ( interactive ) |
| 444 | try { |
| 445 | eval("printBanner();"); |
| 446 | } catch ( EvalError e ) { |
| 447 | println( |
| 448 | "BeanShell " + VERSION + " - https://github.com/beanshell/beanshell"); |
| 449 | } |
| 450 | |
| 451 | // init the callstack. |
| 452 | CallStack callstack = new CallStack( globalNameSpace ); |
| 453 | |
| 454 | SimpleNode node = null; |
| 455 | boolean eof = false; |
| 456 | while( !eof ) |
| 457 | { |
| 458 | try |
| 459 | { |
| 460 | // try to sync up the console |
| 461 | System.out.flush(); |
| 462 | System.err.flush(); |
| 463 | Thread.yield(); // this helps a little |
| 464 | |
| 465 | if ( interactive ) |
| 466 | print( getBshPrompt() ); |
| 467 | |
| 468 | eof = Line(); |
| 469 | |
| 470 | if( get_jjtree().nodeArity() > 0 ) // number of child nodes |
| 471 | { |
| 472 | if( node != null ) |
| 473 | node.lastToken.next = null; // prevent OutOfMemoryError |
| 474 | |
| 475 | node = (SimpleNode)(get_jjtree().rootNode()); |
| 476 | |
| 477 | if(DEBUG) |
| 478 | node.dump(">"); |
| 479 | |
| 480 | Object ret = node.eval( callstack, this ); |
| 481 | |
| 482 | node.lastToken.next = null; // prevent OutOfMemoryError |
| 483 | |
| 484 | // sanity check during development |
| 485 | if ( callstack.depth() > 1 ) |
| 486 | throw new InterpreterError( |
| 487 | "Callstack growing: "+callstack); |
| 488 | |
| 489 | if(ret instanceof ReturnControl) |
| 490 | ret = ((ReturnControl)ret).value; |