0

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?:?:

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by ExplainThat
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.