gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:38:55 25 4
gpt4 key购买 nike

有谁知道(或拥有)C 目标的简单 ANTLR 3.4 示例 main() 函数?我试图开始使用 C 或 C++ 中的 ANTLR,我看到的所有示例(包括 this)都已过时,例如他们使用不再存在的功能。下载包本身似乎没有任何示例,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);

}

关于c++ - C 目标运行时的简单 ANTLR 3.4 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8537214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com