Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to parse expression to see what it returns ?

Status
Not open for further replies.

Tilen

Programmer
Apr 2, 2005
75
SI
Hi

I need to write a procedure that would identify what would specific expression return, either string, number,date,boolean...

Example:

1+1 = number
'test' = string
12.02.2004 = date
FALSE = boolean

I think I can make it work for such simple expressions, but what about something like this:

IF(A=2,'number = 2','number <> 2')

returns string (this is simple expression, like in Excel)

I get expressions as strings.

Does anybody have any suggestions how can I parse the expression to see what the result is?


Thanx
 
Look at the use of the
val(s: var; V: var; code: integer)
procedure this is a safe way to test for numeric values.

Remember that pascal is a stronly typed language, in most cases if you pass a variable of the wrong type you will get an error, but you need to be more specific aboput what you want to do, when you say TRUE do you mean the text 'TRUE' or a boolean variable that could be true or false?



Steve:
A Delphi Programmer
 
As I was typing the message I kind of got the idea, how to do it.

The thing is, in expression there could also be variables. So, first I need to do is to delete all IF conditions and then check for any variable left in expression. Then the return value is almost 100% the same a variable type.
You can't mix integer and string and boolean without conversion functions.

Then I could check if there are any conversion functions, like StrToInt or IntToStr...

If there's no variable, next thing to check is if there is any text... 'my text'.. then result is almost sure a string. Again careful for conversions.

And so on...

It will be a long procedure but, not as complex as I thought.

Well, I'm just about to start, so I'll see if my theory works.

Yes, TRUE would be a text.. all expressions are as text/string.

Thanx anyway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top