Lexical analysis
Lexical tokenization is conversion of a text into (semantically or syntactically) meaningful lexical tokens belonging to categories defined by a "lexer" program.[src] In case of a natural language, those categories include nouns, verbs, adjectives, punctuations etc.[src] In case of a programming language, the categories include identifiers, operators, grouping symbols, data types and language keywords.[src] Lexical tokenization is related to the type of tokenization used in large language models (LLMs) but with two differences.[9] First, lexical tokenization is usually based on a lexical grammar, whereas LLM tokenizers are usually probability-based.[src] Second, LLM tokenizers perform a second step that converts the tokens into numerical values.[src]
Lexical tokenization is conversion of a text into (semantically or syntactically) meaningful lexical tokens belonging to categories defined by a "lexer" program.[src] In case of a natural language, those categories include nouns, verbs, adjectives, punctuations etc.[src] In case of a programming language, the categories include identifiers, operators, grouping symbols, data types and language keywords.[src] Lexical tokenization is related to the type of tokenization used in large language models (LLMs) but with two differences.[9] First, lexical tokenization is usually based on a lexical grammar, whereas LLM tokenizers are usually probability-based.[src] Second, LLM tokenizers perform a second step that converts the tokens into numerical values.[src] == Lexical token and lexical tokenization== A lexical token is a string with an assigned and thus identified meaning, in contrast to the probabilistic token used in large language models.[9] A lexical token consists of a token name and an optional token value.[src] The token name is a category of a rule-based lexical unit.[src] Consider this expression in the C programming language: The lexical analysis of this expression yields the following sequence of tokens: A token name is what might be termed a part of speech in linguistics.[9] Lexical tokenization is the conversion of a raw text into (semantically or syntactically) meaningful lexical tokens, belonging to categories defined by a "lexer" program, such as identifiers, operators, grouping symbols, and data types.[src] The resulting tokens are then passed on to some other form of processing.[src] The process can be considered a sub-task of parsing input.[src] For example, in the text string: The quick brown fox jumps over the lazy dog the string is not implicitly segmented on spaces, as a natural language speaker would do.[src] The raw input, the 43 characters, must be explicitly split into the 9 tokens with a given space delimiter (i.e., matching the string " " or regular expression ).[src] When a token class represents more than one possible lexeme, the lexer often saves enough information to reproduce the original lexeme, so that it can be used in semantic analysis.[src] The parser typically retrieves this information from the lexer and stores it in the abstract syntax tree.[src] This is necessary in order to avoid information loss in the case where numbers may also be valid identifiers.[src] Tokens are identified based on the specific rules of the lexer.[src] Some methods used to identify tokens include regular expressions, specific sequences of characters termed a flag, specific separating characters called delimiters, and explicit definition by a dictionary.[src] Special characters, including punctuation characters, are commonly used by lexers to identify tokens because of their natural use in written and programming languages.[src] A lexical analyzer generally does nothing with combinations of tokens, a task left for a parser.[src] For example, a typical lexical analyzer recognizes parentheses as tokens but does nothing to ensure that each "(" is matched with a ")".[src] When a lexer feeds tokens to the parser, the representation used is typically an enumerated type, which is a list of number representations.[src] For example, "Identifier" can be represented with 0, "Assignment operator" with 1, "Addition operator" with 2, etc.[src] Tokens are often defined by regular expressions, which are understood by a lexical analyzer generator such as lex, or handcoded equivalent finite-state automata.[src] The lexical analyzer (generated automatically by a tool like lex or hand-crafted) reads in a stream of characters, identifies the lexemes in the stream, and categorizes them into tokens.[src] This is termed tokenizing.[src] If the lexer finds an invalid token, it will report an error.[src] Following tokenizing is parsing.[src] From there, the interpreted data may be loaded into data structures for general use, interpretation, or compiling.[src] Algorithms + Data Structures = Programs, Niklaus Wirth, 1975, Compiler Construction, Niklaus Wirth, 1996, Sebesta, R.[src] W.[src] (2006).[src] Concepts of programming languages (Seventh edition) pp. 177.[src] Boston: Pearson/Addison-Wesley.[src]
42 sentences · 42 cited inline · 9 references stored
References
- Anatomy of a Compiler and The Tokenizer . www.cs.man.ac.uk . · retrieved 2026-08-21 · rev 1370769639
Cite this reference
MLA "Anatomy of a Compiler and The Tokenizer . www.cs.man.ac.uk ." Anatomy of a Compiler and The Tokenizer. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639. Accessed 28 November 2026.
Chicago "Anatomy of a Compiler and The Tokenizer . www.cs.man.ac.uk ." Anatomy of a Compiler and The Tokenizer. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639.
APA Anatomy of a Compiler and The Tokenizer. (2026). Anatomy of a Compiler and The Tokenizer . www.cs.man.ac.uk . Retrieved November 28, 2026, from https://en.wikipedia.org/w/index.php?oldid=1370769639
- Compilers Principles, Techniques, & Tools, 2nd Ed. · retrieved 2026-08-21 · rev 1370769639
Cite this reference
MLA "Compilers Principles, Techniques, & Tools, 2nd Ed." page 111, "Compilers Principles, Techniques, & Tools, 2nd Ed. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639. Accessed 28 November 2026.
Chicago "Compilers Principles, Techniques, & Tools, 2nd Ed." page 111, "Compilers Principles, Techniques, & Tools, 2nd Ed. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639.
APA page 111, "Compilers Principles, Techniques, & Tools, 2nd Ed. (2026). Compilers Principles, Techniques, & Tools, 2nd Ed. Retrieved November 28, 2026, from https://en.wikipedia.org/w/index.php?oldid=1370769639
- Structure and Interpretation of Computer Programs . mitpress.mit.edu . retrieved 2009-03-07 · retrieved 2009-03-06 · rev 1370769639
Cite this reference
MLA "Structure and Interpretation of Computer Programs . mitpress.mit.edu . retrieved 2009-03-07." Structure and Interpretation of Computer Programs. 2009-03-06. https://en.wikipedia.org/w/index.php?oldid=1370769639. Accessed 28 November 2026.
Chicago "Structure and Interpretation of Computer Programs . mitpress.mit.edu . retrieved 2009-03-07." Structure and Interpretation of Computer Programs. 2009-03-06. https://en.wikipedia.org/w/index.php?oldid=1370769639.
APA Structure and Interpretation of Computer Programs. (2009). Structure and Interpretation of Computer Programs . mitpress.mit.edu . retrieved 2009-03-07. Retrieved November 28, 2026, from https://en.wikipedia.org/w/index.php?oldid=1370769639
- Huang, C., Simon, P., Hsieh, S., & Prevot, L. (2007) [http://www.aclweb.org/anthology/P/P07/P07-2018.pdf Rethinking Chinese Word Segmentation: Tokenization, Character Classification, or Word break Ide . · retrieved 2026-08-21 · rev 1370769639
Cite this reference
MLA "Huang, C., Simon, P., Hsieh, S., & Prevot, L. (2007) [http://www.aclweb.org/anthology/P/P07/P07-2018.pdf Rethinking Chinese Word Segmentation: Tokenization, Character Classification, or Word break Ide ." Huang, C. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639. Accessed 28 November 2026.
Chicago "Huang, C., Simon, P., Hsieh, S., & Prevot, L. (2007) [http://www.aclweb.org/anthology/P/P07/P07-2018.pdf Rethinking Chinese Word Segmentation: Tokenization, Character Classification, or Word break Ide ." Huang, C. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639.
APA Huang, C. (2026). Huang, C., Simon, P., Hsieh, S., & Prevot, L. (2007) [http://www.aclweb.org/anthology/P/P07/P07-2018.pdf Rethinking Chinese Word Segmentation: Tokenization, Character Classification, or Word break Ide . Retrieved November 28, 2026, from https://en.wikipedia.org/w/index.php?oldid=1370769639
- [https://www.gnu.org/software/bash/manual/bashref.html Bash Reference Manual], [https://www.gnu.org/software/bash/manual/bashref.html#Escape-Character 3.1.2.1 Escape Character] . · retrieved 2026-08-21 · rev 1370769639
Cite this reference
MLA "[https://www.gnu.org/software/bash/manual/bashref.html Bash Reference Manual], [https://www.gnu.org/software/bash/manual/bashref.html#Escape-Character 3.1.2.1 Escape Character] ." https://www. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639. Accessed 28 November 2026.
Chicago "[https://www.gnu.org/software/bash/manual/bashref.html Bash Reference Manual], [https://www.gnu.org/software/bash/manual/bashref.html#Escape-Character 3.1.2.1 Escape Character] ." https://www. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639.
APA https://www. (2026). [https://www.gnu.org/software/bash/manual/bashref.html Bash Reference Manual], [https://www.gnu.org/software/bash/manual/bashref.html#Escape-Character 3.1.2.1 Escape Character] . Retrieved November 28, 2026, from https://en.wikipedia.org/w/index.php?oldid=1370769639
- 3.6.4 Documentation . docs.python.org . · retrieved 2026-08-21 · rev 1370769639
Cite this reference
MLA "3.6.4 Documentation . docs.python.org ." 6. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639. Accessed 28 November 2026.
Chicago "3.6.4 Documentation . docs.python.org ." 6. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639.
APA 6. (2026). 3.6.4 Documentation . docs.python.org . Retrieved November 28, 2026, from https://en.wikipedia.org/w/index.php?oldid=1370769639
- [http://golang.org/doc/effective_go.html#semicolons Semicolons] · retrieved 2026-08-21 · rev 1370769639
Cite this reference
MLA "[http://golang.org/doc/effective_go.html#semicolons Semicolons]." http://golang. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639. Accessed 28 November 2026.
Chicago "[http://golang.org/doc/effective_go.html#semicolons Semicolons]." http://golang. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639.
APA http://golang. (2026). [http://golang.org/doc/effective_go.html#semicolons Semicolons]. Retrieved November 28, 2026, from https://en.wikipedia.org/w/index.php?oldid=1370769639
- [https://groups.google.com/forum/#!topic/golang-nuts/XuMrWI0Q8uk Semicolons in Go] · retrieved 2026-08-21 · rev 1370769639
Cite this reference
MLA "[https://groups.google.com/forum/#!topic/golang-nuts/XuMrWI0Q8uk Semicolons in Go]." "[https://groups. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639. Accessed 28 November 2026.
Chicago "[https://groups.google.com/forum/#!topic/golang-nuts/XuMrWI0Q8uk Semicolons in Go]." "[https://groups. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639.
APA "[https://groups. (2026). [https://groups.google.com/forum/#!topic/golang-nuts/XuMrWI0Q8uk Semicolons in Go]. Retrieved November 28, 2026, from https://en.wikipedia.org/w/index.php?oldid=1370769639
- Lexical analysis > Indentation . The Python Language Reference . retrieved 21 June 2023 · retrieved 2026-08-21 · rev 1370769639
Cite this reference
MLA "Lexical analysis > Indentation . The Python Language Reference . retrieved 21 June 2023." Lexical analysis > Indentation. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639. Accessed 28 November 2026.
Chicago "Lexical analysis > Indentation . The Python Language Reference . retrieved 21 June 2023." Lexical analysis > Indentation. 2026-08-21. https://en.wikipedia.org/w/index.php?oldid=1370769639.
APA Lexical analysis > Indentation. (2026). Lexical analysis > Indentation . The Python Language Reference . retrieved 21 June 2023. Retrieved November 28, 2026, from https://en.wikipedia.org/w/index.php?oldid=1370769639
Cite this article
MLA
"Lexical analysis." encyclopegia.org, 2026, https://encyclopegia.org/wiki/lexical-analysis. Accessed 28 November 2026.
Chicago
"Lexical analysis." encyclopegia.org. Accessed November 28, 2026. https://encyclopegia.org/wiki/lexical-analysis.
APA
encyclopegia.org. (2026). Lexical analysis. Retrieved November 28, 2026, from https://encyclopegia.org/wiki/lexical-analysis
Accessed November 28, 2026 · CC BY-SA 4.0 · citation page · JSON