Sample Search Antlr 3 / C main ()

I see some examples of main () for C floating around, for example. http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3 and http://www.antlr.org/api/C/index.html

The difference, apparently, is AST. I don’t know what it is, and please excuse me - I don’t want it if I can avoid it.

I would just like to define lexer and grammar (for AT modem commands) and have main () automatically generated or cut / paste from somewhere.

A small twist is that most of the examples seem to be read from a file, while I will get a series of inputs (AT commands) as strings passed as parameters.

Can someone point me to a simple main () that I can adapt (and perhaps suggest hwo to adapt it?) To ask a lot, I know, I'm sorry.

+1
source share
1 answer

AST is an "abstract syntax tree", and you don't need AT commands.

In fact, ANTLR is redundant for parsing AT commands. Why not just check "AT" and then parse the commands manually? The modem command set is probably simple enough that it will be easier to do this than get ANTLR if you have never done it before.

If you implement the full set of AT commands, including the escape sequence β€œ+++”, time is also a factor that you cannot implement using only ANTLR.

Reply to comments:

Seeing ANTLR as a tool to reduce errors is prudent. Answering your questions: β€œWould you rather read this code or the code that would be processed? And what would you rather save?”, The answer is β€œit depends.” I use ANTLR and manual encoders depending on the context; this is the context in which I would choose a parser with manual coding. Some reasons: perhaps a built-in application, relatively simple (many teams are not equal in complexity), a communication protocol. You have a different context, and you have your own reasons, which include trying.

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

+2
source

Source: https://habr.com/ru/post/1386740/


All Articles