03-synsem-post3up

03-synsem-post3up - The syntax and semantics of Beginning...

Info iconThis preview shows pages 1–4. 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

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 Winter 2012 03: The syntax and semantics of Beginning Student 1 • A program has a precise meaning and effect. • A model of a programming language provides a way of describing the meaning of a program. • Typically this is done informally, by examples. • With Scheme, we can do better. CS 135 Winter 2012 03: The syntax and semantics of Beginning Student 2 Advantages in modelling Scheme • Few language constructs, so model description is short • We don’t need anything more than the language itself! – No diagrams – No vague descriptions of the underlying machine CS 135 Winter 2012 03: The syntax and semantics of Beginning Student 3 Spelling rules for Beginning Student Identifiers are the names of constants, parameters, and user-defined functions. They are made up of letters, numbers, hyphens, underscores, and a few other punctuation marks. They must contain at least one non-number. They can’t contain spaces or any of these: ( ) , ; { } [ ] ‘ ’ “ ”. Symbols start with a single quote ’ followed by something obeying the rules for identifiers. CS 135 Winter 2012 03: The syntax and semantics of Beginning Student 4 There are rules for numbers (integers, rationals, decimals) which are fairly intuitive. There are some built-in constants, like true and false . Of more interest to us are the rules describing program structure. For example: a program is a sequence of definitions and expressions. CS 135 Winter 2012 03: The syntax and semantics of Beginning Student 5 Syntax and grammar There are three problems we need to address: 1. Syntax: The way we’re allowed to say things. ‘?is This Sentence Syntactically Correct’ 2. Semantics: the meaning of what we say. ‘Trombones fly hungrily.’ 3. Ambiguity: valid sentences have exactly one meaning. ‘Sally was given a book by Joyce.’ English rules on these issues are pretty lax. For Scheme, we need rules that always avoid these problems. CS 135 Winter 2012 03: The syntax and semantics of Beginning Student 6 Grammars To enforce syntax and avoid ambiguity, we’d like to use grammars. For example, an English sentence can be made up of a subject, verb, and object, in that order....
View Full Document

This note was uploaded on 04/02/2012 for the course CS 135 taught by Professor Vasiga during the Winter '07 term at Waterloo.

Page1 / 9

03-synsem-post3up - The syntax and semantics of Beginning...

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

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