chapter2

chapter2 - Chapter 2 Programming Languages In this chapter...

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

View Full Document Right Arrow Icon
Chapter 2 Programming Languages In this chapter we will study some simple but powerful general programming languages. Turing machines can be viewed as : 1. Language Recognizers 2. String Manipulators 3. Function Computers TMs can be viewed as language recognizers since, given an input string, they can either accept or reject the string (in±nite looping is considered rejection) and thus determine whether the string is in some language or not. They can also be viewed as string manipulators, since given an input string they may overwrite the input tape and terminate with a di²erent string. In order to view them as function computers, we need to be able to represent numbers on the input tape. We will restrict our discussion to non-negative integers. This is not an unreasonable assumption because in the realm of computers, all data, whether integer, real or otherwise, is represented in terms of patterns of bits. These patterns can be represented by integers, in particular non-negative integers. Hence the processing of computers can be viewed as operations on non-negative integers. For example real numbers may be represented as mantissa and exponent pairs, each of which are stored as a sequence of bits. Character or string data is represented in terms of the corresponding ASCII codes which are non-negative integers. Consider for example a TM that adds two numbers represented in binary or unary and separated by the # symbol. It is easy to see that the following functions are all computable by TMs: f ( x, y )= x + y f ( x, y x . y ,where f is the monus function, de±ned as x . y = ( x y if x>y 0o t h e r w i s e 27
Background image of page 1

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

View Full DocumentRight Arrow Icon
c ± O.H.Ibarra 28 f ( x, y )= x y f ( x, y x y f ( x, y ² x/y ³ f ( x, y ´ x/y µ 2.1 The G Programming Language Let us now defne a simple programming language called G programming language. Every program in this language begins with an input statement such as: input ( x 1 ,x 2 , ··· n ) and ends with an output statement such as: output ( y ), where the x i s are input variables and y is the output variable. All variables in this language can assume only non-negative integers values. The body oF the program is made up oF a sequence oF (possibly labeled) statements oF the Following Form: x x +1 x x . 1 if x =0 goto l ,where l is a statement label halt It is assumed that all noninput variables are initially zero. Clearly, using the above constructs, we can implement the Following constructs: x 0 goto l x y x x + y x x . y x x y x ←² x/y ³
Background image of page 2
c ± O.H.Ibarra 29 For example, let us implement x y : x 0 y 1 0 1: if y =0 goto 5 x x +1 y 1 y 1+1 y y . 1 goto 1 5: . . . and y 1 can then be copied into y . The others are left as an exercise for the reader.
Background image of page 3

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

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

Page1 / 11

chapter2 - Chapter 2 Programming Languages In this chapter...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online