You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Announcement
Collapse
No announcement yet.
Discussion on Reverse Polish Notation (Sourcecode)
It looks pretty good imo, yet I only have PBCC3 so it doesn't run for me as is,
but it looks like it works, and a lot going on there, I assume you want honest critique
a honestly it looks like a powerful piece of code, yet I think it's overkill for parsing an equation, look at all the variables that need to be stored, which costs time,
what I think is most efficient is, since you have a limited number of alpha chars to parse, ie SIN, TAN, etc, we should hard code the filtering, ie (read it)
for SIN, for instance, on "S" jump to code to look for "I" next, if not "I" or no other alpha of interest, then "syntax error", etc, (resolving or terminating SIN w/ a "(", also allowing for the whitespace/s),
if you take care in spacing the jump distance in the source, the near jumps are superfast,
I now remember that i did have a more complete example running, I'll try to find tonight, anyway just some ideas, otherwise it looks good!
Steven,
Coding a math parser is indeed very complex. If you search the source code forum for 'math parser' you will find a couple of fairly complete parsers written in PB in 2003. I have not done much coding recently so my memory is not fresh but my parser converts input into Polish notation using a non-recursive process. For added speed the operators were recoded as numbers rather than strings. The whole algorithm was extremely fast. How it exactly works can only be understood by working an example through with pencil and paper and the code in front of you. Erik Christensen also wrote a very complete and elegant parser in PB.
Hope this helps.
Regards,
Gunar Zagars.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment