Lazarus
Home
Forum
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
fpExpressionParser
Downloads
Daily Snapshots
FAQ
Wiki
Bugtracker
IRC channel
Developer Blog
Follow us on Twitter
Mailing List
Free pascal
Other languages
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
About donations (wiki)
Bookstore
Lazarus, the complete guide
Search
Advanced search
« previous
next »
Print
Pages: [
1
]
Author
Topic: fpExpressionParser (Read 1162 times)
wp
Hero Member
Posts: 558
fpExpressionParser
«
on:
September 20, 2012, 12:36:39 am »
Two questions regarding fpExpressionParser:
Following the examples with the built-in functions I added a user-defined function "power" to the parser by calling "Identifiers.AddFunction('power', 'F', 'FF', @ExprPower)". The functions works fine as long as I use a floating point number for the exponent, i.e. "power(x, 2.0)" is ok, but with integer exponents (i.e. "power(x, 2)") I get the error that a float is expected. Is there a way to automatically convert integers to floats?
I'd like to add a new symbol "^" as a short-cut to the power function. Is this possible?
Logged
Lazarus trunk / fpc 2.6.2 / Win32
Leonor
New member
Posts: 16
Re: fpExpressionParser
«
Reply #1 on:
September 20, 2012, 01:19:02 am »
Hello wp, I don't know if there is a way to convert automatically integers to floats, but I do this way:
procedure integersToFloat(iValue: integer; var DblResult: Double);
var
VrnValue: Variant;
begin
VrnValue := iValue;
DblResult := VrnValue;
end;
Logged
Leledumbo
Hero Member
Posts: 4296
Programming + Glam Metal + Tae Kwon Do = Me
Re: fpExpressionParser
«
Reply #2 on:
September 20, 2012, 05:45:55 am »
Quote
I'd like to add a new symbol "^" as a short-cut to the power function. Is this possible?
Looking at the source code, it seems impossible. The operators are hardcoded and no user defined operator handling provided.
Logged
Want to get your questions answered quickly? Follow the guide:
http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F
http://pascalgeek.blogspot.com
https://bitbucket.org/leledumbo
https://github.com/leledumbo
Code first, think later - Natural pro
wp
Hero Member
Posts: 558
Re: fpExpressionParser
«
Reply #3 on:
September 20, 2012, 10:53:17 pm »
@Leonor: This is a stand-alone procedure (BTW: wouldn't a simple assignment "floatVariable := integerVariable" have the same effect?). I am seeking a way how to tell fpExpressionParser to do such a conversion internally.
It looks as if fpExpressionParser is not prepared for this feature. So it seems that I'll have to patch the sources.
Logged
Lazarus trunk / fpc 2.6.2 / Win32
marcov
Global Moderator
Hero Member
Posts: 1677
Re: fpExpressionParser
«
Reply #4 on:
September 21, 2012, 09:21:48 am »
Or use the "symbolic" expression parser.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
fpExpressionParser
Recent
property Showhint by defa...
by
Jurassic Pork
[
Today
at 01:32:21 am]
A feature for Lazarus?
by
Martin_fr
[
Today
at 01:26:01 am]
Binary Decimal Convertor ...
by
BenJones
[
Today
at 12:39:31 am]
string assignment on fpc ...
by
parcel
[May 22, 2013, 11:47:07 pm]
What did I do to Tortoise...
by
Avishai
[May 22, 2013, 10:20:58 pm]
Generics.Collections
by
mrmizak
[May 22, 2013, 10:05:57 pm]
Sniplet Ed v1.0
by
BenJones
[May 22, 2013, 09:23:33 pm]
Qt so slow
by
stocki
[May 22, 2013, 09:22:04 pm]
SOLVED where is the probl...
by
yanes19
[May 22, 2013, 09:18:17 pm]
How do I resolve Debbuger...
by
Martin_fr
[May 22, 2013, 09:03:12 pm]