I usually use FSMs for fairly simple problems and choose them intuitively. Is the question "How do I choose the states and the transition conditions?", or "How do I implement my abstract state machine in Foo?" How do I choose the states and the transition conditions? It's not pretty (it doesn't have to be since it's not supposed to be read by humans, they're supposed to be looking at the lex/yacc code) but it may give you a better idea as to how they work. The best thing you could do is grab a copy of some lex/yacc (or equivalent) code for a specific simple language and see the code it generates. The actual finite state machine code required to do what a one-liner RE can do is usually very long and complex. It doesn't show how to do greedy/nongreedy matches, backtracking, matching within a line (instead of the whole line) and other more esoteric features of state machines that are easily handled by the RE syntax. Now, as I said, this is a very simple example. If char is not in the set "A-Z" or "a-z" or "0-9" or "_": If char is not in the set "A-Z" or "a-z": The following pseudo-code shows how this can be done with a finite state machine: state = FIRSTCHAR Which is a typical identifier (must start with alpha and can have any number of alphanumeric and undescore characters following, including none). Sure, although you'll need more complicated examples to truly understand how REs work.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |