Sep 16

Lecture Overview

Operating Systems, Continued

In addition to the kernel (see day7), there are two more components usually associated to the operating system.

Programming Languages

Programming languages are made up of three components:

Python defines the syntax and semantics here. As an example, consider the if statement.

The syntax of a programming language is described using Backus-Naur Form. This gives slightly more detail than we discussed in class so I won't rewrite it all.

For example, the python reference uses (a variant) of BNF to describe the syntax of statements, for example the if statement. The BNF syntax is then followed by a description of the semantics. Section 1.2 describes the python variant of BNF.

Exercises

On day6, you wrote code and used Wallis' and Leibniz's approximations of pi. Convert both of these implementations to functions and put them into the same file. Each function should take one paramter for the number of terms to compute, and return the approximation of pi. That is, create a python file like

def wallis(terms):
    # Code for wallis here, where terms is an integer for the number of terms to compute
    # return the pi approximation

def leibnitz(terms):
    # Code for leibnitz here, where terms is an integer for the number of terms to compute
    # return the pi approximation

Add some test code to make sure your code works, for example

print(wallis(1000))