473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

parsing a command

Hi,

I am writing a minimal shell as a learning project. I am able to
execute simple commands through this shell, but don't know how to
execute "for/while loops" "if-then" and so on. Is there any standard
way of interpreting these ? Does anyone knows of any link that
explains this in detail ?

thanks for any help .....

Oct 7 '06 #1
7 1619


On Oct 7, 2:52 pm, "junky_fel...@yahoo.co.in"
<junky_fel...@yahoo.co.inwrote:
Hi,

I am writing a minimal shell as a learning project. I am able to
execute simple commands through this shell, but don't know how to
execute "for/while loops" "if-then" and so on. Is there any standard
way of interpreting these ? Does anyone knows of any link that
explains this in detail ?

thanks for any help .....
Maybe Bison can help you.
http://dinosaur.compilertools.net/bison/index.html

Oct 7 '06 #2
Be creative.
If you're re-inventing the wheel for the sake of learning why concern
yourself with what other people have done?
ju**********@yahoo.co.in wrote:
Hi,

I am writing a minimal shell as a learning project. I am able to
execute simple commands through this shell, but don't know how to
execute "for/while loops" "if-then" and so on. Is there any standard
way of interpreting these ? Does anyone knows of any link that
explains this in detail ?

thanks for any help .....
Oct 7 '06 #3

<ju**********@yahoo.co.inwrote in message news
Hi,

I am writing a minimal shell as a learning project. I am able to
execute simple commands through this shell, but don't know how to
execute "for/while loops" "if-then" and so on. Is there any standard
way of interpreting these ? Does anyone knows of any link that
explains this in detail ?
You need a copy of MiniBasic, how to write a script interpreter.
You could simply embed the interpreter into your shell, which would allow
you write BASIC programs on the fly.
You will need to add a syntax to call programs by name. That's not
difficult. Either add a keyword "CALL" or say that lines beginning with
unknown identifiers are calls.

Or you could strip out the line numbers to get something more like the UNIX
shells. That's a slightly bigger operation, since line number make the
interpreter a lot easier to write.
Source is available for free on the website, the book is very reasonably
priced.
--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.
Oct 8 '06 #4

ju**********@yahoo.co.in wrote:
Hi,

I am writing a minimal shell as a learning project. I am able to
execute simple commands through this shell, but don't know how to
execute "for/while loops" "if-then" and so on. Is there any standard
way of interpreting these ? Does anyone knows of any link that
explains this in detail ?

thanks for any help .....
I think you should have an expression evaluator.
if you have a while, evaluate whats inside, each iteration.

if u have the text
for(exp1; exp2; exp3){
exp4
}

you should have in your code:
for(eval("exp1"); eval("exp2"); eval("exp3")){
eval("exp4")
}

or something like that.
It's not that complicated...

Oct 8 '06 #5
"Spiritus" <Sp*******@gmail.comwrote in message news
>
ju**********@yahoo.co.in wrote:
>Hi,

I am writing a minimal shell as a learning project. I am able to
execute simple commands through this shell, but don't know how to
execute "for/while loops" "if-then" and so on. Is there any standard
way of interpreting these ? Does anyone knows of any link that
explains this in detail ?

thanks for any help .....

I think you should have an expression evaluator.
if you have a while, evaluate whats inside, each iteration.

if u have the text
for(exp1; exp2; exp3){
exp4
}

you should have in your code:
for(eval("exp1"); eval("exp2"); eval("exp3")){
eval("exp4")
}

or something like that.
It's not that complicated...
MiniBasic is about a thousand lines of C source, and is designed to be a
fairly minimal but usable BASIC.
A minimal shell will run to a similar size. It's quite a big job.
--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.
Oct 8 '06 #6


On Oct 7, 12:36 pm, "Cong Wang" <xiyou.wangc...@gmail.comwrote:
On Oct 7, 2:52 pm, "junky_fel...@yahoo.co.in"

<junky_fel...@yahoo.co.inwrote:
Hi,
I am writing a minimal shell as a learning project. I am able to
execute simple commands through this shell, but don't know how to
execute "for/while loops" "if-then" and so on. Is there any standard
way of interpreting these ? Does anyone knows of any link that
explains this in detail ?
thanks for any help .....Maybe Bison can help you.http://dinosaur.compilertools.net/bison/index.html
thanks. using flex/bison to parse the command looks really useful. I am
able to interpret simple expressions with this. However, I don't know
how to deal with complex statements like IF cond statements else
statements. Is there any useful link that explains the things with
simple examples ?

Oct 12 '06 #7

ju**********@yahoo.co.in wrote:
Hi,

I am writing a minimal shell as a learning project. I am able to
execute simple commands through this shell, but don't know how to
execute "for/while loops" "if-then" and so on. Is there any standard
way of interpreting these ? Does anyone knows of any link that
explains this in detail ?

thanks for any help .....
Marc Rochkind's book on Advanced C in the Unix environment had a small
shell example. I don't remember if it handled loops, but it was a nice
piece of work as I recall.

Oct 12 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fraser Gordon | last post by:
Hello, Hopefully someone can help me out with this issue... I have a python script that needs to run a shell command and be able to react to output from that command as it occurs (as opposed...
7
by: Adam Hartshorne | last post by:
Hi All, I am looking for a c++ class or library that will handle command line parsing for me. Any such library is required to be able to work on both windows and linux hopefully without...
6
by: John Paulsson | last post by:
Is there a C# pattern or perhaps a .NET framework way of parsing a command lines, supporting quoted filepaths etc? (I'm not talking about the current applications command arguments. I've got...
1
by: Christoph Bisping | last post by:
Hello! Maybe someone is able to give me a little hint on this: I've written a vb.net app which is mainly an interpreter for specialized CAD/CAM files. These files mainly contain simple movement...
2
by: JaythePCguy | last post by:
Hi, I am trying to write a text parser to group all nonprintable and control characters, spaces and space delimited words in different groups using Regex class. Using a parsing of...
13
by: 31337one | last post by:
Hello everyone, I am writing an application that uses a command line interface. It will be configurable by passing arguments on the command line. The program is going to run in windows and...
4
by: Jim Langston | last post by:
In my program I am accepting messages over the network and parsing them. I find that the function that does this has gotten quite big, and so want to break the if else code into functions. I...
30
by: drhowarddrfine | last post by:
I'm working with a server that will provide me the pathname to a file, among many paths. So from getenv I may get /home/myweb/page1 but, of course, there will be many variations of that. I'm...
2
by: Andy | last post by:
Hi guys, I'm writing a program with a feature of accepting user input as command text and parsing it to correct function calls...example: "5 minutes later"/"5 min later"/"5 minute...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.