C目标运行时的简单ANTLR 3.4示例

有没有人知道(或有)一个简单的ANTLR 3.4示例main()函数用于C目标? 我试图在C或C ++中开始使用ANTLR,我看到的所有示例(包括这个 )都已过时,例如它们使用的函数不再存在。 似乎没有下载包本身的任何示例,Wiki上的示例已过时。

未经测试。

 #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); }