/** * \brief * Creates a new ANTLR3 exception structure * * \param[in] exception * One of the ANTLR3_xxx_EXCEPTION indicators such as #ANTLR3_RECOGNITION_EXCEPTION * * \param[in] message * Pointer to message string * * \param[in] freeMessage * Set to ANTLR3_TRUE if the message parameter should be freed by a call to * ANTLR3_FREE() when the exception is destroyed. * * \returns * Pointer to newly initialized exception structure, or an ANTLR3_ERR_xx defined value * upon failure. * * An exception is 'thrown' by a recognizer when input is seen that is not predicted by * the grammar productions or when some other error condition occurs. In C we do not have * the luxury of try and catch blocks, so exceptions are added in the order they occur to * a list in the baserecognizer structure. The last one to be thrown is inserted at the head of * the list and the one currently installed is pointed to by the newly installed exception. * * \remarks * After an exception is created, you may add a pointer to your own structure and a pointer * to a function to free this structure when the exception is destroyed. * * \see * ANTLR3_EXCEPTION */ pANTLR3_EXCEPTION antlr3ExceptionNew(ANTLR3_UINT32 exception, void * name, void * message, ANTLR3_BOOLEAN freeMessage) { pANTLR3_EXCEPTION ex; /* Allocate memory for the structure */ ex = (pANTLR3_EXCEPTION) ANTLR3_CALLOC(1, sizeof(ANTLR3_EXCEPTION)); /* Check for memory allocation */ if (ex == NULL) { return NULL; } ex->name = name; /* Install exception name */ ex->type = exception; /* Install the exception number */ ex->message = message; /* Install message string */ /* Indicate whether the string should be freed if exception is destroyed */ ex->freeMessage = freeMessage; /* Install the API */ ex->print = antlr3ExceptionPrint; ex->freeEx = antlr3ExceptionFree; return ex; }
/** \brief Create a new corpconfParser 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 pcorpconfParser corpconfParserNewSSD (pANTLR3_COMMON_TOKEN_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state) { pcorpconfParser ctx; /* Context structure we will build and return */ ctx = (pcorpconfParser) ANTLR3_CALLOC(1, sizeof(corpconfParser)); 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 corpconfParser.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 corpconfParser interface */ ctx->config = config; ctx->block = block; ctx->line = line; ctx->value = value; ctx->free = corpconfParserFree; 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 = corpconfParserTokenNames; /* Return the newly built parser to the caller */ return ctx; }
ANTLR3_API pANTLR3_COMMON_TREE antlr3CommonTreeNew() { pANTLR3_COMMON_TREE tree; tree = (pANTLR3_COMMON_TREE)ANTLR3_CALLOC(1, sizeof(ANTLR3_COMMON_TREE)); if (tree == NULL) { return NULL; } antlr3SetCTAPI(tree); return tree; }
/** \brief Use the contents of an operating system file as the input * for an input stream. * * \param fileName Name of operating system file to read. * \return * - Pointer to new input stream context upon success * - One of the ANTLR3_ERR_ defines on error. */ ANTLR3_API pANTLR3_INPUT_STREAM antlr3AsciiFileStreamNew(pANTLR3_UINT8 fileName) { // Pointer to the input stream we are going to create // pANTLR3_INPUT_STREAM input; ANTLR3_UINT32 status; if (fileName == NULL) { return NULL; } // Allocate memory for the input stream structure // input = (pANTLR3_INPUT_STREAM) ANTLR3_CALLOC(1, sizeof(ANTLR3_INPUT_STREAM)); if (input == NULL) { return NULL; } // Structure was allocated correctly, now we can read the file. // status = antlr3readAscii(input, fileName); // Call the common 8 bit ASCII input stream handler // Initializer type thingy doobry function. // antlr3AsciiSetupStream(input, ANTLR3_CHARSTREAM); // Now we can set up the file name // input->istream->streamName = input->strFactory->newStr(input->strFactory, fileName); input->fileName = input->istream->streamName; if (status != ANTLR3_SUCCESS) { input->close(input); return NULL; } return input; }
static pANTLR3_INPUT_STREAM antlr3CreateLineBufferedStream(std::istream& in) { // Pointer to the input stream we are going to create // pANTLR3_INPUT_STREAM input; if (!in) { return NULL; } // Allocate memory for the input stream structure // input = (pANTLR3_INPUT_STREAM) ANTLR3_CALLOC(1, sizeof(ANTLR3_LINE_BUFFERED_INPUT_STREAM)); if (input == NULL) { return NULL; } // Structure was allocated correctly, now we can install the pointer // input->data = malloc(1024); input->isAllocated = ANTLR3_FALSE; ((pANTLR3_LINE_BUFFERED_INPUT_STREAM)input)->in = ∈ // Call the common 8 bit input stream handler // initialization. // #ifdef CVC4_ANTLR3_OLD_INPUT_STREAM antlr3AsciiSetupStream(input, ANTLR3_CHARSTREAM); #else /* CVC4_ANTLR3_OLD_INPUT_STREAM */ antlr38BitSetupStream(input); // In some libantlr3c 3.4-beta versions, this call is not included in the above. // This is probably an erroneously-deleted line in the libantlr3c source since 3.2. antlr3GenericSetupStream(input); #endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */ return input; }
pANTLR3_INPUT_STREAM MemoryMappedInputBufferNew(const std::string& filename) { // Pointer to the input stream we are going to create // pANTLR3_INPUT_STREAM input; ANTLR3_UINT32 status; // Allocate memory for the input stream structure // input = (pANTLR3_INPUT_STREAM) ANTLR3_CALLOC(1, sizeof(ANTLR3_INPUT_STREAM)); if(input == NULL) { return NULL; } // Structure was allocated correctly, now we can read the file. // status = MemoryMapFile(input, filename); // Call the common 8 bit ASCII input stream handler // Initializer type thingy doobry function. // #ifdef CVC4_ANTLR3_OLD_INPUT_STREAM antlr3AsciiSetupStream(input, ANTLR3_CHARSTREAM); #else /* CVC4_ANTLR3_OLD_INPUT_STREAM */ antlr38BitSetupStream(input); #endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */ // Now we can set up the file name // input->istream->streamName = input->strFactory->newStr(input->strFactory, (uint8_t*) filename.c_str()); input->fileName = input->istream->streamName; input->free = UnmapFile; if(status != ANTLR3_SUCCESS) { input->close(input); return NULL; } return input; }
ANTLR3_API pANTLR3_TREE_NODE_STREAM antlr3TreeNodeStreamNew() { pANTLR3_TREE_NODE_STREAM stream; // Memory for the interface structure // stream = (pANTLR3_TREE_NODE_STREAM) ANTLR3_CALLOC(1, sizeof(ANTLR3_TREE_NODE_STREAM)); if (stream == NULL) { return NULL; } // Install basic API // stream->replaceChildren = replaceChildren; stream->free = antlr3TreeNodeStreamFree; return stream; }
static pANTLR3_COMMON_TOKEN newToken(void) { pANTLR3_COMMON_TOKEN token; /* Allocate memory for this */ token = (pANTLR3_COMMON_TOKEN) ANTLR3_CALLOC(1, (size_t)(sizeof(ANTLR3_COMMON_TOKEN))); if (token == NULL) { return NULL; } // Install the API // antlr3SetTokenAPI(token); token->factoryMade = ANTLR3_FALSE; return token; }
static void newPool(pANTLR3_TOKEN_FACTORY factory) { /* Increment factory count */ factory->thisPool++; // If we were reusing this token factory then we may already have a pool // allocated. If we exceeded the max avaible then we must allocate a new // one. if (factory->thisPool > factory->maxPool) { /* Ensure we have enough pointers allocated */ factory->pools = (pANTLR3_COMMON_TOKEN *) ANTLR3_REALLOC( (void *)factory->pools, /* Current pools pointer (starts at NULL) */ (ANTLR3_UINT32)((factory->thisPool + 1) * sizeof(pANTLR3_COMMON_TOKEN *)) /* Memory for new pool pointers */ ); /* Allocate a new pool for the factory */ factory->pools[factory->thisPool] = (pANTLR3_COMMON_TOKEN) ANTLR3_CALLOC(1, (size_t)(sizeof(ANTLR3_COMMON_TOKEN) * ANTLR3_FACTORY_POOL_SIZE)); // We now have a new pool and can track it as the maximum we have created so far // factory->maxPool = factory->thisPool; } /* Reset the counters */ factory->nextToken = 0; /* Done */ return; }
ANTLR3_API pANTLR3_COMMON_TREE_NODE_STREAM antlr3CommonTreeNodeStreamNew(pANTLR3_STRING_FACTORY strFactory, ANTLR3_UINT32 hint) { pANTLR3_COMMON_TREE_NODE_STREAM stream; pANTLR3_COMMON_TOKEN token; // Memory for the interface structure // stream = (pANTLR3_COMMON_TREE_NODE_STREAM) ANTLR3_CALLOC(1, sizeof(ANTLR3_COMMON_TREE_NODE_STREAM)); if (stream == NULL) { return NULL; } // String factory for tree walker // stream->stringFactory = strFactory; // Create an adaptor for the common tree node stream // stream->adaptor = ANTLR3_TREE_ADAPTORNew(strFactory); if (stream->adaptor == NULL) { stream->free(stream); return NULL; } // Create space for the tree node stream interface // stream->tnstream = antlr3TreeNodeStreamNew(); if (stream->tnstream == NULL) { stream->adaptor->free (stream->adaptor); stream->free (stream); return NULL; } // Create space for the INT_STREAM interface // stream->tnstream->istream = antlr3IntStreamNew(); if (stream->tnstream->istream == NULL) { stream->adaptor->free (stream->adaptor); stream->tnstream->free (stream->tnstream); stream->free (stream); return NULL; } // Install the common tree node stream API // stream->addNavigationNode = addNavigationNode; stream->hasUniqueNavigationNodes = hasUniqueNavigationNodes; stream->newDownNode = newDownNode; stream->newUpNode = newUpNode; stream->reset = reset; stream->push = push; stream->pop = pop; stream->free = antlr3CommonTreeNodeStreamFree; // Install the tree node stream API // stream->tnstream->getTreeAdaptor = getTreeAdaptor; stream->tnstream->getTreeSource = getTreeSource; stream->tnstream->_LT = _LT; stream->tnstream->setUniqueNavigationNodes = setUniqueNavigationNodes; stream->tnstream->toString = toString; stream->tnstream->toStringSS = toStringSS; stream->tnstream->toStringWork = toStringWork; stream->tnstream->get = get; // Install INT_STREAM interface // stream->tnstream->istream->consume = consume; stream->tnstream->istream->index = tindex; stream->tnstream->istream->_LA = _LA; stream->tnstream->istream->mark = mark; stream->tnstream->istream->release = release; stream->tnstream->istream->rewind = rewindMark; stream->tnstream->istream->rewindLast = rewindLast; stream->tnstream->istream->seek = seek; stream->tnstream->istream->size = size; // Initialize data elements of INT stream // stream->tnstream->istream->type = ANTLR3_COMMONTREENODE; stream->tnstream->istream->super = (stream->tnstream); // Initialize data elements of TREE stream // stream->tnstream->ctns = stream; // Initialize data elements of the COMMON TREE NODE stream // stream->super = NULL; stream->uniqueNavigationNodes = ANTLR3_FALSE; stream->markers = NULL; stream->nodeStack = antlr3StackNew(INITIAL_CALL_STACK_SIZE); // Create the node list map // if (hint == 0) { hint = DEFAULT_INITIAL_BUFFER_SIZE; } stream->nodes = antlr3VectorNew(hint); stream->p = -1; // Install the navigation nodes // antlr3SetCTAPI(&(stream->UP)); antlr3SetCTAPI(&(stream->DOWN)); antlr3SetCTAPI(&(stream->EOF_NODE)); antlr3SetCTAPI(&(stream->INVALID_NODE)); token = antlr3CommonTokenNew(ANTLR3_TOKEN_UP); token->strFactory = strFactory; token->textState = ANTLR3_TEXT_CHARP; token->tokText.chars = (pANTLR3_UCHAR)"UP"; stream->UP.token = token; token = antlr3CommonTokenNew(ANTLR3_TOKEN_DOWN); token->strFactory = strFactory; token->textState = ANTLR3_TEXT_CHARP; token->tokText.chars = (pANTLR3_UCHAR)"DOWN"; stream->DOWN.token = token; token = antlr3CommonTokenNew(ANTLR3_TOKEN_EOF); token->strFactory = strFactory; token->textState = ANTLR3_TEXT_CHARP; token->tokText.chars = (pANTLR3_UCHAR)"EOF"; stream->EOF_NODE.token = token; token = antlr3CommonTokenNew(ANTLR3_TOKEN_INVALID); token->strFactory = strFactory; token->textState = ANTLR3_TEXT_CHARP; token->tokText.chars = (pANTLR3_UCHAR)"INVALID"; stream->INVALID_NODE.token = token; return stream; }
ANTLR3_API pANTLR3_COMMON_TREE_NODE_STREAM antlr3CommonTreeNodeStreamNewStream(pANTLR3_COMMON_TREE_NODE_STREAM inStream) { pANTLR3_COMMON_TREE_NODE_STREAM stream; // Memory for the interface structure // stream = (pANTLR3_COMMON_TREE_NODE_STREAM) ANTLR3_CALLOC(1, sizeof(ANTLR3_COMMON_TREE_NODE_STREAM)); if (stream == NULL) { return NULL; } // Copy in all the reusable parts of the originating stream and create new // pieces where necessary. // // String factory for tree walker // stream->stringFactory = inStream->stringFactory; // Create an adaptor for the common tree node stream // stream->adaptor = inStream->adaptor; // Create space for the tree node stream interface // stream->tnstream = antlr3TreeNodeStreamNew(); if (stream->tnstream == NULL) { stream->free (stream); return NULL; } // Create space for the INT_STREAM interface // stream->tnstream->istream = antlr3IntStreamNew(); if (stream->tnstream->istream == NULL) { stream->tnstream->free (stream->tnstream); stream->free (stream); return NULL; } // Install the common tree node stream API // stream->addNavigationNode = addNavigationNode; stream->hasUniqueNavigationNodes = hasUniqueNavigationNodes; stream->newDownNode = newDownNode; stream->newUpNode = newUpNode; stream->reset = reset; stream->push = push; stream->pop = pop; stream->getLookaheadSize = getLookaheadSize; stream->free = antlr3CommonTreeNodeStreamFree; // Install the tree node stream API // stream->tnstream->getTreeAdaptor = getTreeAdaptor; stream->tnstream->getTreeSource = getTreeSource; stream->tnstream->_LT = _LT; stream->tnstream->setUniqueNavigationNodes = setUniqueNavigationNodes; stream->tnstream->toString = toString; stream->tnstream->toStringSS = toStringSS; stream->tnstream->toStringWork = toStringWork; stream->tnstream->get = get; // Install INT_STREAM interface // stream->tnstream->istream->consume = consume; stream->tnstream->istream->index = tindex; stream->tnstream->istream->_LA = _LA; stream->tnstream->istream->mark = mark; stream->tnstream->istream->release = release; stream->tnstream->istream->rewind = rewindMark; stream->tnstream->istream->rewindLast = rewindLast; stream->tnstream->istream->seek = seek; stream->tnstream->istream->size = size; // Initialize data elements of INT stream // stream->tnstream->istream->type = ANTLR3_COMMONTREENODE; stream->tnstream->istream->super = (stream->tnstream); // Initialize data elements of TREE stream // stream->tnstream->ctns = stream; // Initialize data elements of the COMMON TREE NODE stream // stream->super = NULL; stream->uniqueNavigationNodes = ANTLR3_FALSE; stream->markers = NULL; stream->nodeStack = inStream->nodeStack; // Create the node list map // stream->nodes = antlr3VectorNew(DEFAULT_INITIAL_BUFFER_SIZE); stream->p = -1; // Install the navigation nodes // // Install the navigation nodes // antlr3SetCTAPI(&(stream->UP)); antlr3SetCTAPI(&(stream->DOWN)); antlr3SetCTAPI(&(stream->EOF_NODE)); antlr3SetCTAPI(&(stream->INVALID_NODE)); stream->UP.token = inStream->UP.token; inStream->UP.token->strFactory = stream->stringFactory; stream->DOWN.token = inStream->DOWN.token; inStream->DOWN.token->strFactory = stream->stringFactory; stream->EOF_NODE.token = inStream->EOF_NODE.token; inStream->EOF_NODE.token->strFactory = stream->stringFactory; stream->INVALID_NODE.token = inStream->INVALID_NODE.token; inStream->INVALID_NODE.token->strFactory= stream->stringFactory; // Reuse the root tree of the originating stream // stream->root = inStream->root; // Signal that this is a rewriting stream so we don't // free the originating tree. Anything that we rewrite or // duplicate here will be done through the adaptor or // the original tree factory. // stream->isRewriter = ANTLR3_TRUE; return stream; }
ANTLR3_API pANTLR3_LEXER antlr3LexerNew(ANTLR3_UINT32 sizeHint, pANTLR3_RECOGNIZER_SHARED_STATE state) { pANTLR3_LEXER lexer; pANTLR3_COMMON_TOKEN specialT; /* Allocate memory */ lexer = (pANTLR3_LEXER) ANTLR3_MALLOC(sizeof(ANTLR3_LEXER)); if (lexer == NULL) { return NULL; } /* Now we need to create the base recognizer */ lexer->rec = antlr3BaseRecognizerNew(ANTLR3_TYPE_LEXER, sizeHint, state); if (lexer->rec == NULL) { lexer->free(lexer); return NULL; } lexer->rec->super = lexer; lexer->rec->displayRecognitionError = displayRecognitionError; lexer->rec->reportError = reportError; lexer->rec->reset = reset; lexer->rec->getCurrentInputSymbol = getCurrentInputSymbol; lexer->rec->getMissingSymbol = getMissingSymbol; /* Now install the token source interface */ if (lexer->rec->state->tokSource == NULL) { lexer->rec->state->tokSource = (pANTLR3_TOKEN_SOURCE)ANTLR3_CALLOC(1, sizeof(ANTLR3_TOKEN_SOURCE)); if (lexer->rec->state->tokSource == NULL) { lexer->rec->free(lexer->rec); lexer->free(lexer); return NULL; } lexer->rec->state->tokSource->super = lexer; /* Install the default nextToken() method, which may be overridden * by generated code, or by anything else in fact. */ lexer->rec->state->tokSource->nextToken = nextToken; lexer->rec->state->tokSource->strFactory = NULL; lexer->rec->state->tokFactory = NULL; } /* Install the lexer API */ lexer->setCharStream = setCharStream; lexer->mTokens = (void (*)(void *))(mTokens); lexer->setCharStream = setCharStream; lexer->pushCharStream = pushCharStream; lexer->popCharStream = popCharStream; lexer->emit = emit; lexer->emitNew = emitNew; lexer->matchs = matchs; lexer->matchc = matchc; lexer->matchRange = matchRange; lexer->matchAny = matchAny; lexer->recover = recover; lexer->getLine = getLine; lexer->getCharIndex = getCharIndex; lexer->getCharPositionInLine = getCharPositionInLine; lexer->getText = getText; lexer->free = freeLexer; /* Initialise the eof token */ specialT = &(lexer->rec->state->tokSource->eofToken); antlr3SetTokenAPI (specialT); specialT->setType (specialT, ANTLR3_TOKEN_EOF); specialT->factoryMade = ANTLR3_TRUE; // Prevent things trying to free() it specialT->strFactory = NULL; specialT->textState = ANTLR3_TEXT_NONE; specialT->custom = NULL; specialT->user1 = 0; specialT->user2 = 0; specialT->user3 = 0; // Initialize the skip token. // specialT = &(lexer->rec->state->tokSource->skipToken); antlr3SetTokenAPI (specialT); specialT->setType (specialT, ANTLR3_TOKEN_INVALID); specialT->factoryMade = ANTLR3_TRUE; // Prevent things trying to free() it specialT->strFactory = NULL; specialT->custom = NULL; specialT->user1 = 0; specialT->user2 = 0; specialT->user3 = 0; return lexer; }
/** \brief Create a new lexer called belle_sdpLexer * * \param[in] instream Pointer to an initialized input stream * \param[state] state Previously created shared recognizer stat * \return * - Success pbelle_sdpLexer initialized for the lex start * - Fail NULL */ ANTLR3_API pbelle_sdpLexer belle_sdpLexerNewSSD (pANTLR3_INPUT_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state) { pbelle_sdpLexer ctx; // Context structure we will build and return ctx = (pbelle_sdpLexer) ANTLR3_CALLOC(1, sizeof(belle_sdpLexer)); if (ctx == NULL) { // Failed to allocate memory for lexer context return NULL; } /* ------------------------------------------------------------------- * Memory for basic structure is allocated, now to fill in * in base ANTLR3 structures. We initialize the function pointers * for the standard ANTLR3 lexer 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 belle_sdpLexer.h here so you can get a sense * of what goes where. */ /* Create a base lexer, using the supplied input stream */ ctx->pLexer = antlr3LexerNewStream(ANTLR3_SIZE_HINT, instream, state); /* Check that we allocated the memory correctly */ if (ctx->pLexer == NULL) { ANTLR3_FREE(ctx); return NULL; } /* Install the implementation of our belle_sdpLexer interface */ ctx->mT__20 = mT__20; ctx->mT__21 = mT__21; ctx->mT__22 = mT__22; ctx->mT__23 = mT__23; ctx->mT__24 = mT__24; ctx->mT__25 = mT__25; ctx->mT__26 = mT__26; ctx->mT__27 = mT__27; ctx->mDIGIT = mDIGIT; ctx->mZERO = mZERO; ctx->mPOS_DIGIT = mPOS_DIGIT; ctx->mCOMMON_CHAR = mCOMMON_CHAR; ctx->mHEX_CHAR = mHEX_CHAR; ctx->mSPACE = mSPACE; ctx->mLQUOTE = mLQUOTE; ctx->mRQUOTE = mRQUOTE; ctx->mCR = mCR; ctx->mLF = mLF; ctx->mDOT = mDOT; ctx->mEQUAL = mEQUAL; ctx->mCOLON = mCOLON; ctx->mSLASH = mSLASH; ctx->mDASH = mDASH; ctx->mANY_EXCEPT_CR_LF = mANY_EXCEPT_CR_LF; ctx->mTokens = mTokens; /** When the nextToken() call is made to this lexer's pANTLR3_TOKEN_SOURCE * it will call mTokens() in this generated code, and will pass it the ctx * pointer of this lexer, not the context of the base lexer, so store that now. */ ctx->pLexer->ctx = ctx; /**Install the token matching function */ ctx->pLexer->mTokens = (void (*) (void *))(mTokens); ctx->getGrammarFileName = getGrammarFileName; ctx->free = belle_sdpLexerFree; /* Return the newly built lexer to the caller */ return ctx; }
/** \brief Create a new lexer called ExprCppTreeLexer * * \param[in] instream Pointer to an initialized input stream * \param[state] state Previously created shared recognizer stat * \return * - Success pExprCppTreeLexer initialized for the lex start * - Fail NULL */ ANTLR3_API pExprCppTreeLexer ExprCppTreeLexerNewSSD (pANTLR3_INPUT_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state) { pExprCppTreeLexer ctx; // Context structure we will build and return ctx = (pExprCppTreeLexer) ANTLR3_CALLOC(1, sizeof(ExprCppTreeLexer)); if (ctx == NULL) { // Failed to allocate memory for lexer context return NULL; } /* ------------------------------------------------------------------- * Memory for basic structure is allocated, now to fill in * in base ANTLR3 structures. We initialize the function pointers * for the standard ANTLR3 lexer 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 ExprCppTreeLexer.h here so you can get a sense * of what goes where. */ /* Create a base lexer, using the supplied input stream */ ctx->pLexer = antlr3LexerNewStream(ANTLR3_SIZE_HINT, instream, state); /* Check that we allocated the memory correctly */ if (ctx->pLexer == NULL) { ANTLR3_FREE(ctx); return NULL; } /* Install the implementation of our ExprCppTreeLexer interface */ ctx->mT__12 = mT__12; ctx->mT__13 = mT__13; ctx->mPLUS = mPLUS; ctx->mMINUS = mMINUS; ctx->mTIMES = mTIMES; ctx->mASSIGN = mASSIGN; ctx->mID = mID; ctx->mINT = mINT; ctx->mNEWLINE = mNEWLINE; ctx->mWS = mWS; ctx->mTokens = mTokens; /** When the nextToken() call is made to this lexer's pANTLR3_TOKEN_SOURCE * it will call mTokens() in this generated code, and will pass it the ctx * pointer of this lexer, not the context of the base lexer, so store that now. */ ctx->pLexer->ctx = ctx; /**Install the token matching function */ ctx->pLexer->mTokens = (void (*) (void *))(mTokens); ctx->getGrammarFileName = getGrammarFileName; ctx->free = ExprCppTreeLexerFree; ctx->reset = ExprCppTreeLexerReset; /* Return the newly built lexer to the caller */ return ctx; }
/** \brief Create a new filter_expressionParser 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 pfilter_expressionParser filter_expressionParserNewSSD (pANTLR3_COMMON_TOKEN_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state) { pfilter_expressionParser ctx; /* Context structure we will build and return */ ctx = (pfilter_expressionParser) ANTLR3_CALLOC(1, sizeof(filter_expressionParser)); 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 filter_expressionParser.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 filter_expressionParser interface */ ctx->start_point = start_point; ctx->filter_expr = filter_expr; ctx->boolean_expr = boolean_expr; ctx->boolean_term = boolean_term; ctx->boolean_value = boolean_value; ctx->parenthesized_boolean = parenthesized_boolean; ctx->nonparentherized_boolean = nonparentherized_boolean; ctx->unary_expr = unary_expr; ctx->xpath_expr = xpath_expr; ctx->constant_expr = constant_expr; ctx->operand_expr = operand_expr; ctx->free = filter_expressionParserFree; ctx->reset = filter_expressionParserReset; ctx->getGrammarFileName = getGrammarFileName; /* Install the scope pushing methods. */ RECOGNIZER->displayRecognitionError = displayRecognitionErrorNew; // RECOGNIZER->reportError = reportOverride; // RECOGNIZER->antlr3RecognitionExceptionNew = antlr3RecognitionExceptionNewNew; // RECOGNIZER->mismatch = mismatchNew; /* Install the token table */ PSRSTATE->tokenNames = filter_expressionParserTokenNames; /* Return the newly built parser to the caller */ return ctx; }