protected void parseBracketCreateMatrix ( TokenList tokens , Sequence sequence ) { List < TokenList . Token > left = new ArrayList < TokenList . Token > ( ) ; TokenList . Token t = tokens . getFirst ( ) ; while ( t != null ) { TokenList . Token next = t . next ; if ( t . getSymbol ( ) == Symbol . BRACKET_LEFT ) { left . add ( t ) ; } else if ( t . getSymbol ( ) == Symbol . BRACKET_RIGHT ) { if ( left . isEmpty ( ) ) throw new RuntimeException ( "No matching left bracket for right" ) ; TokenList . Token start = left . remove ( left . size ( ) - 1 ) ; // Compute everything inside the [ ], this will leave a // series of variables and semi-colons hopefully TokenList bracketLet = tokens . extractSubList ( start . next , t . previous ) ; parseBlockNoParentheses ( bracketLet , sequence , true ) ; MatrixConstructor constructor = constructMatrix ( bracketLet ) ; // define the matrix op and inject into token list Operation . Info info = Operation . matrixConstructor ( constructor ) ; sequence . addOperation ( info . op ) ; tokens . insert ( start . previous , new TokenList . Token ( info . output ) ) ; // remove the brackets tokens . remove ( start ) ; tokens . remove ( t ) ; } t = next ; } if ( ! left . isEmpty ( ) ) throw new RuntimeException ( "Dangling [" ) ; }
Searches for brackets which are only used to construct new matrices by concatenating 1 or more matrices together