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

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

问题描述

我看到C的一些示例main()浮动了,例如 http://www.antlr.org/Wiki/display/ANTLR3/五分钟+简介+到+ ANTLR + 3

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天全站免登陆