Imagine analyzing an expression in a programming language:
x = a + b * 2;
When the lexical analysis is performed on this expression, the following sequence of tokens is produced:
[
(identifier, x),
(operator, =),
(identifier, a),
(operator, +),
(identifier, b),
(operator, *),
(literal, 2),
(separator, ;)
]
In essence, we dissect a mathematical equation into tokens such as x
, =
, a
, +
, b
, *
, 2
My task now is to tokenize a piece of text and have the program output the tokens. I attempted to achieve this, but encountered difficulties.