Solved

String passing problem

Posted on 2004-09-03
5
186 Views
Last Modified: 2013-11-18
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
Comment
Question by:swap0
5 Comments
 
LVL 37

Expert Comment

by:Harisha M G
ID: 11976361
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
 
LVL 3

Accepted Solution

by:
str_ek earned 63 total points
ID: 11976434
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
 
LVL 3

Assisted Solution

by:Validor
Validor earned 62 total points
ID: 11978046
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now