• Aucun résultat trouvé

by David D. Busch

Dans le document JUNE 1981 (Page 70-75)

Most of the Basic language's limitations stem from its original purpose as a high level language that would be easy for beginners to learn and use. Its strongest point-the simple English keywords-provides an arti­

ficial barrier for those whose primary language is not English. Some of the largest Spanish-speaking com­

munities in the world, for example, are in the U.S. The availability of a Basic in Spanish might make it easier for these citizens to use computers such as the TRS-80, Pet or Apple II at an earlier age.

A machine language Spanish-Basic interpreter for any of these would be ideal. Programs could be written in a Hispanic version of Basic, run, tested and debugged in that form. Unfortunately, that would be a major undertaking, best tackled by a software house with some hopes of recouping the time investment through sales. But, one-tenth a loaf is often better than none. I used my TRS-80's Disk Basic to write a very simple pseudo-compiler that converts programs written in Spanish Tiny Basic to standard Basic for running.

In other words, the program Spanish/Bas is used to write source code, using 20 level 1-type Spanish key­

words, instead of the English Basic equivalent (table 1 ).

As each line is entered, the program checks it for various criteria (each must begin with a line number, and no more than one statement is allowed per line) and generates a new line of code, replacing each of the Spanish keywords with the English equivalent. Both versions may be saved to disk or listed at any time.

Editing is accomplished (like level I) by re-entering the line. The English (compiled) version of the program is object code that may be loaded and run under your Basic interpreter, like any Basic program , as long as the code entered in Spanish conformed to the normal syntax rules of Basic.

Ideally, the program should be used by a person who already knows standard Basic to teach a Spanish­

speaking person how to program. Any Basic program­

ming course, translated into Spanish, could be used , with my Spanish statement and command equivalents substituted for those of standard Basic.

The Spanish words I have chosen are not necessarily the best possible equivalents for the Basic keywords replaced. I chose the Basic translations using two criteria. First, the Spanish words should be short and mean approximately what the Basic equivalents mean.

Because the keywords are, in effect, commands, I used the imperative form of the verbs. Second, my pro­

gramming job was made easier by selecting Spanish words that were either the same length or longer than the Basic keywords.

If this last criterion is kept in mind, users with more sophisticated Spanish backgrounds than mine may wish to substitute Spanish keywords that are more accurate.

In some cases, it was necessary to sacrifice a direct translation for ease of programming. For example, LEA would have been better than LLEVE (carry) for READ. But, since it was shorter than the word it would have replaced, it would have made writing the program more difficult.

To use the program , the student types RUN (in English) and is shown a summary of the commands and statements available. This is only a memory-refresher, as knowledge of Basic (or 'Spanish' Basic) will be necessary. An existing program can be loaded from disk, using the CARGE command . Prompts ask for the names under which the Spanish (source) program and the English (object) program were saved . Then, the program can be edited, like Ievei i, by retyping in a line, ·

or by adding new ones.

At any time, a specific line in Spanish can be seen by entering ALISTE XXX, where XXX is the line number.

Or, by typing just ALISTE, the entire program will be presented a section at a time. Entering LIST will display the compiled English version. NUEVO or CORRA will erase the current program in memory, and allow starting over.

To conserve memory space, and speed up 1/0 time when saving and loading, line numbers between 0 and 1 00 must be used. Those with 48K machines can easily up the total allowable line numbers as high as possible.

Only single statements are allowed per line. Spaces must be used after line numbers and between words.

It is permissible to forget to end a line with a space, as one is automatically added by the program. Spaces are essential, because in searching for keywords, the program looks not for, say, the letters Sl, but

<space>SI<space>. Otherwise, by the time the loop which searches for keywords got to SIGUIENTE, the word would have been changed to IFGUI ENTE.

Disk Basic words may be used, or the original English

JUNE 1 98 1

keywords (PRINT, for example). The program looks for and changes only the Spanish words in table 1 .

Table 1 . Spanish-English keywords used

English NEW LOAD

LIST

English PRINT READ RESTORE

I F-THEN STEP

END RETURN

CLS

Commands (Los Mandados) Spanish English

N U EVO R U N

CARGE SAVE ALISTE

Statements (Las Declaraclones) Spanish

CORRA AHORRE

Spanish English Spanish

IM PRIMA IN PUT CONTESTE

LLEVE DATA DATOS

RESTAURE GOTO VAYA A SI-ENTONCES FOR-N EXT PARA-SIGUIENTE

PASO STO P CESE

FIN GOSU B VAYA SUB

RETO R N E O N E N

BORRE

Statements that may be used In English:

POINT TAB SET.RESET @ (as in PRINT @)

All built-in functions (MEM, INT, ABS, RN D), math operators, relational operators, and logical operators (AND, OR), as well as any Disk Basic features may be used , but they must conform to Disk Basic syntax, not that of level I . For example, PRINT @ is used instead of PRINT AT, and OR instead of + .

The actual translation from Spanish to English is a relatively simple process. The programmer inputs the

INTERFACE AGE 67

desired line in line 580. That line is first checked to see if it begins with one of the seven recognized commands (lines 600-680). Then, the program line is stored in its unchanged version in the string variable UC$ (line 690).

The program next checks for the positions within the line for quotation marks and colons (lines 71 0-81 0). If neither is found, control passes line 850. Otherwise, the program compares the positions of the two quotes (B and B2) with that of the colon (C) to see if the colon occurs between the quotes. If it does not, the line has two statements, and is rejected (line 830). Colons inside the quotation marks (in a PRINT or INPUT statement, for example) are ignored.

Valid line number needed

At line 850, a subroutine begins that checks each character of the line until a space is encountered. The characters up to the first space must be a valid line number, or else the line is rejected . If the line number is OK, then the value is stored in LN (line 91 0), which points to the array element of EP$(n) (Spanish version) or CP$(n) (English version) in which the line will be placed.

A lqop beginning at line 950 searches through the

Stores each Spanish program line as input by user Spaces needed to make English word same length as Spanish equivalent

Position of first quotation mark in program line Position of second quotation mark in program line Colon (CHR$(58))

Stores original program lines, as they appeared before compiling

Counter to keep track of lines displayed on screen English keywords. with spaces to lengthen to Spanish equivalent

English keywords

Stores Spanish. program lines, after compiling Filespec to save original Spanish version of Qu otation mark (CHR$(34))

Space (CHR$(32))

SPAN$(n) Spanish keywords T Loop Counter

W$ Remainder of program line, beginning one position after first quote

WRDS Number of keywords used in Spanish/Bas Y Position of start keyword in program line

68 INTERFACE AGE

read from DATA into an array SPAN$(n). If, using the INSTR function, a keyword is found, control branches to line 1 040. There, the position of the word (Y) is compared with the positions of the quotation marks found previously, if any. Keywords contained in quotes are ignored and the program returns to the loop to spaces are ignored when the compiled program is RUN.

The spaces required are READ from OAT A into (UC$) is stored in EP$(LN). and the translated version in CP$(LN). Entering a new line with the same line number (LN) simply replaces the old line with the new in the array.

The other portions of the program just LIST the two versions, SAVE them, or LOAD them from disk. The subroutine at 1 1 20-1 1 80, for example, checks each ALiSTE command for a line number, and then lists that line, if it exists. If no line number is appended to the ALISTE command, all the lines are listed, 1 0 at a time to keep the program from scrolling off the screen (lines 1 200-1 280). A similar subroutine at lines 1 580-1 640 LISTS the English version.

When the programs written are SAVED or LOADed, the user is asked for the filespec of both versions. Disk Basic saves these in ASCII form, and the English pro­

gram can be loaded and run normally, assuming that the syntax is correct.

A word of warning

Herein lies the problem with all compilers. The pro­

grammer cannot run the program to test it until it has been compiled. Then, the compiled version, if bugs are found, cannot be changed (because the Spanish­

speaking person can 't understand the Basic object code). Because the program is actually being run under an interpreter, the English-speaking person can edit it.

But for those for whom the Spanish/Bas was intended, the object code may mean about as much as a machine language dump.

Because Spanish/Bas was meant to be used as a learning tool by myself and others, I made it extremely simple to change. Keywords may be added by appending them to the proper locations in DATA lines, and adding numeric OAT A that shows the difference in length between the longer Spanish keyword, and the shorter English equivalent. WR in line 1 40 must be changed to reflect the new number of keywords.

This program will compile from any language. The user should select keywords in, say, French and enter them with their English Basic counterparts in the DATA lines. All the prompts in Spanish will have to be changed as well, but these were purposely kept to a minimum in the program. 0

Program on page 1 44

COMPUTERIZED BILLING

Dans le document JUNE 1981 (Page 70-75)

Documents relatifs