parsing a command

J

junky_fellow

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 .....
 
S

Samuel Stearley

Be creative.
If you're re-inventing the wheel for the sake of learning why concern
yourself with what other people have done?
 
M

Malcolm

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.
 
S

Spiritus

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...
 
M

Malcolm

Spiritus said:
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.
 
J

junky_fellow

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 ?
 
M

mark_bluemel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,371
Latest member
TroyHursey

Latest Threads

Top