LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-02-2009, 07:50 PM   #1
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Rep: Reputation: 16
interpreter creation with yacc


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.
 
Old 10-02-2009, 09:26 PM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by wtruong View Post
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.
 
Old 10-03-2009, 03:50 AM   #3
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
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?
 
Old 10-03-2009, 04:52 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by wtruong View Post
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?
 
Old 10-03-2009, 12:44 PM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,241

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by lutusp View Post
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
 
Old 10-03-2009, 12:47 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,543

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
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.
 
Old 10-04-2009, 01:37 PM   #7
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
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.
 
Old 10-04-2009, 02:12 PM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by wtruong View Post
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.
In this case it is.
 
Old 10-04-2009, 02:15 PM   #9
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,241

Rep: Reputation: 194Reputation: 194
unless you want to run shell scripts
 
Old 10-04-2009, 06:30 PM   #10
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,543

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Quote:
Originally Posted by Sergei Steshenko
In this case it is.
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.

@wtruong: have you tried rlwrap?
 
Old 10-05-2009, 12:21 PM   #11
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
I'm looking into it right now. Thanks ntubski.
 
Old 10-05-2009, 12:40 PM   #12
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by wtruong View Post
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.
 
Old 10-05-2009, 10:34 PM   #13
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
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)
 
Old 10-05-2009, 11:21 PM   #14
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by wtruong View Post
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.
 
Old 10-06-2009, 01:15 AM   #15
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
... 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.

Thanks again ntubski
 
  


Reply

Tags
lex, yacc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hiding a yacc interpreter prompt from pipes wtruong Programming 5 05-30-2009 06:11 AM
LEX and YACC with C gr33ndata Programming 4 11-18-2007 06:12 PM
Using YACC with C++ in Kdevelop dancarlson Programming 1 01-07-2006 01:29 PM
Where to get Yacc? kaydknight Linux - Software 2 12-08-2005 03:59 AM
problem with yacc fssengg Programming 3 03-09-2005 11:56 AM


All times are GMT -5. The time now is 07:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration