Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ Programming ➜ General ➜ Parsing Compile

Parsing Compile

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Thierry   (5 posts)  Bio
Date Mon 09 Nov 2015 06:10 AM (UTC)
Message
Hello

I use Parser since 2 or 2 years in a data acquisition program and it works fine. I'm currently developing the new release and I need to parse several expression with dynamic variables up to 20 times per second.

I'd like to modify the parser as to pre-compile the expression to avoid useless re-parsing every time I need to evaluate the expressions (up to 128 expressions, 20 times per second means too much time ..)

Can you give some clues on how to do that ?

Thanks for sharing this excellent piece of code

Thierry
Top

Posted by Fiendish   USA  (2,555 posts)  Bio   Global Moderator
Date Reply #1 on Mon 09 Nov 2015 08:29 AM (UTC)
Message
Hiya. Can you link to what you're talking about so people don't have to go digging for it?

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Mon 09 Nov 2015 09:04 AM (UTC)
Message
I presume the question refers to this:

http://www.gammon.com.au/forum/?id=4649




Quote:

I'd like to modify the parser as to pre-compile the expression to avoid useless re-parsing every time I need to evaluate the expressions ...


You may well like to do this, but the parser is specifically written as something that evaluates at run-time. To "modify" it is to completely rewrite it.

You could conceivably (and with considerable effort) rewrite to pre-compile functions into pseudo-code (P-code) and then evaluate them as a separate operation.

However this goes well beyond the scope of a simple modification.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Mon 09 Nov 2015 08:09 PM (UTC)
Message
Can you give examples of the sorts of expressions you are evaluating? Perhaps hard-coded C functions can do it, if you are only varying parameters to the function.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Thierry   (5 posts)  Bio
Date Reply #4 on Mon 09 Nov 2015 09:28 PM (UTC)
Message
Hello Nick

The application I'm working on is called Genesis. It's an OPC Client used to acquire data on process machines (mainly PLCs and DCS). Genesis allows the user to compute derived data from acquired data.
As such, any expression are added by the user. I already add some standard function as a scaling function but users are free to build up any kind of expression.

That where your parser is shining. It works fine for the purpose. With current version, the minimum rate of acquisition is 1 second. Several users ask me to reduce this limit. Now (in the release 3.0 still in preparation) it goes down to 50 ms (and I try to go to 25 ms). At such speed, I need to gain time everywhere as Genesis acquires data, compute derived data, stored all these data in a SQL data, displays the data in List and in Chart. A quite busy processor at 50 ms....

Thierry
www.tgmdev.be
Top

Posted by Thierry   (5 posts)  Bio
Date Reply #5 on Sun 15 Nov 2015 09:54 AM (UTC)
Message
Hello Nick

I wrote a test application to check an extended parser that fits my needs for Genesis: obtaining symbols value from the caller (and not from the parser) and using pre-compiled expression.
I got the very first result.
* Time for evaluating 10 expressions: about 100 ms
* Time for evaluation pre-compiled expressions: about 5 ms

I extend your parser to get a list of tokens and, using the same function hierarchy, I basically replace GetToken by a simple read of the token list.

I still need to work on it but it looks promising.

Thierry
www.tgmdev.be
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #6 on Sun 15 Nov 2015 08:25 PM (UTC)
Message
That sounds like a good start. If you pre-parse the string into tokens that you have removed most of the string-matching, so the execution should be somewhat faster.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


27,481 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.