This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Need sample java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need sample java code" Watch "Need sample java code" New topic
Author

Need sample java code

S Srikanth
Greenhorn

Joined: Sep 09, 2002
Posts: 14
Hi,
I have a scenario as follows.

I have a formula say F1+F2+F3.
Where..
F1 = B1+B2
F2 = F6+B3
F3 = B4
F6 = F7+B5
F7 = B6

After substitution of these values my formula becomes B1+B2+B3+B4+B5+B6.

Like this there can be multiple levels of substitution. How to handle these kind of situations in a java program.

In Brief,
I need to write a java function which takes F1+F2+F3 as input and which gives B1+B2+B3+B4+B5+B6 as output.

Regds,
Srikanth
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24189
    
  34

Briefly, you need a parser which parses expressions into a tree structure, then evaluates/simplifies the tree, and then prints (or otherwise reports) the tree. The details are covered in any introductory book on compiler or parser writing, or the help docs for many "compiler-compilers" like ANTLR.


[Jess in Action][AskingGoodQuestions]
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Need sample java code
 
It's not a secret anymore!