Download presentation
Presentation is loading. Please wait.
Published byBeverley Cummings Modified over 9 years ago
1
The joy of lex Or: How I learned to stop worrying and love the deterministic, finite-state automaton...
2
Administrivia Reminder: schedule rollout meeting w/ me & Blake During finals week Allow ~1.5 hours for presentation, demos, code walk-through, doc reviews, etc. Everything must be completed by noon, Friday Dec 15 Slots are first-come, first-served Reminder: final exam 12:30-2:30 PM, Tues Dec 12
3
Historical review Last Thursday: Thanksgiving! Hope you all had excellent chow and good family time. Before that: Thinking about the timer design Use of finite state machine in P2 design Today: Finite state machines in (some) detail...
4
Finite State Machines Mathematical abstraction for thinking about how a process works Processing data stream to identify regular expressions States of assembly line activity in GrellSim Many consumer electronics (DVD, VCR, cruise controls, alarm clocks, etc.) UNIT behaviors in JCiv... AKA: Finite state automata (FSA), DFA, et al.
5
Example: Cruise control Car’s cruise control can on or off Hit button to turn on Hit off button or press brake to turn off Have to enable the CC system before you can activate CC Separate button to enable/disable Stays enabled even if CC is off
6
The state diagram Disable d; off Enabled ; off enable button disable button Enabled ; on on button off button brake disable button on/off/ brake/ disable off/ brake/ enable on/ enable
7
Key characteristics Finite set of states Have to completely characterize all possibilities Finite set of inputs A.k.a., characters Transition function For each state/input pair: next state Finite set of actions
8
Designing w/ FSAs Decide what states are necessary E.g., idle, working-on-job, about-to-start-job Work out all possible inputs/characters E.g., all ASCII chars, job completion events, etc. Draw state transition diagram MUST account for all states and all inputs for every state Turn diagram into code...
9
Diagrams to code Representation of states: int (byte, long, etc.): unique code for each state enum general objects
10
Diagrams to code Representation of inputs: int/char/etc.: unique code for each input enum/general object/etc.
11
Diagrams to code Hard part: representing transition function “for each state and input pair, return the next state” Could do it with a big series of if/case statements Ugh... “Classical” FSA code: use a 2-d array (table) next_state=table[curr_state][input];
12
Example code: Table-driven finite state machines for lexical analysis
13
Analysis of table-driven FSA ✓ Define Defend Attack
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.