1 / 8

SIMPLE LANGUAGE

SIMPLE LANGUAGE. p. 318-321. Elizabeth Valdini. Several questions puzzled computer scientists at the beginning of the computer era:. Which problems can be solved by a computer? Which cannot? How long does it take to solve a problem using a particular language?

edda
Download Presentation

SIMPLE LANGUAGE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SIMPLE LANGUAGE p. 318-321 Elizabeth Valdini

  2. Several questions puzzled computer scientists at the beginning of the computer era: • Which problems can be solved by a computer? Which cannot? • How long does it take to solve a problem using a particular language? • Is one language superior to another? That is, can a computer program written in one language solve a problem that another cannot? • What is the minimum number of statements needed for a language to solve a problem? • Before running a program, can it be determined if the program will halt (terminate) or run forever? • To answer these questions, we turn to a discipline called the theory of computation. First, we introduce a language, called the Simple Language, to show that the minimum number of statements needed to solve any problem that is solvable by a computer is three..

  3. SIMPLE LANGUAGE In this language, you use only the integer data type. There is no need for any other data type because you can simulate other data types with the integer type. The language uses only a few symbols such as { and }.

  4. An increment statement adds 1 to the variable. X=X +1 An decrement statement subtracts 1 from the variable. X=X-1 Increment Decrement While Loop A loop statement repeats an action (or series of actions) while the value of the variable is not 0. While x does not equal 0 (Action or Actions)

  5. Macros in the Simple Language First Macro: X  0 (sometimes called the clearing) While X { decr X } X  n The following code shows how to use the statements in this language to assign a positive integer to a variable X. X  0 Incr. X Incr. X . . . Incr. X Second Macro:

  6. Third Macro: Y  X Every programming language has a statement that copies the value of one variable to another without losing the valuse f the original variable. Y  0 TEMP 0 While {incr. Y / decr. X / incr. TEMP } While TEMP {decr TEMP / Incr. X } Fourth Macro: Z  X + Y This macro adds the values of X and Y and stores the result in Z. You do this in two steps. First store the value of X in Z and then increment z Y times. Z  X Temp Y While TEMP { incr. Z / decr. Temp }

  7. Fifth Macro: Z  X * Y This macro multiplies the values of x and y and stores the result in z. You use the fourth macro because multiplication is repeated addition. Z 0 TEMP  Y While TEMP { Z Z + X decr. TEMP } Z  X** Y This macro raises x to the power y and stored the result in Z. You do this using multiplication because exponentiation is repeated multiplication. Z  1 TEMP  Y While TEMP { Z  Z * X / decr. TEMP } Sixth Macro:

  8. Input and Output There is no need for a language such as this for input or output. You can simulate the input, such as read x, by an assignment statement (x  n). You can also simulate the output by assuming the last variable used in a program holds what should be printed. Remember that this is not practical language; it is designed to prove some theorems in computer science.

More Related