1 / 13

The joy of lex

The joy of lex. Or : How I learned to stop worrying and love the deterministic, finite-state automaton. Administrivia. Reminder: schedule rollout meeting w/ me & Blake During finals week Allow ~1.5 hours for presentation, demos, code walk-through, doc reviews, etc.

delora
Download Presentation

The joy of lex

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. enable button on/ enable disable button off/ brake/ enable on/off/ brake/ disable off button brake disable button on button Enabled; on The state diagram Disabled; off Enabled; off

  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

More Related