Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-v5vhk Total loading time: 0 Render date: 2024-06-16T08:38:37.351Z Has data issue: false hasContentIssue false

2 - Lexical Analysis

Published online by Cambridge University Press:  05 June 2012

Andrew W. Appel
Affiliation:
Princeton University, New Jersey
Get access

Summary

lex-i-cal: of or relating to words or the vocabulary of a language as distinguished from its grammar and construction

Webster's Dictionary

To translate a program from one language into another, a compiler must first pull it apart and understand its structure and meaning, then put it together in a different way. The front end of the compiler performs analysis; the back end does synthesis.

The analysis is usually broken up into

Lexical analysis: breaking the input into individual words or “tokens”;

Syntax analysis: parsing the phrase structure of the program; and

Semantic analysis: calculating the program's meaning.

The lexical analyzer takes a stream of characters and produces a stream of names, keywords, and punctuation marks; it discards white space and comments between the tokens. It would unduly complicate the parser to have to account for possible white space and comments at every possible point; this is the main reason for separating lexical analysis from parsing.

Lexical analysis is not very complicated, but we will attack it with high-powered formalisms and tools, because similar formalisms will be useful in the study of parsing and similar tools have many applications in areas other than compilation.

LEXICAL TOKENS

A lexical token is a sequence of characters that can be treated as a unit in the grammar of a programming language. A programming language classifies lexical tokens into a finite set of token types.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 1997

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Lexical Analysis
  • Andrew W. Appel, Princeton University, New Jersey
  • With Maia Ginsburg
  • Book: Modern Compiler Implementation in C
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139174930.003
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Lexical Analysis
  • Andrew W. Appel, Princeton University, New Jersey
  • With Maia Ginsburg
  • Book: Modern Compiler Implementation in C
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139174930.003
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Lexical Analysis
  • Andrew W. Appel, Princeton University, New Jersey
  • With Maia Ginsburg
  • Book: Modern Compiler Implementation in C
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139174930.003
Available formats
×