-4

Possible Duplicate:
Evaluating a math expression given in string form

How can I convert a string representing a math expression, like "1+23-56," into a number? I am trying to do this in Java.

Community
  • 1
  • 1

1 Answers1

1

You would have to create your own language specification, with your own grammar and then implement it, there are several examples of how to write a language for a calculator.

The basic principle is to first do a syntax analisis, generate a syntactic tree and the parse it using your language rules, the semantic analisis.

Here are some examples:

danielrvt
  • 10,177
  • 20
  • 80
  • 121