一个简单的ANTLR 3.4例如对于C目标运行时 [英] A simple ANTLR 3.4 example for C target runtime

查看:200
本文介绍了一个简单的ANTLR 3.4例如对于C目标运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道(或有)一个简单的ANTLR 3.4例如的main()函数对C目标?我想开始使用ANTLR在C或C ++,我看到所有的例子(包括的这个)已经过时,例如:他们使用不存在任何更多的功能。目前似乎没有要与下载的软件包本身的任何实例,并在维基的例子是过时的。

Does anyone know of (or have) a simple ANTLR 3.4 example main() function for C target? I'm trying to get started with ANTLR in C or C++, and all examples I see (including this) are out of date, e.g. they use functions that don't exist any more. There don't seem to be any examples with downloaded package itself, and the example on Wiki is out of date.

推荐答案

未经检验。

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

}

这篇关于一个简单的ANTLR 3.4例如对于C目标运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆