{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
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 one’s 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
Image of page 1

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

View Full Document Right Arrow Icon
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 don’t need diagrams or other external descriptions. In fact, we don’t 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 we’re 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 can’t 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. We’ll start with a simple example, namely a description of (possibly signed) integer constants like 42 , + 28 , and - 37 . CS 135 Fall 2008 03: The syntax and semantics of Beginning Student 6
Image of page 2
Here is a grammar describing integer constants.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern