public static Grammar translate ( Rule [ ] rules , StringArrayList symbolTable ) throws ActionException { int i ; Ebnf builder ; Grammar tmp ; Grammar buffer ; int firstHelper ; int lastHelper ; firstHelper = symbolTable . size ( ) ; buffer = new Grammar ( rules [ 0 ] . getLeft ( ) , symbolTable ) ; builder = new Ebnf ( firstHelper ) ; for ( i = 0 ; i < rules . length ; i ++ ) { tmp = ( Grammar ) rules [ i ] . getRight ( ) . visit ( builder ) ; buffer . addProduction ( new int [ ] { rules [ i ] . getLeft ( ) , tmp . getStart ( ) } ) ; buffer . addProductions ( tmp ) ; buffer . expandSymbol ( tmp . getStart ( ) ) ; buffer . removeProductions ( tmp . getStart ( ) ) ; } lastHelper = builder . getHelper ( ) - 1 ; buffer . removeDuplicateSymbols ( firstHelper , lastHelper ) ; buffer . removeDuplicateRules ( ) ; buffer . packSymbols ( firstHelper , lastHelper + 1 ) ; return buffer ; }
helper symbols are added without gaps starting with freeHelper .