/** \file
 *  This C source file was generated by $ANTLR version 3.2 debian-5
 *
 *     -  From the grammar source file : DAAP.g
 *     -                            On : 2011-09-11 16:17:21
 *     -                for the parser : DAAPParserParser *
 * Editing it, at least manually, is not wise. 
 *
 * C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws.
 *
 *
*/
// [The "BSD licence"]
// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
// http://www.temporal-wave.com
// http://www.linkedin.com/in/jimidle
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
// 3. The name of the author may not be used to endorse or promote products
//    derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/* -----------------------------------------
 * Include the ANTLR3 generated header file.
 */
#include    "DAAPParser.h"
/* ----------------------------------------- */





/* MACROS that hide the C interface implementations from the
 * generated code, which makes it a little more understandable to the human eye.
 * I am very much against using C pre-processor macros for function calls and bits
 * of code as you cannot see what is happening when single stepping in debuggers
 * and so on. The exception (in my book at least) is for generated code, where you are
 * not maintaining it, but may wish to read and understand it. If you single step it, you know that input()
 * hides some indirect calls, but is always referring to the input stream. This is
 * probably more readable than ctx->input->istream->input(snarfle0->blarg) and allows me to rejig
 * the runtime interfaces without changing the generated code too often, without
 * confusing the reader of the generated output, who may not wish to know the gory
 * details of the interface inheritance.
 */
 
#define		CTX	ctx

/* Aids in accessing scopes for grammar programmers
 */
#undef	SCOPE_TYPE
#undef	SCOPE_STACK
#undef	SCOPE_TOP
#define	SCOPE_TYPE(scope)   pDAAPParser_##scope##_SCOPE
#define SCOPE_STACK(scope)  pDAAPParser_##scope##Stack
#define	SCOPE_TOP(scope)    ctx->pDAAPParser_##scope##Top
#define	SCOPE_SIZE(scope)		ctx->pDAAPParser_##scope##Stack_limit
#define SCOPE_INSTANCE(scope, i)	(ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i))

/* Macros for accessing things in the parser
 */
 
#undef	    PARSER		    
#undef	    RECOGNIZER		    
#undef	    HAVEPARSEDRULE
#undef		MEMOIZE
#undef	    INPUT
#undef	    STRSTREAM
#undef	    HASEXCEPTION
#undef	    EXCEPTION
#undef	    MATCHT
#undef	    MATCHANYT
#undef	    FOLLOWSTACK
#undef	    FOLLOWPUSH
#undef	    FOLLOWPOP
#undef	    PRECOVER
#undef	    PREPORTERROR
#undef	    LA
#undef	    LT
#undef	    CONSTRUCTEX
#undef	    CONSUME
#undef	    MARK
#undef	    REWIND
#undef	    REWINDLAST
#undef	    PERRORRECOVERY
#undef	    HASFAILED
#undef	    FAILEDFLAG
#undef	    RECOVERFROMMISMATCHEDSET
#undef	    RECOVERFROMMISMATCHEDELEMENT
#undef		INDEX
#undef      ADAPTOR
#undef		SEEK
#undef	    RULEMEMO		    
#undef		DBG

#define	    PARSER							ctx->pParser  
#define	    RECOGNIZER						PARSER->rec
#define		PSRSTATE						RECOGNIZER->state
#define	    HAVEPARSEDRULE(r)				RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)
#define		MEMOIZE(ri,si)					RECOGNIZER->memoize(RECOGNIZER, ri, si)
#define	    INPUT							PARSER->tstream
#define	    STRSTREAM						INPUT
#define		ISTREAM							INPUT->istream
#define		INDEX()							ISTREAM->index(INPUT->istream)
#define	    HASEXCEPTION()					(PSRSTATE->error == ANTLR3_TRUE)
#define	    EXCEPTION						PSRSTATE->exception
#define	    MATCHT(t, fs)					RECOGNIZER->match(RECOGNIZER, t, fs)
#define	    MATCHANYT()						RECOGNIZER->matchAny(RECOGNIZER)
#define	    FOLLOWSTACK					    PSRSTATE->following
#define	    FOLLOWPUSH(x)					FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL)
#define	    FOLLOWPOP()						FOLLOWSTACK->pop(FOLLOWSTACK)
#define	    PRECOVER()						RECOGNIZER->recover(RECOGNIZER)
#define	    PREPORTERROR()					RECOGNIZER->reportError(RECOGNIZER)
#define	    LA(n)							INPUT->istream->_LA(ISTREAM, n)
#define	    LT(n)							INPUT->_LT(INPUT, n)
#define	    CONSTRUCTEX()					RECOGNIZER->exConstruct(RECOGNIZER)
#define	    CONSUME()						ISTREAM->consume(ISTREAM)
#define	    MARK()							ISTREAM->mark(ISTREAM)
#define	    REWIND(m)						ISTREAM->rewind(ISTREAM, m)
#define	    REWINDLAST()					ISTREAM->rewindLast(ISTREAM)
#define		SEEK(n)							ISTREAM->seek(ISTREAM, n)
#define	    PERRORRECOVERY					PSRSTATE->errorRecovery
#define	    FAILEDFLAG						PSRSTATE->failed
#define	    HASFAILED()						(FAILEDFLAG == ANTLR3_TRUE)
#define	    BACKTRACKING					PSRSTATE->backtracking
#define	    RECOVERFROMMISMATCHEDSET(s)		RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s)
#define	    RECOVERFROMMISMATCHEDELEMENT(e)	RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s)
#define     ADAPTOR                         ctx->adaptor
#define		RULEMEMO						PSRSTATE->ruleMemo
#define		DBG								RECOGNIZER->debugger

#define		TOKTEXT(tok, txt)				tok, (pANTLR3_UINT8)txt

/* The 4 tokens defined below may well clash with your own #defines or token types. If so
 * then for the present you must use different names for your defines as these are hard coded
 * in the code generator. It would be better not to use such names internally, and maybe
 * we can change this in a forthcoming release. I deliberately do not #undef these
 * here as this will at least give you a redefined error somewhere if they clash.
 */
#define	    UP	    ANTLR3_TOKEN_UP
#define	    DOWN    ANTLR3_TOKEN_DOWN
#define	    EOR	    ANTLR3_TOKEN_EOR
#define	    INVALID ANTLR3_TOKEN_INVALID


/* =============================================================================
 * Functions to create and destroy scopes. First come the rule scopes, followed
 * by the global declared scopes.
 */



/* ============================================================================= */

/* =============================================================================
 * Start of recognizer
 */



/** \brief Table of all token names in symbolic order, mainly used for
 *         error reporting.
 */
pANTLR3_UINT8   DAAPParserTokenNames[8+4]
     = {
        (pANTLR3_UINT8) "<invalid>",       /* String to print to indicate an invalid token */
        (pANTLR3_UINT8) "<EOR>",
        (pANTLR3_UINT8) "<DOWN>", 
        (pANTLR3_UINT8) "<UP>", 
        (pANTLR3_UINT8) "NEWLINE",
        (pANTLR3_UINT8) "OPOR",
        (pANTLR3_UINT8) "OPAND",
        (pANTLR3_UINT8) "LPAR",
        (pANTLR3_UINT8) "RPAR",
        (pANTLR3_UINT8) "STR",
        (pANTLR3_UINT8) "QUOTE",
        (pANTLR3_UINT8) "ESCAPED"
       };

        

// Forward declare the locally static matching functions we have generated.
//
static DAAPParser_query_return	query    (pDAAPParser ctx);
static DAAPParser_expr_return	expr    (pDAAPParser ctx);
static DAAPParser_aexpr_return	aexpr    (pDAAPParser ctx);
static DAAPParser_crit_return	crit    (pDAAPParser ctx);
static void	DAAPParserFree(pDAAPParser ctx);
/* For use in tree output where we are accumulating rule labels via label += ruleRef
 * we need a function that knows how to free a return scope when the list is destroyed. 
 * We cannot just use ANTLR3_FREE because in debug tracking mode, this is a macro.
 */
static	void ANTLR3_CDECL freeScope(void * scope)
{
    ANTLR3_FREE(scope);
}

/** \brief Name of the grammar file that generated this code
 */
static const char fileName[] = "DAAP.g";

/** \brief Return the name of the grammar file that generated this code.
 */
static const char * getGrammarFileName()
{
	return fileName;
}
/** \brief Create a new DAAPParser parser and return a context for it.
 *
 * \param[in] instream Pointer to an input stream interface.
 *
 * \return Pointer to new parser context upon success.
 */
ANTLR3_API pDAAPParser
DAAPParserNew   (pANTLR3_COMMON_TOKEN_STREAM instream)
{
	// See if we can create a new parser with the standard constructor
	//
	return DAAPParserNewSSD(instream, NULL);
}

/** \brief Create a new DAAPParser parser and return a context for it.
 *
 * \param[in] instream Pointer to an input stream interface.
 *
 * \return Pointer to new parser context upon success.
 */
ANTLR3_API pDAAPParser
DAAPParserNewSSD   (pANTLR3_COMMON_TOKEN_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state)
{
    pDAAPParser ctx;	    /* Context structure we will build and return   */
    
    ctx	= (pDAAPParser) ANTLR3_CALLOC(1, sizeof(DAAPParser));
    
    if	(ctx == NULL)
    {
		// Failed to allocate memory for parser context
		//
        return  NULL;
    }
    
    /* -------------------------------------------------------------------
     * Memory for basic structure is allocated, now to fill in
     * the base ANTLR3 structures. We initialize the function pointers
     * for the standard ANTLR3 parser function set, but upon return
     * from here, the programmer may set the pointers to provide custom
     * implementations of each function. 
     *
     * We don't use the macros defined in DAAPParser.h here, in order that you can get a sense
     * of what goes where.
     */

    /* Create a base parser/recognizer, using the supplied token stream
     */
    ctx->pParser	    = antlr3ParserNewStream(ANTLR3_SIZE_HINT, instream->tstream, state);
    /* Install the implementation of our DAAPParser interface
     */
    ctx->query	= query;
    ctx->expr	= expr;
    ctx->aexpr	= aexpr;
    ctx->crit	= crit;
    ctx->free			= DAAPParserFree;
    ctx->getGrammarFileName	= getGrammarFileName;
    
    /* Install the scope pushing methods.
     */
    ADAPTOR	= ANTLR3_TREE_ADAPTORNew(instream->tstream->tokenSource->strFactory);
    ctx->vectors	= antlr3VectorFactoryNew(0);
    

	
    /* Install the token table
     */
    PSRSTATE->tokenNames   = DAAPParserTokenNames;
    
    
    /* Return the newly built parser to the caller
     */
    return  ctx;
}

/** Free the parser resources
 */
 static void
 DAAPParserFree(pDAAPParser ctx)
 {
    /* Free any scope memory
     */
    
    ctx->vectors->close(ctx->vectors);
    /* We created the adaptor so we must free it
     */
    ADAPTOR->free(ADAPTOR);
	// Free this parser
	//
    ctx->pParser->free(ctx->pParser);
    ANTLR3_FREE(ctx);

    /* Everything is released, so we can return
     */
    return;
 }
 
/** Return token names used by this parser
 *
 * The returned pointer is used as an index into the token names table (using the token 
 * number as the index).
 * 
 * \return Pointer to first char * in the table.
 */
static pANTLR3_UINT8    *getTokenNames() 
{
        return DAAPParserTokenNames; 
}

    
/* Declare the bitsets
 */

/** Bitset defining follow set for error recovery in rule state: FOLLOW_expr_in_query42  */
static	ANTLR3_BITWORD FOLLOW_expr_in_query42_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000010) };
static  ANTLR3_BITSET_LIST FOLLOW_expr_in_query42	= { FOLLOW_expr_in_query42_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_NEWLINE_in_query44  */
static	ANTLR3_BITWORD FOLLOW_NEWLINE_in_query44_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000000) };
static  ANTLR3_BITSET_LIST FOLLOW_NEWLINE_in_query44	= { FOLLOW_NEWLINE_in_query44_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_EOF_in_query47  */
static	ANTLR3_BITWORD FOLLOW_EOF_in_query47_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000002) };
static  ANTLR3_BITSET_LIST FOLLOW_EOF_in_query47	= { FOLLOW_EOF_in_query47_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_aexpr_in_expr62  */
static	ANTLR3_BITWORD FOLLOW_aexpr_in_expr62_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000022) };
static  ANTLR3_BITSET_LIST FOLLOW_aexpr_in_expr62	= { FOLLOW_aexpr_in_expr62_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_OPOR_in_expr65  */
static	ANTLR3_BITWORD FOLLOW_OPOR_in_expr65_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000280) };
static  ANTLR3_BITSET_LIST FOLLOW_OPOR_in_expr65	= { FOLLOW_OPOR_in_expr65_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_aexpr_in_expr68  */
static	ANTLR3_BITWORD FOLLOW_aexpr_in_expr68_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000022) };
static  ANTLR3_BITSET_LIST FOLLOW_aexpr_in_expr68	= { FOLLOW_aexpr_in_expr68_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_crit_in_aexpr80  */
static	ANTLR3_BITWORD FOLLOW_crit_in_aexpr80_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000042) };
static  ANTLR3_BITSET_LIST FOLLOW_crit_in_aexpr80	= { FOLLOW_crit_in_aexpr80_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_OPAND_in_aexpr83  */
static	ANTLR3_BITWORD FOLLOW_OPAND_in_aexpr83_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000280) };
static  ANTLR3_BITSET_LIST FOLLOW_OPAND_in_aexpr83	= { FOLLOW_OPAND_in_aexpr83_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_crit_in_aexpr86  */
static	ANTLR3_BITWORD FOLLOW_crit_in_aexpr86_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000042) };
static  ANTLR3_BITSET_LIST FOLLOW_crit_in_aexpr86	= { FOLLOW_crit_in_aexpr86_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_LPAR_in_crit98  */
static	ANTLR3_BITWORD FOLLOW_LPAR_in_crit98_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000280) };
static  ANTLR3_BITSET_LIST FOLLOW_LPAR_in_crit98	= { FOLLOW_LPAR_in_crit98_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_expr_in_crit100  */
static	ANTLR3_BITWORD FOLLOW_expr_in_crit100_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000100) };
static  ANTLR3_BITSET_LIST FOLLOW_expr_in_crit100	= { FOLLOW_expr_in_crit100_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_RPAR_in_crit102  */
static	ANTLR3_BITWORD FOLLOW_RPAR_in_crit102_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000002) };
static  ANTLR3_BITSET_LIST FOLLOW_RPAR_in_crit102	= { FOLLOW_RPAR_in_crit102_bits, 1	};
/** Bitset defining follow set for error recovery in rule state: FOLLOW_STR_in_crit112  */
static	ANTLR3_BITWORD FOLLOW_STR_in_crit112_bits[]	= { ANTLR3_UINT64_LIT(0x0000000000000002) };
static  ANTLR3_BITSET_LIST FOLLOW_STR_in_crit112	= { FOLLOW_STR_in_crit112_bits, 1	};
     

 
 
/* ==============================================
 * Parsing rules
 */
/** 
 * $ANTLR start query
 * DAAP.g:27:1: query : expr ( NEWLINE )? EOF -> expr ;
 */
static DAAPParser_query_return
query(pDAAPParser ctx)
{   
    DAAPParser_query_return retval;

    pANTLR3_BASE_TREE root_0;

    pANTLR3_COMMON_TOKEN    NEWLINE2;
    pANTLR3_COMMON_TOKEN    EOF3;
    DAAPParser_expr_return expr1;
    #undef	RETURN_TYPE_expr1
    #define	RETURN_TYPE_expr1 DAAPParser_expr_return

    pANTLR3_BASE_TREE NEWLINE2_tree;
    pANTLR3_BASE_TREE EOF3_tree;
    pANTLR3_REWRITE_RULE_TOKEN_STREAM stream_NEWLINE;
    pANTLR3_REWRITE_RULE_TOKEN_STREAM stream_EOF;
    pANTLR3_REWRITE_RULE_SUBTREE_STREAM stream_expr;
    /* Initialize rule variables
     */


    root_0 = NULL;

    NEWLINE2       = NULL;
    EOF3       = NULL;
    expr1.tree = NULL;

    retval.start = LT(1); retval.stop = retval.start;

    NEWLINE2_tree   = NULL;
    EOF3_tree   = NULL;

    stream_NEWLINE   = NULL;
    #define CREATE_stream_NEWLINE  if (stream_NEWLINE == NULL) {stream_NEWLINE = antlr3RewriteRuleTOKENStreamNewAE(ADAPTOR, RECOGNIZER, (pANTLR3_UINT8)"token NEWLINE"); } 
    stream_EOF   = NULL;
    #define CREATE_stream_EOF  if (stream_EOF == NULL) {stream_EOF = antlr3RewriteRuleTOKENStreamNewAE(ADAPTOR, RECOGNIZER, (pANTLR3_UINT8)"token EOF"); } 
    stream_expr   = NULL;
    #define CREATE_stream_expr  if (stream_expr == NULL) {stream_expr = antlr3RewriteRuleSubtreeStreamNewAE(ADAPTOR, RECOGNIZER, (pANTLR3_UINT8)"rule expr"); }

    retval.tree  = NULL;
    {
        // DAAP.g:27:7: ( expr ( NEWLINE )? EOF -> expr )
        // DAAP.g:27:9: expr ( NEWLINE )? EOF
        {
            FOLLOWPUSH(FOLLOW_expr_in_query42);
            expr1=expr(ctx);

            FOLLOWPOP();
            if  (HASEXCEPTION())
            {
                goto rulequeryEx;
            }

            CREATE_stream_expr; stream_expr->add(stream_expr, expr1.tree, NULL);

            // DAAP.g:27:14: ( NEWLINE )?
            {
                int alt1=2;
                switch ( LA(1) ) 
                {
                    case NEWLINE:
                    	{
                    		alt1=1;
                    	}
                        break;
                }

                switch (alt1) 
                {
            	case 1:
            	    // DAAP.g:27:14: NEWLINE
            	    {
            	        NEWLINE2 = (pANTLR3_COMMON_TOKEN) MATCHT(NEWLINE, &FOLLOW_NEWLINE_in_query44); 
            	        if  (HASEXCEPTION())
            	        {
            	            goto rulequeryEx;
            	        }
            	         
            	        CREATE_stream_NEWLINE; stream_NEWLINE->add(stream_NEWLINE, NEWLINE2, NULL);


            	    }
            	    break;

                }
            }
            EOF3 = (pANTLR3_COMMON_TOKEN) MATCHT(EOF, &FOLLOW_EOF_in_query47); 
            if  (HASEXCEPTION())
            {
                goto rulequeryEx;
            }
             
            CREATE_stream_EOF; stream_EOF->add(stream_EOF, EOF3, NULL);


             
            /* AST REWRITE
             * elements          : expr
             * token labels      : 
             * rule labels       : retval
             * token list labels : 
             * rule list labels  : 
             */
            {
            	pANTLR3_REWRITE_RULE_SUBTREE_STREAM stream_retval;

            	stream_retval=antlr3RewriteRuleSubtreeStreamNewAEE(ADAPTOR,  RECOGNIZER, (pANTLR3_UINT8)"token retval", retval.tree != NULL ? retval.tree : NULL);

            	root_0			    = (pANTLR3_BASE_TREE)(ADAPTOR->nilNode(ADAPTOR));
            	retval.tree    = root_0;
            	// 27:27: -> expr
            	{
            	    ADAPTOR->addChild(ADAPTOR, root_0, stream_expr == NULL ? NULL : stream_expr->nextTree(stream_expr));

            	}

            	retval.tree = root_0; // set result root
            	if (stream_retval != NULL) stream_retval->free(stream_retval);


            }
        }

    }
    

    // This is where rules clean up and exit
    //
    goto rulequeryEx; /* Prevent compiler warnings */
    rulequeryEx: ;
    retval.stop = LT(-1);

    	retval.stop = LT(-1);
    	retval.tree = (pANTLR3_BASE_TREE)(ADAPTOR->rulePostProcessing(ADAPTOR, root_0));
    	ADAPTOR->setTokenBoundaries(ADAPTOR, retval.tree, retval.start, retval.stop);
        if (stream_NEWLINE != NULL) stream_NEWLINE->free(stream_NEWLINE);
        if (stream_EOF != NULL) stream_EOF->free(stream_EOF);
        if (stream_expr != NULL) stream_expr->free(stream_expr);

            if (HASEXCEPTION())
            {
                PREPORTERROR();
                PRECOVER();
                retval.tree = (pANTLR3_BASE_TREE)(ADAPTOR->errorNode(ADAPTOR, INPUT, retval.start, LT(-1), EXCEPTION));
            }


    return retval;
}
/* $ANTLR end query */

/** 
 * $ANTLR start expr
 * DAAP.g:30:1: expr : aexpr ( OPOR aexpr )* ;
 */
static DAAPParser_expr_return
expr(pDAAPParser ctx)
{   
    DAAPParser_expr_return retval;

    pANTLR3_BASE_TREE root_0;

    pANTLR3_COMMON_TOKEN    OPOR5;
    DAAPParser_aexpr_return aexpr4;
    #undef	RETURN_TYPE_aexpr4
    #define	RETURN_TYPE_aexpr4 DAAPParser_aexpr_return

    DAAPParser_aexpr_return aexpr6;
    #undef	RETURN_TYPE_aexpr6
    #define	RETURN_TYPE_aexpr6 DAAPParser_aexpr_return

    pANTLR3_BASE_TREE OPOR5_tree;

    /* Initialize rule variables
     */


    root_0 = NULL;

    OPOR5       = NULL;
    aexpr4.tree = NULL;

    aexpr6.tree = NULL;

    retval.start = LT(1); retval.stop = retval.start;

    OPOR5_tree   = NULL;


    retval.tree  = NULL;
    {
        // DAAP.g:30:6: ( aexpr ( OPOR aexpr )* )
        // DAAP.g:30:8: aexpr ( OPOR aexpr )*
        {
            root_0 = (pANTLR3_BASE_TREE)(ADAPTOR->nilNode(ADAPTOR));

            FOLLOWPUSH(FOLLOW_aexpr_in_expr62);
            aexpr4=aexpr(ctx);

            FOLLOWPOP();
            if  (HASEXCEPTION())
            {
                goto ruleexprEx;
            }

            ADAPTOR->addChild(ADAPTOR, root_0, aexpr4.tree);

            // DAAP.g:30:14: ( OPOR aexpr )*

            for (;;)
            {
                int alt2=2;
                switch ( LA(1) ) 
                {
                case OPOR:
                	{
                		alt2=1;
                	}
                    break;

                }

                switch (alt2) 
                {
            	case 1:
            	    // DAAP.g:30:15: OPOR aexpr
            	    {
            	        OPOR5 = (pANTLR3_COMMON_TOKEN) MATCHT(OPOR, &FOLLOW_OPOR_in_expr65); 
            	        if  (HASEXCEPTION())
            	        {
            	            goto ruleexprEx;
            	        }

            	        OPOR5_tree = (pANTLR3_BASE_TREE)(ADAPTOR->create(ADAPTOR, OPOR5));
            	        root_0 = (pANTLR3_BASE_TREE)(ADAPTOR->becomeRoot(ADAPTOR, OPOR5_tree, root_0));

            	        FOLLOWPUSH(FOLLOW_aexpr_in_expr68);
            	        aexpr6=aexpr(ctx);

            	        FOLLOWPOP();
            	        if  (HASEXCEPTION())
            	        {
            	            goto ruleexprEx;
            	        }

            	        ADAPTOR->addChild(ADAPTOR, root_0, aexpr6.tree);

            	    }
            	    break;

            	default:
            	    goto loop2;	/* break out of the loop */
            	    break;
                }
            }
            loop2: ; /* Jump out to here if this rule does not match */


        }

    }
    

    // This is where rules clean up and exit
    //
    goto ruleexprEx; /* Prevent compiler warnings */
    ruleexprEx: ;
    retval.stop = LT(-1);

    	retval.stop = LT(-1);
    	retval.tree = (pANTLR3_BASE_TREE)(ADAPTOR->rulePostProcessing(ADAPTOR, root_0));
    	ADAPTOR->setTokenBoundaries(ADAPTOR, retval.tree, retval.start, retval.stop);

            if (HASEXCEPTION())
            {
                PREPORTERROR();
                PRECOVER();
                retval.tree = (pANTLR3_BASE_TREE)(ADAPTOR->errorNode(ADAPTOR, INPUT, retval.start, LT(-1), EXCEPTION));
            }


    return retval;
}
/* $ANTLR end expr */

/** 
 * $ANTLR start aexpr
 * DAAP.g:33:1: aexpr : crit ( OPAND crit )* ;
 */
static DAAPParser_aexpr_return
aexpr(pDAAPParser ctx)
{   
    DAAPParser_aexpr_return retval;

    pANTLR3_BASE_TREE root_0;

    pANTLR3_COMMON_TOKEN    OPAND8;
    DAAPParser_crit_return crit7;
    #undef	RETURN_TYPE_crit7
    #define	RETURN_TYPE_crit7 DAAPParser_crit_return

    DAAPParser_crit_return crit9;
    #undef	RETURN_TYPE_crit9
    #define	RETURN_TYPE_crit9 DAAPParser_crit_return

    pANTLR3_BASE_TREE OPAND8_tree;

    /* Initialize rule variables
     */


    root_0 = NULL;

    OPAND8       = NULL;
    crit7.tree = NULL;

    crit9.tree = NULL;

    retval.start = LT(1); retval.stop = retval.start;

    OPAND8_tree   = NULL;


    retval.tree  = NULL;
    {
        // DAAP.g:33:7: ( crit ( OPAND crit )* )
        // DAAP.g:33:9: crit ( OPAND crit )*
        {
            root_0 = (pANTLR3_BASE_TREE)(ADAPTOR->nilNode(ADAPTOR));

            FOLLOWPUSH(FOLLOW_crit_in_aexpr80);
            crit7=crit(ctx);

            FOLLOWPOP();
            if  (HASEXCEPTION())
            {
                goto ruleaexprEx;
            }

            ADAPTOR->addChild(ADAPTOR, root_0, crit7.tree);

            // DAAP.g:33:14: ( OPAND crit )*

            for (;;)
            {
                int alt3=2;
                switch ( LA(1) ) 
                {
                case OPAND:
                	{
                		alt3=1;
                	}
                    break;

                }

                switch (alt3) 
                {
            	case 1:
            	    // DAAP.g:33:15: OPAND crit
            	    {
            	        OPAND8 = (pANTLR3_COMMON_TOKEN) MATCHT(OPAND, &FOLLOW_OPAND_in_aexpr83); 
            	        if  (HASEXCEPTION())
            	        {
            	            goto ruleaexprEx;
            	        }

            	        OPAND8_tree = (pANTLR3_BASE_TREE)(ADAPTOR->create(ADAPTOR, OPAND8));
            	        root_0 = (pANTLR3_BASE_TREE)(ADAPTOR->becomeRoot(ADAPTOR, OPAND8_tree, root_0));

            	        FOLLOWPUSH(FOLLOW_crit_in_aexpr86);
            	        crit9=crit(ctx);

            	        FOLLOWPOP();
            	        if  (HASEXCEPTION())
            	        {
            	            goto ruleaexprEx;
            	        }

            	        ADAPTOR->addChild(ADAPTOR, root_0, crit9.tree);

            	    }
            	    break;

            	default:
            	    goto loop3;	/* break out of the loop */
            	    break;
                }
            }
            loop3: ; /* Jump out to here if this rule does not match */


        }

    }
    

    // This is where rules clean up and exit
    //
    goto ruleaexprEx; /* Prevent compiler warnings */
    ruleaexprEx: ;
    retval.stop = LT(-1);

    	retval.stop = LT(-1);
    	retval.tree = (pANTLR3_BASE_TREE)(ADAPTOR->rulePostProcessing(ADAPTOR, root_0));
    	ADAPTOR->setTokenBoundaries(ADAPTOR, retval.tree, retval.start, retval.stop);

            if (HASEXCEPTION())
            {
                PREPORTERROR();
                PRECOVER();
                retval.tree = (pANTLR3_BASE_TREE)(ADAPTOR->errorNode(ADAPTOR, INPUT, retval.start, LT(-1), EXCEPTION));
            }


    return retval;
}
/* $ANTLR end aexpr */

/** 
 * $ANTLR start crit
 * DAAP.g:36:1: crit : ( LPAR expr RPAR -> expr | STR );
 */
static DAAPParser_crit_return
crit(pDAAPParser ctx)
{   
    DAAPParser_crit_return retval;

    pANTLR3_BASE_TREE root_0;

    pANTLR3_COMMON_TOKEN    LPAR10;
    pANTLR3_COMMON_TOKEN    RPAR12;
    pANTLR3_COMMON_TOKEN    STR13;
    DAAPParser_expr_return expr11;
    #undef	RETURN_TYPE_expr11
    #define	RETURN_TYPE_expr11 DAAPParser_expr_return

    pANTLR3_BASE_TREE LPAR10_tree;
    pANTLR3_BASE_TREE RPAR12_tree;
    pANTLR3_BASE_TREE STR13_tree;
    pANTLR3_REWRITE_RULE_TOKEN_STREAM stream_RPAR;
    pANTLR3_REWRITE_RULE_TOKEN_STREAM stream_LPAR;
    pANTLR3_REWRITE_RULE_SUBTREE_STREAM stream_expr;
    /* Initialize rule variables
     */


    root_0 = NULL;

    LPAR10       = NULL;
    RPAR12       = NULL;
    STR13       = NULL;
    expr11.tree = NULL;

    retval.start = LT(1); retval.stop = retval.start;

    LPAR10_tree   = NULL;
    RPAR12_tree   = NULL;
    STR13_tree   = NULL;

    stream_RPAR   = NULL;
    #define CREATE_stream_RPAR  if (stream_RPAR == NULL) {stream_RPAR = antlr3RewriteRuleTOKENStreamNewAE(ADAPTOR, RECOGNIZER, (pANTLR3_UINT8)"token RPAR"); } 
    stream_LPAR   = NULL;
    #define CREATE_stream_LPAR  if (stream_LPAR == NULL) {stream_LPAR = antlr3RewriteRuleTOKENStreamNewAE(ADAPTOR, RECOGNIZER, (pANTLR3_UINT8)"token LPAR"); } 
    stream_expr   = NULL;
    #define CREATE_stream_expr  if (stream_expr == NULL) {stream_expr = antlr3RewriteRuleSubtreeStreamNewAE(ADAPTOR, RECOGNIZER, (pANTLR3_UINT8)"rule expr"); }

    retval.tree  = NULL;
    {
        {
            //  DAAP.g:36:6: ( LPAR expr RPAR -> expr | STR )
            
            ANTLR3_UINT32 alt4;

            alt4=2;

            switch ( LA(1) ) 
            {
            case LPAR:
            	{
            		alt4=1;
            	}
                break;
            case STR:
            	{
            		alt4=2;
            	}
                break;

            default:
                CONSTRUCTEX();
                EXCEPTION->type         = ANTLR3_NO_VIABLE_ALT_EXCEPTION;
                EXCEPTION->message      = (void *)"";
                EXCEPTION->decisionNum  = 4;
                EXCEPTION->state        = 0;


                goto rulecritEx;
            }

            switch (alt4) 
            {
        	case 1:
        	    // DAAP.g:36:8: LPAR expr RPAR
        	    {
        	        LPAR10 = (pANTLR3_COMMON_TOKEN) MATCHT(LPAR, &FOLLOW_LPAR_in_crit98); 
        	        if  (HASEXCEPTION())
        	        {
        	            goto rulecritEx;
        	        }
        	         
        	        CREATE_stream_LPAR; stream_LPAR->add(stream_LPAR, LPAR10, NULL);

        	        FOLLOWPUSH(FOLLOW_expr_in_crit100);
        	        expr11=expr(ctx);

        	        FOLLOWPOP();
        	        if  (HASEXCEPTION())
        	        {
        	            goto rulecritEx;
        	        }

        	        CREATE_stream_expr; stream_expr->add(stream_expr, expr11.tree, NULL);
        	        RPAR12 = (pANTLR3_COMMON_TOKEN) MATCHT(RPAR, &FOLLOW_RPAR_in_crit102); 
        	        if  (HASEXCEPTION())
        	        {
        	            goto rulecritEx;
        	        }
        	         
        	        CREATE_stream_RPAR; stream_RPAR->add(stream_RPAR, RPAR12, NULL);


        	         
        	        /* AST REWRITE
        	         * elements          : expr
        	         * token labels      : 
        	         * rule labels       : retval
        	         * token list labels : 
        	         * rule list labels  : 
        	         */
        	        {
        	        	pANTLR3_REWRITE_RULE_SUBTREE_STREAM stream_retval;

        	        	stream_retval=antlr3RewriteRuleSubtreeStreamNewAEE(ADAPTOR,  RECOGNIZER, (pANTLR3_UINT8)"token retval", retval.tree != NULL ? retval.tree : NULL);

        	        	root_0			    = (pANTLR3_BASE_TREE)(ADAPTOR->nilNode(ADAPTOR));
        	        	retval.tree    = root_0;
        	        	// 36:24: -> expr
        	        	{
        	        	    ADAPTOR->addChild(ADAPTOR, root_0, stream_expr == NULL ? NULL : stream_expr->nextTree(stream_expr));

        	        	}

        	        	retval.tree = root_0; // set result root
        	        	if (stream_retval != NULL) stream_retval->free(stream_retval);


        	        }
        	    }
        	    break;
        	case 2:
        	    // DAAP.g:37:4: STR
        	    {
        	        root_0 = (pANTLR3_BASE_TREE)(ADAPTOR->nilNode(ADAPTOR));

        	        STR13 = (pANTLR3_COMMON_TOKEN) MATCHT(STR, &FOLLOW_STR_in_crit112); 
        	        if  (HASEXCEPTION())
        	        {
        	            goto rulecritEx;
        	        }

        	        STR13_tree = (pANTLR3_BASE_TREE)(ADAPTOR->create(ADAPTOR, STR13));
        	        ADAPTOR->addChild(ADAPTOR, root_0, STR13_tree);


        	    }
        	    break;

            }
        }
    }
    

    // This is where rules clean up and exit
    //
    goto rulecritEx; /* Prevent compiler warnings */
    rulecritEx: ;
    retval.stop = LT(-1);

    	retval.stop = LT(-1);
    	retval.tree = (pANTLR3_BASE_TREE)(ADAPTOR->rulePostProcessing(ADAPTOR, root_0));
    	ADAPTOR->setTokenBoundaries(ADAPTOR, retval.tree, retval.start, retval.stop);
        if (stream_RPAR != NULL) stream_RPAR->free(stream_RPAR);
        if (stream_LPAR != NULL) stream_LPAR->free(stream_LPAR);
        if (stream_expr != NULL) stream_expr->free(stream_expr);

            if (HASEXCEPTION())
            {
                PREPORTERROR();
                PRECOVER();
                retval.tree = (pANTLR3_BASE_TREE)(ADAPTOR->errorNode(ADAPTOR, INPUT, retval.start, LT(-1), EXCEPTION));
            }


    return retval;
}
/* $ANTLR end crit */
/* End of parsing rules
 * ==============================================
 */

/* ==============================================
 * Syntactic predicates
 */
/* End of syntactic predicates
 * ==============================================
 */

 
 



/* End of code
 * =============================================================================
 */
