Expressions / String parsing
Posted on 2001-07-23
I'm having problem to make a scriptish class that
is suppose to parse string expressions into delphi.
This is what I had in mind:
I have a string, lets say:
myStr := '(("Variable1" = "Variable2") OR
("Variable3" <> "Variable4")) AND (Variable5 > 0)';
Of course, this string could contain any delphish expression, such as: (just examples)
myStr := '"Variable1" = "Variable2"';
myStr := '("Variable1" <> "Variable2") AND ("Variable3" = "Variable4")';
Ok, now you should have an idea on how the input string
to my class should look.
TExpressionParser is a class,
with the events:
Token2: String; var IsTrue: Boolean);
and the procedure:
What ParseExpression does is:
(this proc is called with myStr (see above) as parameter)
1) Parses the expression into many parts (i think
a tree like structure would fit here?)
2) On every expression, it is to raise the
OnCheckExpression with those parameter, where
Token1 is the left variable, Operator is the
operator ('>', '<>', '=' ..etc), Token2 is the
3) User sets IsTrue to whatever he/she wishes.
4) TExpressionParsers takes the respons from every
OnCheckExpression result and put it togheter
and return a final variable (by raising the OnComplete
event). TExpressionParsers should of course
use all logical operators (and, not, or...etc),
this should not be even showed to the user. (he is only
to answer if each expression is true or false!
So, I want to know how I make this class :]
I lack the skills to write the actual parsing &
tree structure thing; i hope anyone could help/hint
I will reward you well!