aspose file tools
The moose likes Beginning Java and the fly likes string translation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "string translation problem" Watch "string translation problem" New topic
Author

string translation problem

macca cronin
Greenhorn

Joined: Aug 05, 2004
Posts: 7
Hey there,

First off I'm really new to Java so please bear with me. I need to translate a line of text from one form to another. An example line segment has the following format:

" step(sent(1,A,B,vars(Na,Rv,ped(pk(B),cat(Na,A)))))"

This means that at step 1, A sends to B that which is contained in vars() i.e. Na, Rv and encryption of Na and A (concatenated) using B's public key [ped(pk(B),cat(Na,A))]

The output format I need is the following:

"Knows_B,time_1(Received(B,time_1,(Na,Rv,enc({Na,A},pk_B))))"

Basically this is the same information that is in the input format but I just need to translate it to the output format above i.e. 'knows_B' corresponds to 'B'; 'time_1' corresponds to '1'; 'ped' corresponds to 'enc'; 'pk(B)' corresponds to 'pk_B' and 'cat(Na,A)' corresponds to '{Na,A}'. I've tried using string tokenizers to extract the data from the input and thus build the output form, but I just haven't been able to extract the data properly. If anyone has the time could they perhaps give me an example of some code that might solve this problem.

If anyone needs more information regarding the input format and how it's related to the output format I will try and elaborate some more on their connection.

Please help!
Thanks a million.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Macca,

How about this:

It picks out the components you require, regardless of their length, as long as the basic format remains the same. It's a bit crude, I know but you can change it as you require.

If you want something more generic then you'll need to write a basic expression parser, which is not a trivial undertaking (a worthwhile exercise though). I would suggest identifying tokens such as function names, variable names, separators (comma) and delimiters (brackets) and pushing them onto a java.util.Stack for later processing.

However, your time may be better spent searching the web for the code for a simple expression parser.

Hope this helps.

Jules
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: string translation problem
 
Similar Threads
answers of the sample test
Query regarding XML/XSL
Data: Unexpected database access problem
Help! Problem with Encryption!
Wss4J Security question on Username Token