Programming Language Basics - Computer Science - Lecture Notes, Study notes of Computer Science

This is introductory course for computer science. Its about basic concepts involving in computer programming, structure and working. Key points in this lecture handout are: Programming Language Basics, Values and Types, Computers and Computation, General-Purpose Machine, Universal Machine, Conditional Execution, Looping

Typology: Study notes

2012/2013

Uploaded on 09/28/2013

noob
noob 🇮🇳

4.4

(25)

105 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture Notes CPSC 121 (Fall 2011)
Today ...
Programming language basics
Values and types
Homework
HW 1 due
HW 2 out
Reading Assignment
Ch. 1 and 2 (pp. 3–12)
S. Bowers 1 of 9
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Programming Language Basics - Computer Science - Lecture Notes and more Study notes Computer Science in PDF only on Docsity!

Today ...

  • Programming language basics
  • Values and types

Homework

  • HW 1 due
  • HW 2 out

Reading Assignment

  • Ch. 1 and 2 (pp. 3–12)

A note about computers and computation

A computer is a general-purpose machine (aka “universal machine”)

  • Instead of being able to execute only one or a few types of processes
    • e.g., like a toaster or a car wash
  • A computer can perform any computation
    • According to the Church-Turing Thesis
    • Everything computable is computable by a “Turing Machine” (ca. 1936)
    • A tape of cells containing symbols, a set of states, a read/write heaad, and a transition table (state,symbol → state,symbol,move)
  • But you have to give it the instructions :-)

Syntax and Semantics

Tokens are the basic building blocks of programming languages

  • Allowable values, operations (e.g., +, −), keywords, punctuation, etc.

The keywords of a language are special tokens

  • Sometimes called reserved words

The Python keywords (reserved words):

False class finally is return None continue for lambda try True def from nonlocal while and del global not with as elif if or yield assert else import pass break except in raise

Syntax specifies the legal statements

  • Rules for allowable ways to combine tokens
  • The allowable structure of programs (as opposed to their meaning)

Semantics specifies the meaning of statements

  • Rules for how to evaluate statements

Interpretation versus Compilation

Two main approaches for running programs

Compilers



______^ Compiler^

Executable

Source Code (^) (a program)

input

output

Linker




Object Code




  • Translates programs into “machine” code
  • Machine code run directly by the operating system
    • E.g., a .exe file on Windows
  • Many PLs have compilers including C, C++, Java (sort of)

Debugging

It’s easy to make mistakes when programming

  • Errors are traditionally called bugs
  • Tracking down bugs is called debugging

Programmers do lots of debugging!

  • debugging is an important programming skill
  • it is a lot like being a detective:
    • look for clues
    • make hypotheses
    • make changes
    • check if you fixed the bug

Develop code in small steps to avoid becoming overwhelmed by bugs

  • write a few lines
  • run your program
  • debug
  • write a few more lines
  • and so on

Types of bugs

Syntax errors

  • The Python interpreter catches these for us!

Runtime errors

  • Errors that occur as the program is run
  • Referred to as exceptions in Python
  • We’ll talk more about these later
  • Python can catch some of these before runtime (“static semantics”)

Semantic errors

  • typically means your program runs ...
  • ... but it doesn’t do what you wanted
  • these bugs are trickier to find

When a syntax or runtime error occurs, the Python interpreter

  • prints an error message and exits your program