public Sequence compile ( String equation , boolean assignment , boolean debug ) { functions . setManagerTemp ( managerTemp ) ; Sequence sequence = new Sequence ( ) ; TokenList tokens = extractTokens ( equation , managerTemp ) ; if ( tokens . size ( ) < 3 ) throw new RuntimeException ( "Too few tokens" ) ; TokenList . Token t0 = tokens . getFirst ( ) ; if ( t0 . word != null && t0 . word . compareToIgnoreCase ( "macro" ) == 0 ) { parseMacro ( tokens , sequence ) ; } else { insertFunctionsAndVariables ( tokens ) ; insertMacros ( tokens ) ; if ( debug ) { System . out . println ( "Parsed tokens:\n------------" ) ; tokens . print ( ) ; System . out . println ( ) ; } // Get the results variable if ( t0 . getType ( ) != Type . VARIABLE && t0 . getType ( ) != Type . WORD ) { compileTokens ( sequence , tokens ) ; // If there's no output then this is acceptable, otherwise it's assumed to be a bug // If there's no output then a configuration was changed Variable variable = tokens . getFirst ( ) . getVariable ( ) ; if ( variable != null ) { if ( assignment ) throw new IllegalArgumentException ( "No assignment to an output variable could be found. Found " + t0 ) ; else { sequence . output = variable ; // set this to be the output for print() } } } else { compileAssignment ( sequence , tokens , t0 ) ; } if ( debug ) { System . out . println ( "Operations:\n------------" ) ; for ( int i = 0 ; i < sequence . operations . size ( ) ; i ++ ) { System . out . println ( sequence . operations . get ( i ) . name ( ) ) ; } } } return sequence ; }
Parses the equation and compiles it into a sequence which can be executed later on