• Post Reply Bookmark Topic Watch Topic
  • New Topic

Content interpreter  RSS feed

 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a string say "1+(2+3)" which i want to evaluate. Are there any in built,ready made Java classes that can be used here?
Or do i have to parse it individually?
 
Tanu Gulati
Ranch Hand
Posts: 113
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when it is already a string it is one object and can not be used for evaluating as such. since +,( are not the arithmatic symbols here they are just the characters that put together form a string.

i belive you should parse it and then do the evaluation/arithmatic on it.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are lots of parsers available written in Java. For bottom-up parsing try a combination of JFlex and CUP. For top-down parsing try ANTLR.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!