CS110 Chapter Notes - Chapter 5: Finite-State Machine, Regular Expression, Eval
This document is a complement to part 5 of chapter 6, which discusses in details about the proposed prototype of regular expression pattern recognizer. Note that the prototype only accepts or rejects string pattern, instead of looking for all possible matches in a huge string. In this document, the source code will be explained in a top-down approach (i. e. from huge macros to tiny details) The proposed regular expression recognizer is basically a collection of functions in proper sequence (and therefore is a product of functional programming approach). The main function named eval, which takes in two parameters i. e. string to be analyzed and regular expression string, and returns integer (1=true, 0=false), contains five auxiliary functions namely eatsymbol, eatsymbols, postsymbol, postsymbols, and eval functions. Note that in this approach, the state/input map is updated once a token is retrieved (as opposed to gaining all tokens prior to analysis).