+ - 0:00:00
Notes for current slide
Notes for next slide

Lexical Analysis - Part 2

CMPU 331 - Compilers

1 / 8

Update

  • Assignment 1 is posted on the calendar

  • The lexer project instructions are on the calendar and in GitHub

2 / 8

Finite-state machines

Remember finite-state machines from CMPU 240?

finite-state machines

  • Regular expressions are powerful, but can be slow (and memory-hungry)

  • One way of optimizing a lexer is to transform it into a DFA

3 / 8

Lexer Project

  • Accept the assignment in GitHub

    • Who will be working as pairs?
  • Clone the repository to your machine

    • Who will be working on their own laptop?
    • Do you have git and Python 3 installed already?
  • Add token definitions with regular expressions

  • Commit your changes, and push them back to GitHub

4 / 8

Python Flash Cards

5 / 8

Python Regular Expressions

  • . matches any character
  • * zero or more repetitions
  • + one or more repetitions
  • \d a digit
  • [a-z] a character class
  • \s a space
  • \t a tab
  • \n a newline
  • | alternation, like a|b
  • (...) a group, like (a | b)+
6 / 8

Python Regular Expressions

Characters with special meaning in regular expressions need to be escaped

  • \+ a literal plus character
  • \* a literal asterisk
  • \( literal open parentheses
  • \) literal close parentheses
  • \[ literal open square bracket
  • \] literal close square bracket
  • \{ literal open curly bracket
  • \} literal close curly bracket
7 / 8

Tour of SLY

8 / 8

Update

  • Assignment 1 is posted on the calendar

  • The lexer project instructions are on the calendar and in GitHub

2 / 8
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow