Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UP Lecture 05

UP Lecture 05

Compilers
Regular Expressions
(202402)

Javier Gonzalez-Sanchez

December 08, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. Dr. Javier Gonzalez-Sanchez | Compilers | 4 jgs Keywords Lexical

    Alphabet Symbol String Word Token Rules Regular Expression Deterministic Finite Automata
  2. Dr. Javier Gonzalez-Sanchez | Compilers | 5 jgs Key Ideas

    Lexical Alphabet Symbol String Word Token Rules Regular Expression Deterministic Finite Automata
  3. Dr. Javier Gonzalez-Sanchez | Compilers | 6 jgs Homework Programming

    Assignment #1 Develop a Lexical Analyzer by coding a DFA
  4. Dr. Javier Gonzalez-Sanchez | Compilers | 7 jgs Key Ideas

    Lexical Alphabet Symbol String Word Token Rules Regular Expression Deterministic Finite Automata
  5. Dr. Javier Gonzalez-Sanchez | Compilers | 9 jgs Regular expression

    § A rule to describe finite combinations of symbols (sequences) that are considered well-formed. § Regular expression has symbols and operators. § Symbols are defined in the alphabet. § The operators used in regular expressions are: § * (0 or more), § + (1 or more), § ? (0 or 1), § | (or). § [ ] to enclose sets of symbols without enumerating all of them, such as [0- 9] or [A-Z]. § Parenthesis.
  6. Dr. Javier Gonzalez-Sanchez | Compilers | 10 jgs Regular expression

    | Examples Token Regular Expression (rule) Examples (words) foobarOne (a | b) {a, b} foobarTwo (a | b)(a | b) {aa, bb, ba, ab} foobarThree a* { , a, aa, aaa, aaaa, ... } foobarFour (a | b)* { , a, b, aa, bb, ...abba ...} foobarFive a+ { a, aa, aaa, aaaa, ... } foobarSix [a-z]+ {hello, world, etc, …} number [0-9]+ {1934, 0101, 33, 12321…}
  7. Dr. Javier Gonzalez-Sanchez | Compilers | 11 jgs Regular expression

    | Examples * These definitions are NOT fully complete or correct. The purpose is only to exemplify RE. For instance, 07 matches as an integer, which will NOT be the case for our language. Token1 Regular Expression (rule) Example (word) digit 0 | 1 | 2 | 3 | ... | 9 3 integer digit+ 1945 fraction .digit+ .55 exponent e(+|-)?digit+ e+210 floatDraftOne integer(fraction?) (exponent?) 340.08e-14 floatDraftTwo {[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)([eE][-+]?[0- 9]+)?} binary 0b(0|1)+ 0b1010
  8. Dr. Javier Gonzalez-Sanchez | Compilers | 14 jgs Handwritten notes

    Regular expression Regular expression Regular expression
  9. Dr. Javier Gonzalez-Sanchez | Compilers | 16 jgs Handwritten notes

    Is this correct? Is this correct? Is this correct?
  10. Dr. Javier Gonzalez-Sanchez | Compilers | 19 jgs Regular expressions

    - Examples Define a regular expression for each case a) URLs a) Email addresses a) ZIP codes
  11. Dr. Javier Gonzalez-Sanchez | Compilers | 20 jgs DFA- Examples

    Define a DFA for each case a) URLs a) Email addresses a) ZIP codes
  12. jgs Compilers Javier Gonzalez-Sanchez, Ph.D. [email protected] Spring 2024 Copyright. These

    slides can only be used as study material for the Compilers course at Universidad Panamericana. They cannot be distributed or used for another purpose.