public final ANTLRv3TreeFilter.terminal_return terminal() throws RecognitionException {
        ANTLRv3TreeFilter.terminal_return retval = new ANTLRv3TreeFilter.terminal_return();
        retval.start = input.LT(1);

        CommonTree TOKEN_REF16=null;
        CommonTree STRING_LITERAL17=null;

        try {
            // back-end/koopa/trees/antlr/filter/generator/ANTLRv3TreeFilter.g:364:3: ( CHAR_LITERAL -> {%{\"[>CHAR_LITERAL<]\"}} | TOKEN_REF -> token(id=$TOKEN_REFscop=scope) | STRING_LITERAL -> literal(value=val) | ^( TOKEN_REF ARG_ACTION ) -> {%{\"[>TOKEN_REF ARG_ACTION<]\"}} | '.' -> {%{\"[>.<]\"}})
            int alt39=5;
            switch ( input.LA(1) ) {
            case CHAR_LITERAL:
                {
                alt39=1;
                }
                break;
            case TOKEN_REF:
                {
                int LA39_2 = input.LA(2);

                if ( (LA39_2==DOWN) ) {
                    alt39=4;
                }
                else if ( (LA39_2==UP||(LA39_2>=BLOCK && LA39_2<=SYNPRED)||LA39_2==CHAR_RANGE||LA39_2==EOA||(LA39_2>=SEMPRED && LA39_2<=SYN_SEMPRED)||(LA39_2>=TREE_BEGIN && LA39_2<=BANG)||(LA39_2>=TOKEN_REF && LA39_2<=ACTION)||LA39_2==RULE_REF||LA39_2==71||LA39_2==87||LA39_2==89||LA39_2==92) ) {
                    alt39=2;
                }
                else {
                    NoViableAltException nvae =
                        new NoViableAltException("", 39, 2, input);

                    throw nvae;
                }
                }
                break;
            case STRING_LITERAL:
                {
                alt39=3;
                }
                break;
            case 92:
                {
                alt39=5;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 39, 0, input);

                throw nvae;
            }

            switch (alt39) {
                case 1 :
                    // back-end/koopa/trees/antlr/filter/generator/ANTLRv3TreeFilter.g:364:5: CHAR_LITERAL
                    {
                    match(input,CHAR_LITERAL,FOLLOW_CHAR_LITERAL_in_terminal1882); 


                    // TEMPLATE REWRITE
                    // 366:5: -> {%{\"[>CHAR_LITERAL<]\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"[>CHAR_LITERAL<]");
                    }


                    }
                    break;
                case 2 :
                    // back-end/koopa/trees/antlr/filter/generator/ANTLRv3TreeFilter.g:368:5: TOKEN_REF
                    {
                    TOKEN_REF16=(CommonTree)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal1898); 


                    // TEMPLATE REWRITE
                    // 370:5: -> token(id=$TOKEN_REFscop=scope)
                    {
                        retval.st = templateLib.getInstanceOf("token",
                      new STAttrMap().put("id", TOKEN_REF16).put("scop", scope));
                    }


                    }
                    break;
                case 3 :
                    // back-end/koopa/trees/antlr/filter/generator/ANTLRv3TreeFilter.g:375:5: STRING_LITERAL
                    {
                    STRING_LITERAL17=(CommonTree)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal1948); 
                     String val = (STRING_LITERAL17!=null?STRING_LITERAL17.getText():null);
                          val = val.substring(1, val.length() - 1);
                        


                    // TEMPLATE REWRITE
                    // 381:5: -> literal(value=val)
                    {
                        retval.st = templateLib.getInstanceOf("literal",
                      new STAttrMap().put("value", val));
                    }


                    }
                    break;
                case 4 :
                    // back-end/koopa/trees/antlr/filter/generator/ANTLRv3TreeFilter.g:385:5: ^( TOKEN_REF ARG_ACTION )
                    {
                    match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal1992); 

                    match(input, Token.DOWN, null); 
                    match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_terminal1994); 

                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 387:5: -> {%{\"[>TOKEN_REF ARG_ACTION<]\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"[>TOKEN_REF ARG_ACTION<]");
                    }


                    }
                    break;
                case 5 :
                    // back-end/koopa/trees/antlr/filter/generator/ANTLRv3TreeFilter.g:389:5: '.'
                    {
                    match(input,92,FOLLOW_92_in_terminal2011); 


                    // TEMPLATE REWRITE
                    // 391:5: -> {%{\"[>.<]\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"[>.<]");
                    }


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }