寻找 Antlr 3/C 示例 main() [英] Looking for Antlr 3 / C sample main()

查看:20
本文介绍了寻找 Antlr 3/C 示例 main()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一些 C 的示例 main() 浮动,例如http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3http://www.antlr.org/api/C/index.html

I see a few sample main() for C floating about, e.g. http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3 and http://www.antlr.org/api/C/index.html

取消引用似乎是 AST.我不知道那是什么,而且——请原谅——如果我能避免的话,我不想这样做.

The dereference seems to be AST. I don't know what that is , and - please excuse me - don't want to if I can avoid it.

我只想定义词法分析器 &语法(用于调制解调器 AT 命令)并自动生成 main() 或从某处剪切/粘贴.

I woudl like to just define the lexer & grammar (for modem AT commands) and have the main() auto-generated, or cut/pasted from somewhere.

稍有不同的是,大多数示例似乎都是从文件中读取的,而我将获得一系列作为字符串的输入(AT 命令),并作为参数传递.

Ons slight twist is that most examples seem to read from a file, whereas I will be getting a series of inputs (AT commands) as strings, passed as parameters.

任何人都可以请我指出一个我可以适应的简单 main() (并且可能建议 hwo 适应它?)我知道很多问题,抱歉.

Can anyone please point me at a simple main() which I can adapt (and maybe suggest hwo to adapt it?) A lot to ask I know, sorry.

推荐答案

AST 是一种抽象语法树",对于 AT 命令,您不需要它.

An AST is an "Abstract Syntax Tree", and for AT commands you do not need one.

事实上,ANTLR 对解析 AT 命令来说太过分了.为什么不直接检查AT",然后手动解析命令呢?调制解调器命令集可能非常简单,如果您以前从未这样做过,那么这样做比让 ANTLR 运行更简单.

In fact, ANTLR is overkill for parsing AT commands. Why not just check for the "AT", and then parse the commands by hand? The modem command set is probably sufficiently simple that it will be simpler to do that than to get ANTLR going if you have never done it before.

如果您要实现完整的 AT 命令集,包括+++"转义序列,时间也是一个因素,您将无法单独使用 ANTLR 来实现.

If you are implementing a full AT command set, including the "+++" escape sequence, timing is also a factor which you will not be able to implement using ANTLR alone.

回复评论:

将 ANTLR 视为减少错误的工具是合理的.在回答您的问题您更愿意阅读那个还是精心设计的代码?您更愿意维护哪个?"时,答案是这取决于".我根据上下文使用 ANTLR 和手工编码的解析器;这是一个我会选择手动编码解析器的上下文.一些原因:可能是嵌入式应用程序,相对简单(许多命令不等于复杂性),通信协议.您有不同的背景,并且显然有自己的理由,包括尝试一下".

Seeing ANTLR as a tool to reduce bugs is reasonable. In answer to your questions "Would you rather read that or the had-crafted code? And which would you rather maintain?", the answer is "it depends." I use both ANTLR and hand-coded parsers depending on the context; this a context where I would choose a hand-coded parser. Some reasons: probably an embedded application, relatively straightforward (many commands does not equal complexity), a comms protocol. You have a different context and clearly have your own reasons which include "trying it out".

所以,要回答关于主要的另一个问题:是的,您可以使用 ANTLR wiki 上的那个.要从一段内存中读取数据,请使用 antlr3NewAsciiStringInPlaceStream()antlr3NewAsciiStringCopyStream()(视情况而定)而不是 antlr3AsciiFileStreamNew().

So, to answer your other question about a main: Yes, you can use the one on the ANTLR wiki. To read from a piece of memory use antlr3NewAsciiStringInPlaceStream() or antlr3NewAsciiStringCopyStream() (as appropriate) instead of antlr3AsciiFileStreamNew().

这篇关于寻找 Antlr 3/C 示例 main()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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