Intermezzo 1: Syntax and Semantics

external ~<#7353#>This section is a rigorous presentation of Scheme's grammar and evaluation rules. The goal is to show that there are two aspects to studying computer languages: syntax and semantics. Covering the section is not necessary but it does provide a first glimpse at what computer scientists study.<#7353#> Thus far we have approached Scheme as if it were a spoken language. Like toddlers, we learned the vocabulary of the language, we acquired an intuitive understanding of its meaning, and we figured out some basic rules of how to compose and not to compose sentences. Truly effective communication, however, in any language---be it natural like English or artificial like Scheme---eventually requires a formal study of its vocabulary, its grammar, and the meaning of sentences. A programming language is in many ways like a spoken language. It has a vocabulary and a grammar. The vocabulary is the collection of those ``basic words'' from which we can compose ``sentences'' in our language. A sentence in a programming language is an expression or a function; the language's grammar dictates how to form complete sentences from words. Programmers use the terminology <#61679#><#7354#>SYNTAX<#7354#><#61679#> to refer to the vocabularies and grammars of programming languages. Not all grammatical sentences are meaningful---neither in English nor in a programming language. For example, the English sentence ``the cat is round'' is a meaningful sentence, but ``the brick is a car'' makes no sense, even though it is completely grammatical. To determine whether or not a sentence is meaningful, we must study the <#61680#><#7355#>MEANING<#7355#><#61680#>, or <#61681#><#7356#>SEMANTICS<#7356#><#61681#>, of words and sentences. For spoken languages, we typically explain the meaning of words with sentences that use simpler words; in the case of a foreign language, we sometimes explain a word with simple sentences in the foreign language or we translate words to a known language. For programming languages, there are also several ways to explain the meaning of individual sentences. In this book, we discuss the meaning of Scheme programs through an extension of the familiar laws of arithmetic and algebra. After all, computation starts with this form of simple mathematics, and we should understand the connection between this mathematics and computing. The first three sections present the vocabulary, grammar, and meaning of a small, but powerful subset of Scheme. The fourth one resumes our discussion of run-time errors in Scheme, based on our new understanding of its meaning. The remaining three sections revisit <#61682#><#7357#>and<#7357#><#61682#> and <#61683#><#7358#>or<#7358#><#61683#> expressions, variable definitions, and structures.