CSE340 - Principles of
Programming Languages
Lecture 06:
Closing with Lexical Analysis
Javier Gonzalez-Sanchez
javiergs@asu.edu
BYENG M1-38
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4
Programming Assignment #1
?
70%
?
100%
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5
Programming Assignment #1
?
100%
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6
Programming Assignment #1
?
70%
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7
Programming Assignment #1
!  Firstname_Lastname_P1.zip
!  Compile and Run
!  Recognize BINARY
!  Recognize DELIMITER and OPERATOR
approx. 20%
!  Recognize INTEGER
!  Recognize OCTAL
!  Recognize HEXADECIMAL
!  Recognize IDENTIFIER
approx. 40%
!  Recognize STRING
!  Recognize CHAR
!  Recognize KEYWORD
!  Recognize FLOAT
approx. 40%
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8
Review | Lexical Analysis
Are the following STRINGS correct or not? Why?
!  000000005
!  000000009
!  000000009.1
!  000000005
!  000000005.1
!  0x0000002
!  0123456789
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9
Review | Lexical Analysis
Are the following STRINGS correct or not? Why?
!  1.2e---3++
!  $50
!  float ________________ = 5;
!  double x = 000000.1;
!  '''a'
!  '''b'
!  ''b'
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10
Review | Lexical Analysis
Are the following STRINGS correct or not? Why?
!  " a"
!  "Hello""world"
!  abc"Hello"
!  ''’
!  'x’
!  ’a'
!  ’w’
!  ""
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11
State Transition Table
for our Lexer
(step by step)
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12
BINARY
INTEGER
OCTAL
HEXADECIMAL
IDENTIFIER
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13
Lexer – Step by Step
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14
Lexer – Step by Step
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15
Lexer – Step by Step
1 = INTEGER
2 = INTEGER
3 = IDENTIFIER
5 = OCTAL
7 = INTEGER
8 = IDENTIFIER
9 = BINARY
10 = HEXADECIMAL
columns
[a-z] = [A] B [C-F] [G-W] X [Y-Z]
[a-f] = [A] B [C-F]
0
$
_
[1]
[2-7]
[8-9]
[A]
B
[C-F]
[G-W]
X
[Y-Z]
states
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16
Lexer – Step by Step
0 $ _ [1] [2-7] [8-9] A B [C-F] [G-W] X [Y-Z] ... Delimiter, operator,
whitespace, quotation
mark
S0! S1$ S3$ S3$ S2$ S2$ S2$ S3$ S3$ S3$ S3$ S3$ S3$ SE! Stop!
S1! S5$ SE! SE! S5$ S5$ SE! SE! S4$ SE! SE! S6$ SE! SE! Stop!
S2! S7$ SE! SE! S7$ S7$ S7$ SE! SE! SE! SE! SE! SE! SE! Stop!
S3! S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ SE! Stop!
S4! S9$ SE! SE! S9$ SE! SE! SE! SE! SE! SE! SE! SE! SE! Stop!
S5! S5$ SE! SE! S5$ S5$ SE! SE! SE! SE! SE! SE! SE! SE! Stop!
S6! S10$ SE! SE! S10$ S10$ S10$ S10$ S10$ S10$ SE! SE! SE! SE! Stop!
S7! S7$ SE! SE! S7$ S7$ S7$ SE! SE! SE! SE! SE! SE! SE! Stop!
S8! S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ SE! Stop!
S9! S9$ SE! SE! S9$ SE! SE! SE! SE! SE! SE! SE! SE! SE! Stop!
S10! S10$ SE! SE! S10$ S10$ S10$ S10$ S10$ S10$ SE! SE! SE! SE! Stop!
SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! Stop!
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17
Homework
Review Recursion
Solve the Problem Set #1 in preparation for your exam
CSE340 - Principles of Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Summer 2015
Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.

201505 CSE340 Lecture 06

  • 1.
    CSE340 - Principlesof Programming Languages Lecture 06: Closing with Lexical Analysis Javier Gonzalez-Sanchez javiergs@asu.edu BYENG M1-38 Office Hours: By appointment
  • 2.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 4 Programming Assignment #1 ? 70% ? 100%
  • 3.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 5 Programming Assignment #1 ? 100%
  • 4.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 6 Programming Assignment #1 ? 70%
  • 5.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 7 Programming Assignment #1 !  Firstname_Lastname_P1.zip !  Compile and Run !  Recognize BINARY !  Recognize DELIMITER and OPERATOR approx. 20% !  Recognize INTEGER !  Recognize OCTAL !  Recognize HEXADECIMAL !  Recognize IDENTIFIER approx. 40% !  Recognize STRING !  Recognize CHAR !  Recognize KEYWORD !  Recognize FLOAT approx. 40%
  • 6.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 8 Review | Lexical Analysis Are the following STRINGS correct or not? Why? !  000000005 !  000000009 !  000000009.1 !  000000005 !  000000005.1 !  0x0000002 !  0123456789
  • 7.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 9 Review | Lexical Analysis Are the following STRINGS correct or not? Why? !  1.2e---3++ !  $50 !  float ________________ = 5; !  double x = 000000.1; !  '''a' !  '''b' !  ''b'
  • 8.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 10 Review | Lexical Analysis Are the following STRINGS correct or not? Why? !  " a" !  "Hello""world" !  abc"Hello" !  ''’ !  'x’ !  ’a' !  ’w’ !  ""
  • 9.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 11 State Transition Table for our Lexer (step by step)
  • 10.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 12 BINARY INTEGER OCTAL HEXADECIMAL IDENTIFIER
  • 11.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 13 Lexer – Step by Step
  • 12.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 14 Lexer – Step by Step
  • 13.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 15 Lexer – Step by Step 1 = INTEGER 2 = INTEGER 3 = IDENTIFIER 5 = OCTAL 7 = INTEGER 8 = IDENTIFIER 9 = BINARY 10 = HEXADECIMAL columns [a-z] = [A] B [C-F] [G-W] X [Y-Z] [a-f] = [A] B [C-F] 0 $ _ [1] [2-7] [8-9] [A] B [C-F] [G-W] X [Y-Z] states
  • 14.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 16 Lexer – Step by Step 0 $ _ [1] [2-7] [8-9] A B [C-F] [G-W] X [Y-Z] ... Delimiter, operator, whitespace, quotation mark S0! S1$ S3$ S3$ S2$ S2$ S2$ S3$ S3$ S3$ S3$ S3$ S3$ SE! Stop! S1! S5$ SE! SE! S5$ S5$ SE! SE! S4$ SE! SE! S6$ SE! SE! Stop! S2! S7$ SE! SE! S7$ S7$ S7$ SE! SE! SE! SE! SE! SE! SE! Stop! S3! S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ SE! Stop! S4! S9$ SE! SE! S9$ SE! SE! SE! SE! SE! SE! SE! SE! SE! Stop! S5! S5$ SE! SE! S5$ S5$ SE! SE! SE! SE! SE! SE! SE! SE! Stop! S6! S10$ SE! SE! S10$ S10$ S10$ S10$ S10$ S10$ SE! SE! SE! SE! Stop! S7! S7$ SE! SE! S7$ S7$ S7$ SE! SE! SE! SE! SE! SE! SE! Stop! S8! S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ S8$ SE! Stop! S9! S9$ SE! SE! S9$ SE! SE! SE! SE! SE! SE! SE! SE! SE! Stop! S10! S10$ SE! SE! S10$ S10$ S10$ S10$ S10$ S10$ SE! SE! SE! SE! Stop! SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! SE! Stop!
  • 15.
    Javier Gonzalez-Sanchez |CSE340 | Summer 2015 | 17 Homework Review Recursion Solve the Problem Set #1 in preparation for your exam
  • 16.
    CSE340 - Principlesof Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Summer 2015 Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.