Module 3

Module 3 - The syntax and semantics of Beginning Student...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come later), and in a somewhat different fashion. CS 135 Fall 2008 03: The syntax and semantics of Beginning Student 1 A program has a precise meaning and effect. In order to be able to write programs that do what we want, and have readers of the program understand what we want the program to do, we should have a better definition of the effect of a program than what happens when the program is run. The meaning of a program precedes an implementation of a programming language. The better ones grasp of that meaning, the less likely one is to make errors. CS 135 Fall 2008 03: The syntax and semantics of Beginning Student 2 A model of a programming language provides a way of describing the meaning of a program. This may or may not correspond to what actually happens in the implementation, but the model should be able to predict the effect of running the program. Most first courses in programming teach about the model implicitly, via examples, or give a simplified description of the underlying machine, or draw diagrams to describe the state of a program. Because of the choice of Scheme, we can do better than this. CS 135 Fall 2008 03: The syntax and semantics of Beginning Student 3 Scheme allows us to do better in two respects. First, because there are so few language constructs, the description of the model is pretty short. Second, because we are using a functional approach, we dont need diagrams or other external descriptions. In fact, we dont need anything more than the language itself, as we will see. We will first study the syntax of a Scheme program, and then its semantics. CS 135 Fall 2008 03: The syntax and semantics of Beginning Student 4 Syntax and grammar Syntax: the way were allowed to say things. Semantics: the meaning of what we can say. The sentence Trombones fly hungrily is syntactically correct but semantically meaningless. For the English language, syntax consists of spelling and grammar rules. A sentence can be made up of a subject, verb, and object; generally it cant be object, subject, verb. A subject can be simple or compound, and so on. CS 135 Fall 2008 03: The syntax and semantics of Beginning Student 5 English grammar consists of a number of rules like these, which are not rigidly enforced. We use similar rules to describe computer languages; because the languages are interpreted by a machine, the rules are rigidly enforced. Well start with a simple example, namely a description of (possibly signed) integer constants like 42, + 28, and- 37....
View Full Document

This note was uploaded on 10/21/2010 for the course CS 135 taught by Professor Vasiga during the Fall '07 term at Waterloo.

Page1 / 15

Module 3 - The syntax and semantics of Beginning Student...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online