× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Techniques for variable field types in a subfile
  • From: "paul cunnane" <paul@xxxxxxxxxxx>
  • Date: Fri, 11 Aug 2000 09:46:39 +0100

> What's a finite state machine?

In this case, it's a routine to parse the numeric value from a formatted
string.  The value of each character is interpreted according to the state
the routine maintains; and the state is affected by the character just read.

Here's a quick example of a state machine to do this task.  This machine
reads the string from right to left, and maintains a state variable as well
as a number of work variables.

Suppose the string is '$12.50  ' (two trailing blanks).  The state would be
(say) 0, meaning we haven't started yet.  When you read the rightmost blank,
the state becomes 1, meaning 'trailing blanks'.  Reading the next blank
leaves the state alone.

Then you come to the zero.  At this point, you don't know if it is a decimal
or an integer, so you store it, and set the state to 2 -- reading an
indeterminate number.  Then you read the 5, store it as well, and leave the
state at 2.

Now comes the period.  At this point, you move the stored 50 to a decimal
storage area, with the value 0.5, and change the state to 3 -- reading the
integer portion.  Read the 2 and the 1, storing them, and leaving the state
at 3.  When you reach the currency symbol, the state is set to 99, meaning
that the value is complete, and you can add the 12 to the 0.5 to get your
result value.  You should keep reading, to check for errors.

This is a very incomplete description of the state machine you would need to
parse a formatted currency value.  Much error checking code is needed -- for
example, if you read a period in state 3 -- and there are many more states
than I have described above.  The best approach is to think of as many
states as possible, then create a matrix describing the result of reading
each type of character when in each state.  The good news is, you only have
to write it once, and put it in a service program.

I don't know if this explained anything, or just confused things further...

--
Paul


+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.