Please enable JavaScript.
Coggle requires JavaScript to display documents.
Lexical Analysis (Language (Elements (Set - collection of unique object,…
Lexical Analysis
Language
Formal Language
-
can be defined by a precise specification
Natural Language
-
cannot be defined perfectly with a precise specification system
Elements
Set - collection of unique object
String - list of characters from a given alphabet
Language - a set of string from a given alphabet
Regular Expression
1. Union - set which contains all elements in the two sets
Example : {abc, ab, ba} + {ba, bb} = {abc, ab, ba, bb}
2. Concatenation - combine two string to form a new string
Example : {ab, a, c} . {b, ε} = { ab.b, ab.ε, a.b, a.ε, c.b, c.ε} = {abb, ab, a, cb, c}
3. Kleene * - unary operation, often called closure
Implementation with FSM
Accept any identifiers beginning with a letter and followed by any number of letters and digits
Accepts numeric constants
Keyword recognizer
Finite State Machine
State Graph
State :
Transition function
Starting state
Accepting state
State Table
State names -> rows
Input symbol -> columns
Each entry -> next state of the machine given an input
Starting state -> first one in a row
Accepting state -> asterisk (*) :
Lexical Tokens
Words
Keywords
Identifiers
Operators
Numeric constant
Character constant
Special characters
Comments
White space
New line