Solved

String passing problem

Posted on 2004-09-03
5
187 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 about my first experience with programming Arduino.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 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

26 Experts available now in Live!

Get 1:1 Help Now