Re: Evaluate an string.
Posted in 1998
Art S. Kagel wrote: > > Juan Manuel Hernandez del Olmo wrote: > > > > Evaluate an string. > > ------------------------------ > > I would know if it is possible, in 4GL, to evaluate an string. For = > > example: > > > > If I have: > > > > let cad='var1+var2*var3' > > > > Could I get something like this: > > > > num=eval cad > > > > So, if var1,var2 and var3 are integers, and its values are 1,2 and 3, the = > > value of num would be 6. > > Actually 1+2*3 is either 7 or 9 depending on the order of evaluation. > Using standard rules that would be 7. > > Anyway... No you cannot do this. You will have to build your own > expression parser for this. > > Art S. Kagel You can build an expression parser with the Unix tools lex and yacc or their GNU equivalents. Read the book "Introduction to compiler construction with Unix" by A T Schreiener and H G Friedman Jr, 1985, Prentice Hall, ISBN 013474396-2. It will tell you all you need to know with the possible exception of how to code a stack machine evaluator but this is simple anyway. -- Peter Lancashire Information Systems Specialist, Bayer plc Eastern Way, Bury St Edmunds, Suffolk, IP32 7AH, UK Tel: +44-1635-562258, Fax: +44-1635-562281 --- If all else fails, read the instructions AND the release notes. All opinions are my own and not those of Bayer plc. My Internet plumbing does not allow me to mail and post news together. Sorry. --- Join Infuse, the UK Informix User Group at http://www.infuse.org.uk/