Results 1 to 7 of 7
Thread: Unknown Variable Types
- 10-22-2010, 08:08 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
Unknown Variable Types
Alright, I'm not sure how to explain this clearly, but I'll give it a shot.
I want to make a program that will tell me the molar mass of molecules. I don't know how separate whether an integer or a variable will come next.
For instance, I give all my elements values, like
double c = 12;
couble h = 1;
double o = 16;
I don't know how to make the program know how to evaluate a person inputting H2O as well as doing OH. How can I make it take the number in the middle?
Idk, I know I'm not too clear with this and I don't have any code to show you because honestly I don't know where to start.
- 10-22-2010, 10:05 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
You don't actually know whether a digit or a letter will come next. For a very simple case you could work along a string like "H2SO4" and test each character to see if it is a letter or a digit.
For more complex cases (integer values represented by multiple digits, lower case letters, parentheses) you are trying to tokenize and parse the string. This is fun, but may be beyond where you are now.
It might be best to describe the range of molecular expressions you are trying to work with.
- 10-23-2010, 06:38 AM #3
The parser had better be case-sensitive, or sodium will break down into nitrogen and argon ;)
db
- 10-23-2010, 08:24 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
True ;-) I forgot most of those molecular expressions so here is a very simple question: do those numbers bind to the last atom or to a latest molecular sub-structure? e.g. in H2SO4 does the '4' bind to the right most 'O' or can it also bind to the group 'SO'? (I know here it binds to the single O, but it's just an example). Do parentheses occur in those expressions? If not, the parsing of such expressions is simple: {<atom><number>?}+
kind regards,
Jos
- 10-25-2010, 04:27 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
I think they are simple enough to do this. How do I test each character to tell if is a letter or a digit?You don't actually know whether a digit or a letter will come next. For a very simple case you could work along a string like "H2SO4" and test each character to see if it is a letter or a digit.
- 10-25-2010, 04:43 AM #6
- 10-25-2010, 04:44 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
Similar Threads
-
variable number of fields with different types
By Sir G. in forum Advanced JavaReplies: 11Last Post: 03-29-2010, 12:40 AM -
nextInt(unknown source)
By babyburger in forum New To JavaReplies: 3Last Post: 03-18-2010, 04:03 PM -
Dynamic types for a variable.
By Somelauw in forum New To JavaReplies: 5Last Post: 11-27-2009, 10:38 AM -
Unknown design pattern
By Steve11235 in forum Advanced JavaReplies: 4Last Post: 07-02-2009, 12:40 PM -
Unknown problem
By sanchir0805 in forum New To JavaReplies: 4Last Post: 03-20-2009, 03:56 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks