• Keine Ergebnisse gefunden

AMOS LANGUAGE PROCESSORS

Im Dokument INTRODUCTION TO AMOS (Seite 72-75)

This chapter will introduce you to the major language processor programs on the AMOS system. You'll meet BASIC, PASCAL, LISP, and the AMOS macro-assembler program, MACRO. The first few sections talk about some basic concepts behind the AMOS language processors. If you are already familiar with these ideas ("computer languages," "compilers," and "interpreters") you may want to skip on to later sections that talk specifically about the AMOS language processors (e.g., Section 10.4, "AlphaBASIC").

10.1 COMPUTER LANGUAGES

In earlier chapters, we mentioned that one of the major benefits of an operating system is that it allows you to communicate with your computer system in a way that is more comfortable for you than entering the machine language understood by that computer. (You'll remember that we defined machine language as the set of all of the instructions that you can give to the CPU which it can understahd directly.) Because the operating system has very specific functions, the instructions that you can enter to it are also very specific and related only to system activities. For example, you cannot ask the operating system to perform a general function, such as to , compute a mathematical value, but you can ask it to tell you what files are in your disk account. Therefore, your computer system gives you another tool that allows you to communicate in a more general way with the computer- computer languages.

A working definition of "language" might be that it is a large set of meaningful patterns that communicate ideas. A computer language allows you to write groups of instructions (a program) that the computer can carry out. A computer language can be machine langllage (which directly communicates instructions and data to the CPU) or it can be a higher-level language (such as BASIC) that is interpreted by a machine language program. (Those languages we call higher-level are more comfortable for us than machine language because they look much more like the languages we humans are used to, and because they let one instruction perform the same function as perhaps hundreds of machine language instructions.)

The type of computer language you use to write your programs depends on the applications performed by that program. For example, one computer language might have commands that make numeric computation very simple, while another language might be very good for writing programs that manipulate text. Still another language might generate programs that execute very quickly.

Just as English has a set of rules concerning the ways in which you can combine words into sentences and paragraphs, so computer languages also have strict rules that govern the ways you can form their elements into program lines and programs. The specific commands and ways in which you can use them vary widely among computer languages, but all computer languages have one thing in common- they help you to communicate with the computer. The computer languages you can use on the AMOS system are: BASIC, PASCAL, LISP, and assembly language.

10.2 WHAT IS A LANGUAGE PROCESSOR?

Anytime we talk to the computer in a language that is not machine language, we must use a translator of some sort that can transform our communication into a pattern that the computer can handle. Such a translator is a language processor.

Usually when we use the term "language processor," we refer to a program that can understand and act upon one of the familiar computer languages such as BASIC or PASCAl. (Of course, in a limited sense, AMOS itself is a language processor. We mentioned in Chapter 3, "Who is AMOS?", that the set of instructions that you can give AMOS make up the AMOS command language.)

At this point we have already made the distinction between a computer language and the program that processes that language. Remember that when we talk about the BASIC language, we are talking about an abstract computer language named "BASIC." Programs written in this language are not directly executable by the operating system unless they are first translated and controlled by the BASIC language processor. The language processor program almost always bears the same name as the language it processes. For example, when you type:

..J3ASIC [RET)

you are telling AMOS to execute the language processor that understands the BASIC language. So, remember that when we talk about being "in BASIC," we mean that you are communicating with the program that processes programs written in the BASIC language. On the other hand, when we talk about a "BASIC state-ment," we are talking about an element in the BASIC language.

10.3 INTERPRETERS AND COMPILERS

We class language processors into one of two groups, according to how they process programs. These two groups are interpreters and compilers.

10.3.1 Language Interpreters

An interpreter reads each line of a program, and performs the commands in that line as it reaches them. For example, when a BASIC interpreter sees this line in your program:

PRINT"HELLO"

the interpreter recognizes the PRI NT command. It then transfers control to the routine within itself that handles the PRI NT command. Then control passes back to the main portion of the interpreter which scans and interprets the next program statement.

When it finishes reading, interpreting, and acting upon a program line, the interpreter goes on to the next line until it reaches the end of the program. If you ask the interpreter to execute your program again, it goes through this entire process of recognizing and acting upon program commands again, as if it had never seen your program before.

A major advantage of an interpreter is that such language processors are usually interactive. That is, you can enter program statements to the language processor, and the interpreter will tell you as you enter it whether a program statement is in legal form. You can even enter language statements that are not part of a program, and the interpreter will execute them directly as you type them in, instead of waiting to execute an entire program.

AMOS Language Processors 10-3

Of course, interpreters also have disadvantages. Because it must go through the same process of recognizing and executing program statements each time it processes your program, an interpreter is usually slower than a compiler when executing the same program. Another drawback to the use of interpreters is that you must keep the interpreter in memory along with your program; this can use up quite a bit of memory, since most interpreters are relatively large programs.

10.3.2 Language Compilers

The second type of language processor is called a compiler because it actually "compiles" or translates your program into another version which is closer to machine language. (A traditional, "strict" compiler translates a source program directly into machine language. Other compilers compile source programs into a pseudo-machine language. Regardless of its type, the compiler reduces your program to a form that is closer to the computer's own level.) This process of translation is called compiling a program or program compilation.

After compiling a program, you have two versions of it: the original (or source) program and the translated version (or compiled) program.

One of the benefits of compiling a program is that most of the scanning and recognition process that an interpreter must do every time it reads your program is done only once by the compiler- at the time that it compiles your program.

The compiler thus allows you to separate the processes of program analysis and execution. You only need to compile a source program once. Then you can execute the compiled program at any time without going through the preliminary processing done earlier. (Of course, if you change your source program, you will need to re-compile it so that the compiled program reflects those changes.) Since the source program has been translated and reduced, the compiled program takes up less memory, and since the compiled program is closer to the computer's own machine language than the source program, it runs faster than an interpreted version. In addition, when you execute the compiled program, you do not have to have the compiler in memory along with your program. Depending on the compiler, your compiled program may either be executed directly by the computer, or you may need to have a small machine language program in memory called a run-time package, which completes the translation between your compiled program and the computer's machine language.

10.3.3 Theory Versus Fact

Now that we've given a very general discussion of interpreters and compilers, we should mention that although in theory the differences between them are very clear, in reality, most interpreters and compilers share some features of each other. That is, you will rarely find a "strict" compiler or a "strict" interpreter.

For example, most interpreters perform a process called tokenization, wherein the processor substitutes special tokens for BASIC statements. That is, when it reads in a line from a BASIC program, an interpreter might (for example) substitute a special one- byte symbol for the PRI NT command. This allows the interpreter to go much faster later when it processes that line, because it doesn't need to scan the entire word "PRINT,"

but only needs to recognize the special PRINT token. A tokenized program also takes up less room in memory. Tokenization is a very limited type of compilation.

As another example, very few compilers actually translate programs directly into machine language. Most compilers (e.g., AlphaBASIC) compile programs into a pseudo- machine language form, which is then executed by a small machine language program called a run-time package. (In the case of AlphaBASIC, the run-time package is called RUN.)

10.4 ALPHABASIC

Because AlphaBASIC is by far the most widely used language processor on the Alpha Micro system, we will talk about it in some depth. For detailed information on using AlphaBASIC, refer to the AlphaBAS/C User's Manual,

(OWM-00100-01).

BASIC is the most popular higher-level language on microcomputers today. Much of this popularity stems from the fact that it is relatively easy to learn. It was designed as a computer language for beginning program-mers; in fact, its name is an acronym for "Beginner's All-purpose Symbolic Instruction Code."

Because it has been implemented by so many manufacturers on numerous computers, BASIC is no longer a standardized language. Many different versions of it exist, each slightly different from the other. Alpha Micro's BASIC, AlphaBASIG, is an extremely powerful version of BASIC that contains a number of unusual features that make it uniquely suitable for business and scientific applications programming.

If you've never seen a BASIC program, you might be interested in taking a look at a very small and simple program written in AlphaBASIC:

10 REM Calculate number of years it takes to double your money.

20 REM-Get information and initialize new principal and number of years.

30 START:

40 INPUT "Enter principal:

$",

MAINPRINCIPAL 50 INPUT "Enter rate of interest (in %): %", RATE 60 YEARS = 1

70 PRlNCIPAL =

~AINPRINCIPAL

80 REM Now calculate the new principal 90 CALCULATE:

100 INTEREST = PRINCIPAL * (RATE/100)

Im Dokument INTRODUCTION TO AMOS (Seite 72-75)