if i wanna read an input file with an equation in it, for example 2+3, and need to give the result of this input file, how should i write this code?:?:

Recommended Answers

All 4 Replies

up up

I hope I am understanding your question correctly. It seems to me that what you want to do is to evaluate an expression? If that is the case

  • The expression as it stands is merely a string.
  • You need to parse that expression - unlike VB and Javascript Delphi does not have a built in eval function. It is worth typing in eval Delphi in Google to see if it comes up with anything useful.
  • The technique for doing this is called Recursive Descent Parsing. I guess there is Pascal code for this somewhere out there.
  • My personal preference would be to convert the expression to Reverse Polish Notation and then evaluate that. This is a great deal more elegant - and faster. I have an RPN evaluator written up some where - if I can dig it up I'll post a copy here.

Hope this helps.

ExplainThat, this is a beginning programming school assignment. I really doubt the professor expects a recursive descent algorithm. Nor do I think he is permitted to redefine the shape of his input.

All the professor wants is some basic string parsing.

joygqy Show us some code, and we'll help you.

Could be - like I said, I was not sure I had understood the question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.