• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

String passing problem

Hi,

I  am building a search appln.
I need to have a function in C which will break down the user input into multiple searches, which are independent, so that they could be looked at in parallel.

Eg:
(Good OR bad) boy
must evaluate to:
Good boy
bad boy

(Good OR bad) boy OR girl
must evaluate to
Good boy
bad boy
girl


Any pointers would be highly appreciated.

Thanks,

Swap


0
swap0
Asked:
swap0
2 Solutions
 
Harisha M GCommented:
This Problem can be tackled easily with the help of STACKs.
Read DATA STRUCTURES carefully. You will come to know how to implement that by yourself.

Bye!
0
 
str_ekCommented:
well rpn might inspire you :) the very firtst step to prasing
http://www.hpmuseum.org/rpn.htm
http://en.wikipedia.org/wiki/Reverse_Polish_Notation

the problem you gave can be evaluated using stack+rpn to get or(+) and(*) and () work the way you want...

you need to get reed of () and simpy read the outputed anded (*) ansers separated by or(+)

it's real a gramary problem :)
0
 
ValidorCommented:
The task is in parsing.  You have to define a grammar that will be parsed.  You then need to express the grammer in a Backus-Naur form, also called a context-free grammar.  Given that, you can build a translator from a top-down recursive-descent parser.  There are other ways, but this is probably the easiest to understand.  

There are some excellent papers on this by Jack Crenshaw (pascal).
http://compilers.iecc.com/crenshaw/

There is also a bit of this in several Herbert Schildt books, including "The craft of C".

Finally, here is a free definitive work on parsing and Grammar.
http://www.cs.vu.nl/~dick/PTAPG.html

If this is all too much, you might want to consider downloading some compiler constructors such as YACC and LEX, or BISON and FLEX.  Feed them the grammar and they will try to build the parser code for you.  It doesn't have to be a programming language, mind you.  Anything that you can express the grammar for will work.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now