Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
reading / 2020 Moler-Mathwork Summary.pdf
Скачиваний:
1
Добавлен:
25.12.2023
Размер:
8.4 Mб
Скачать

A History of MATLAB

81:13

MATLAB maintained this character set as a table with two columns (see Figure 6) that could be modified by the user. Each column has 52 entries; entry was a machine-specific (or operating- system-specific) character code corresponding to MATLAB internal code . This table was used to translate between keyboard characters and MATLAB internal codes.

On input, either of two machine characters could be mapped to the same MATLAB internal code; this allowed lowercase letters to be treated as if they were uppercase, and also allowed programmers to use square brackets (on keyboards that had those characters) rather than angle brackets. Moreover, the function char took an integer as an argument and then read a character (one keypress) directly from the keyboard; it then stored into entry of the first column if ≥ 0, or into entry − of the second column if < 0. In this way a programmer running MATLAB on a system with an unusual keyboard could customize the table for the keyboard, an important aspect of the portability of MATLAB.

On output, straightforward indexing of the table was used to convert internal codes to machine characters. For most purposes the first column was used (and this is why, for example, variables names typed in lowercase are printed in uppercase), but the second column was sometimes used (for example to generate lowercase file names on operating systems for which that was the appropriate convention).

The internal character code was chosen so that the digits have consecutive codes and the letters have consecutive codes (at least one common machine character set of the day, EBCDIC, did not have that property). This is why the MATLAB expression ’A’:’Z’ always produced a row vector of length 26, containing all the letters in order and no other characters—another important contribution to portability.

2.5 Syntax Diagrams

The formal definition of the language, and a kind of flow chart for the parser-interpreter, was provided by 11 syntax diagrams. They defined these eleven syntactic categories: line, statement, clause, expression, term, factor, number, integer, name, command, and text.

Briefly, the recursive core of the language was:

An expression is terms separated by + and - signs.

A term is factors separated by *, / and \ signs.

A factor is a number, a name, or an expression in parentheses ( ).

In the 1970s, Fortran programs could not be recursive. All that meant in practice was that a subroutine could not call itself. So, in the original MATLAB program, EXPR called TERM, TERM called FACTOR, and FACTOR would call EXPR if it encountered a parenthesis. It was necessary to have two arrays, one to manage a stack of subroutine calls, and one to manage the matrices in the workspace.

The complete syntax diagrams, as they appeared in the original line-printer User’s Guide, are presented in Appendix A, with commentary.

2.6 User Function

Classic MATLAB allowed for exactly one external user-defined function, named USER. The user had to write this function in Fortran using a prescribed declaration:

SUBROUTINE USER(A,M,N,S,T)

REAL or DOUBLE PRECISION A(M,N),S,T

This interface allowed MATLAB code to call the USER function with one matrix of any shape and zero, one, or two scalar arguments, and one matrix would be returned. After the external Fortran

Proc. ACM Program. Lang., Vol. 4, No. HOPL, Article 81. Publication date: June 2020.