Token Lexeme Pattern
Token Lexeme Pattern
Tokens
int (keyword), a(identifier), =(operator), 10(constant) and ;(punctuation-semicolon)
Answer – Total number of tokens = 5
Example 2:
int main() {
It is a sequence of
Token is basically a It specifies a
characters in the source
sequence of set of rules
code that are matched by
characters that are that a scanner
Definition given predefined language
treated as a unit as it follows to
rules for every lexeme to
cannot be further create a
be specified as a valid
broken down. token.
token.
it must start
with the
Interpretation
name of a variable, alphabet,
of type main, a
function, etc followed by
Identifier
the alphabet
or a digit.
Interpretation
all the operators are
of type +, = +, =
considered tokens.
Operator
each kind of
Interpretation punctuation is
of type considered a token. (, ), {, } (, ), {, }
Punctuation e.g. semicolon,
bracket, comma, etc.
any string of
characters
Interpretation a grammar rule or “Welcome to
(except ‘ ‘)
of type Literal boolean literal. GeeksforGeeks!”
between ” and
“