The joy of lex Or: How I learned to stop worrying and love the deterministic, finite-state automaton...

Slides:



Advertisements
Similar presentations
1 Week 2 Questions / Concerns Schedule this week: Homework1 & Lab1a due at midnight on Friday. Sherry will be in Klamath Falls on Friday Lexical Analyzer.
Advertisements

4b Lexical analysis Finite Automata
Lecture 16 Deterministic Turing Machine (DTM) Finite Control tape head.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Lecture 6 Nondeterministic Finite Automata (NFA)
Finite Automata CPSC 388 Ellen Walker Hiram College.
Lexical Analysis (4.2) Programming Languages Hiram College Ellen Walker.
Chapter Section Section Summary Set of Strings Finite-State Automata Language Recognition by Finite-State Machines Designing Finite-State.
Lexical Analysis III Recognizing Tokens Lecture 4 CS 4318/5331 Apan Qasem Texas State University Spring 2015.
Transparency No. 2-1 Formal Language and Automata Theory Chapter 2 Deterministic Finite Automata (DFA) (include Lecture 3 and 4)
Lexing & Parsing (the intro version). What you have Input is string (via JTextField.getText() ) “(Lane OR Brown) AND (CS351 OR Java)” Useful to transform.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
Java Puzzlers. Administrivia Reminder: Final exam Can replace final w/ midterm if you warn me Reminder: Final project One group still needs to schedule.
Finite Automata Chapter 5. Formal Language Definitions Why need formal definitions of language –Define a precise, unambiguous and uniform interpretation.
Grammars, Languages and Finite-state automata Languages are described by grammars We need an algorithm that takes as input grammar sentence And gives a.
Automata and Regular Expression Discrete Mathematics and Its Applications Baojian Hua
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 3 Lexical and Syntactic Analysis Syntactic.
Lecture 3 Graph Representation for Regular Expressions
1 Scanning Aaron Bloomfield CS 415 Fall Parsing & Scanning In real compilers the recognizer is split into two phases –Scanner: translate input.
Rosen 5th ed., ch. 11 Ref: Wikipedia
CPSC 388 – Compiler Design and Construction Scanners – Finite State Automata.
Finite-State Machines with No Output Longin Jan Latecki Temple University Based on Slides by Elsa L Gunter, NJIT, and by Costas Busch Costas Busch.
Finite-State Machines with No Output
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions.
AUTOMATA THEORY Reference Introduction to Automata Theory Languages and Computation Hopcraft, Ullman and Motwani.
Object-Oriented Modeling Using UML CS 3331 Section 2.3 of Jia 2003.
Lexical Analysis Constructing a Scanner from Regular Expressions.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 3, 09/11/2003 Prof. Roy Levow.
Introduction to Sequential Logic Design Finite State-Machine Design.
TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA Class date : 12 August, 2013 Prepared by : Karimgailiu R Panmei Roll no. : 11CS10020 GROUP.
CS 536 Fall Scanner Construction  Given a single string, automata and regular expressions retuned a Boolean answer: a given string is/is not in.
1 Languages and Compilers (SProg og Oversættere) Lexical analysis.
Lexical Analysis: Finite Automata CS 471 September 5, 2007.
CS 153: Concepts of Compiler Design October 10 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CSc 453 Lexical Analysis (Scanning)
Finite State Machines CS147 : Presentation by Mabel Thong (9/25/07)
The Endgame These FAQs will be posted and updated as new information comes in. This is as of 12/2/2013. This is all subject to revision. Here are some.
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
State Machines State diagrams SE-2030 Dr. Mark L. Hornick 1.
4) Design the logic to control the motor on a simple remote control car. There are two buttons on the remote control for the motor. If neither button is.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
BİL711 Natural Language Processing1 Regular Expressions & FSAs Any regular expression can be realized as a finite state automaton (FSA) There are two kinds.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Department of Software & Media Technology
Finite-State Machines (FSM) Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth Rosen.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Lecture 2 Lexical Analysis
Chapter 2 Scanning – Part 1 June 10, 2018 Prof. Abdelaziz Khamis.
CSc 453 Lexical Analysis (Scanning)
Finite-State Machines (FSMs)
Lexical analysis Finite Automata
Lecture2 Regular Language
CS 153: Concepts of Compiler Design October 17 Class Meeting
CSc 453 Lexical Analysis (Scanning)
Finite-State Machines (FSMs)
CMPE 152: Compiler Design December 5 Class Meeting
Two issues in lexical analysis
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Finite Automata.
Finite Automata.
4b Lexical analysis Finite Automata
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
4b Lexical analysis Finite Automata
CMPE 152: Compiler Design March 19 Class Meeting
CSc 453 Lexical Analysis (Scanning)
Automata theory and formal languages COS 3112 – AUTOMATA THEORY PRELIM PERIOD WEEK 1 AND 2.
Presentation transcript:

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. 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

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...

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.

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

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

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

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...

Diagrams to code Representation of states: int (byte, long, etc.): unique code for each state enum general objects

Diagrams to code Representation of inputs: int/char/etc.: unique code for each input enum/general object/etc.

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];

Example code: Table-driven finite state machines for lexical analysis

Analysis of table-driven FSA ✓ Define Defend Attack