ANTLR 3.4 Simple Example for C Runtime

Does anyone know (or have) a simple ANTLR 3.4 main() example for a C object? I'm trying to get started with ANTLR in C or C ++, and all the examples I see (including this ) are deprecated, for example. they use functions that no longer exist. It seems that there are no examples with the downloaded package itself, and the example in the Wiki is deprecated.

+4
source share
1 answer

Unverified.

 #include "YourLexer.h" #include "YourParser.h" int main() { uint8_t * bufferData; // Some memory with text in it uint32_t bufferSize; // Size of said memory pANTLR3_UINT8 bufferName; // Name of buffer. ANTLR uses this for some default // error messages //Creates an input stream. If you want to parse once from multiple sources // you can switch among these during lexing pANTLR3_INPUT_STREAM input = antlr3StringStreamNew( bufferData, ANTLR3_ENC_8BIT, bufferSize, bufferName); assert(input != NULL); //Creates the lexer. Doesn't do anything until the parser(or you) tells it to. pYourLexer lxr = YourLexerNew(input); assert(lxr != NULL); //Creates an empty token stream. pANTLR3_COMMON_TOKEN_STREAM tstream = antlr3CommonTokenStreamSourceNew( ANTLR3_SIZE_HINT, TOKENSOURCE(lxr)); assert(tstream != NULL); //Creates a parser. pYourParser psr = YourParserNew(tstream); assert(psr != NULL); //Run the parser rule. This also runs the lexer to create the token stream. psr->some_parser_rule(psr); } 
+6
source

Source: https://habr.com/ru/post/1386736/


All Articles