Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 148-1Programming…8-2General Purpose•The computer is a “general purpose” tool–General purpose means it can do more than one thing–How do we make it do more than one thing?•make it perform a handful of small tasks that could be combined to perform more complicated tasks•allow it to follow instructions to perform the above tasks–It is programmable (i.e., we can program it)•A computer program: a list of instructions for the computer–What sort of instructions does the computer understand?8-3Tell me what to do. . .•Make me a peanut butter and jelly sandwich:–What does this mean to you?8-4Really tell me what to do. . .1. Go to the refrigerator2. Open fridge3. If ((no peanut butter) or (no jelly))1. Go to store and buy ingredients4. Remove peanut butter and jelly5. Get bread6. Open bread7. Do twice:1. Take slice from bag8. Place slices side by side9. Get knife10. Open peanut butter jar11. Insert knife into jar12. Apply peanut butter to knife13. While surface of bread is not covered with peanut butter1. Apply peanut butter to bread from knife14. Close peanut butter jar15. Open jelly jar16. Insert knife into jar17. Apply jelly to knife18. While surface of bread is not covered with jelly1. Apply jelly to bead with knife19. Close jelly jar20. Place both slices of bread together such that the side with peanut butter is touching the side with jelly and the uncovered sides are facing out.And we’re probably missing steps!“simple” tasksrepetitionlogic8-5Language of Instructions•What do we need to know about the target of our instructions before we can give them?•How do we ask them to do things?•What do they know how to do?•What language do they speak?8-6Syntax and Grammar•Syntax – the form of what you say–The grammatical structure (form) of a language–Grammar: defines the words you are allowed to use and specifies the order in which you can place them•a grammar defines a syntaxnoun := sandwichconnector := andadjective := peanut butter | jelly | adjective connector adjectiveverb := makesimpleRequest := verb noun | verb adjective noun–a simpleRequest can be »make peanut butter and jelly sandwich»make sandwich»make jelly sandwich»make jelly and jelly sandwich»make jelly and jelly and jelly sandwich–A grammar tells you how to parse a message into simpler parts»(…or how to compose a message from parts)the sandwich grammar8-7Language of instructions•Semantics – the meaning of what is said–Semantics explain how you interpret the results of parsing•make is a verb–A verb tells me what action to take•peanut butter and jelly is an adjective–An adjective tells me about a noun•sandwich is a noun–The noun is the target of my action–The semantics provide the meaning for each of these things:•Ex: “when you encounter a make adjective sandwich you will need to get two pieces of bread, and put the adjective between the pieces of bread.”–How does this relate to computers?•Beyond the obvious fact that in the future there will be robots and they will make us sandwiches8-8Applied to Computers. . .•What language does a computer “speak” ?–Computers “think” in binary.–Internally, they only understand 1’s and 0’s–We’ve learned that computers can do fancy things with 1’s and 0’s•Boolean logic•Mathematics•Store and retrieve 1’s and 0’s•We need the computer to know that a particular sequence of 1’s and 0’s uniquely identifies some task to do (semantics)•We need to give the computer a series of 1’s and 0’s–Ideally: we (humans) would like a mapping between English (or something closer to English) and something that makes sense to the computer (binary)8-9In the beginning•Early computers were primarily special purpose mathematic computers.–Computers were designed to perform a particular arithmetic task or set of mathematic tasks.•Computers that were unable to change their tasks are “hardwired”–Hardwiring: Using solder to create circuit boards with connections needed to perform a specific task (in a larger sense).•Computers that were able to have their tasks changed required direct “hardware modification” by skilled engineers–Change the flow of electricity to run through different logic paths–Fat-fingering: Engineer needed to position electrical relay switches manually.8-10The Programming Language Continuum•ENIAC–Used programs to complete a number of different mathematical tasks.•Programs were entered by plugging connector cables directly into sockets on a plug-in board.–Set-up could take hours.–A program would generally be used for weeks at a time.8-11The Programming Language Continuum•In the beginning… To use a computer, you needed to know how to program it.•Today… People no longer need to know how to program in order to use the computer.•In addition, programming has become more accessible–programming languages “evolved” from low level to high level.–Fifth Generation - Natural Languages–Fourth Generation - Non-Procedural Languages–Third Generation - People-Oriented Programming Languages–Second Generation - Assembly Language–First Generation - Machine Language (code)HighlevelLowlevel8-12Communicating witha Computer•Programming languages bridge the gap between human thought processes and computer binary circuitry.–Programming language: A series of specifically defined commands designed by human programmers to give directions to digital computers.•The computer knows how to act on each given command•Larger tasks are written as series of such instructions, called programs.•All programming language instructions must be expressed in binary code before the computer can perform them.8-13Computer Software•Computer hardware can do very basic things (when instructed to do so):–Store a number in memory–Get a number from memory–Add two numbers–etc…•Program: a list of these basic operations strung together to perform seemingly difficult tasks8-14Representing (Instructions) Programs•Arithmetic Instructions–Addition, subtraction, multiplication, division, and other numeric operations•Data Movement Instructions–Move numbers from place to place in the computer•Logical or Comparison Instructions–Decision making instructions e.g. x < 10•Control Instructions–Controls the sequences in which instructions are


View Full Document

BU CS 101 - Programming

Download Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?