public Term parseOperators ( Term [ ] terms ) throws SourceCodeException { // Initialize the parsers state. stack . offer ( 0 ) ; state = 0 ; position = 0 ; nextTerm = null ; // Consume the terms from left to right. for ( position = 0 ; position <= terms . length ; ) { Symbol nextSymbol ; // Decide what the next symbol to parse is; candidate op, term or final. if ( position < terms . length ) { nextTerm = terms [ position ] ; if ( nextTerm instanceof CandidateOpSymbol ) { nextSymbol = Symbol . Op ; } else { nextSymbol = Symbol . Term ; } } else { nextSymbol = Symbol . Final ; } // Look in the action table to find the action associated with the current symbol and state. Action action = actionTable [ state ] [ nextSymbol . ordinal ( ) ] ; // Apply the action. action . apply ( ) ; } return ( Functor ) outputStack . poll ( ) ; }
Parses a flat list of terms which are literals variables functors or operators into a tree in such a way that the operators associativity and precendence is obeyed .