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

String passing problem


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.

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

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

Any pointers would be highly appreciated.



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.

well rpn might inspire you :) the very firtst step to prasing

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 :)
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).

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.

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

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