Solved

String passing problem

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about problems I had with the new location API and permissions in Marshmallow
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

770 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