ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Using yacc, lex, and c, how would I imitate the 'up' key feature similar to that from any shell.
Basically I want to be able to press up to display past commands.
Imitate how, and in what context? Any CLI program or shell script can set up the history feature very easily, without invoking the heavy-duty methods you are suggesting.
My yacc/lex program is a CLI, so it acts independently from the outside. That is why i need to find out how other CLI's program their history and up feature so I can imitate. I looked in the bash yacc code and there is too much information to parse. Can anyone point me to the right direction?
My yacc/lex program is a CLI, so it acts independently from the outside. That is why i need to find out how other CLI's program their history and up feature so I can imitate. I looked in the bash yacc code and there is too much information to parse. Can anyone point me to the right direction?
Have you considered writing it yourself, like a normal computer programmer? Has it occurred to you that lex/yacc/c is overkill for such a simple thing?
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Rep:
Quote:
Originally Posted by lutusp
Have you considered writing it yourself, like a normal computer programmer? Has it occurred to you that lex/yacc/c is overkill for such a simple thing?
i agree, i write all my parsers myself
its worth the effort
You could use rlwrap, that would give you bash-like cli pretty much for free. Otherwise look at the GNU readline library. yacc/lex have nothing to do with the history mechanism.
I don't believe that yavv/lex is overkill for parsing. It is much more time efficient than writing a parser manually in C. My CLI does other more complicated things and I just want to add the history and up feature to it.
I don't believe that yavv/lex is overkill for parsing. It is much more time efficient than writing a parser manually in C. My CLI does other more complicated things and I just want to add the history and up feature to it.
The OP's question was about adding a history to the input, and doesn't have anything to do with parsing. There's no way of knowing whether yacc is overkill or not, since we have no idea what the input language looks like.
I don't believe that yavv/lex is overkill for parsing. It is much more time efficient than writing a parser manually in C. My CLI does other more complicated things and I just want to add the history and up feature to it.
Well, once you have used this cybernetic powerhouse to create the trivial feature that is your goal, you will know one way or another whether it is overkill.
There was a time when people wrote a few lines of C to accomplish this. As a result, they had a readable, commented C source file to refer to and change in the future.
I don't know why you guys think yacc/lex is overkill. It allows for much faster development, since that was what it was intended for.
btw for all you nonbelievers, I already have a CLI that interfaces with a driver in order to read and write from registers and memory on an fpga. An equivalent C parser program would mean 1000's of lines of unverified developer code. With yacc and lex, a developer would only need to write a couple hundred lines of code that deals with lexical analyzing and syntax parsing.
I don't know why you guys think yacc/lex is overkill. It allows for much faster development, since that was what it was intended for.
btw for all you nonbelievers, I already have a CLI that interfaces with a driver in order to read and write from registers and memory on an fpga. An equivalent C parser program would mean 1000's of lines of unverified developer code. With yacc and lex, a developer would only need to write a couple hundred lines of code that deals with lexical analyzing and syntax parsing.
(still looking at rlwrap)
If you are talking about a parser, its main task is to find in input stream known to it language constructs and to call user defined subroutine/action upon detection.
So, reaction on a key pressed is a user action, and as such has nothing to do with yacc/lex.
And since you've confessed about FPGA, a, say, Perl (or other scripting language) parser generator would have saved many more lines of code. I.e. one needs a very thin "C" layer (if any) for such tasks.
At all, I find lexer -> token sequence analyzer approach outdated and inefficient from development point of view.
... can i reiterate that I already built a CLI, and therefore any other different approaches would be going backwards in my development. I'm looking in the bash source code right now, and looking at how they integrated rlwrap with yacc/lex.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.