BASIC grammar conclusion

Profile picture of MikeHe-creator

Draft

Dec 17, 2023

·

5 min read

·

262 Views


BASIC is a very early computer language. I guess few of people to know this language now. BASIC means Beginners' All-purpose Symbolic Instruction Code. It is a literal programming language that can be executed without compilation and linking procedures after completion of writing. However, if it needs to be executed separately, it still needs to be created into an executable file.

It is still developing and used, now its offspring is VB (Visual Basic).

Luckily, I have touched this "ancient" language in my senior high school math class. BASIC is very simple, and what I learned is basic.

BASIC doesn't mind up case and low case, which is different with many modern languages.

1. Basic sentence:

1. Assignment (LET) statement

2. Keyboard input (INPUT) statement

3. Reading (READ) statement

4. Set the number (DATA) statement [used in conjunction with the reading statement, called the read data (READ/DATA) statement]

5.Restore data area (RESTORE) statement

6. Unconditional transfer (GOTO) statement

7. Conditional transfer (IF~THEN or IF~GOTO) statement

8. Comment (REM) statement

9. Loop description (FOR) statement

10. Loop end (NEXT) statement [combined with loop description statement to loop (FOR~NEXT) statement]

11. Pause (STOP) statement

12. Custom function (DEF) statement

13. Rotor (GOSUB) statement

14. Return (RETURN) statement [used with the rotor statement to call subroutines]

15.Array description (DIM) statement

16.Print (PRINT) statement

17. End (END) statement

2. Sentence definitions commonly used in BASIC language and their meanings

3. Lexical

1. The representation of numbers

There are numeric values in BASIC constant and character constants. A character constant is a string of characters enclosed in quotation marks, also known as a string. The quotation marks are not part of the string, but only serve as the start and end boundaries of the string. Each character occupies one byte in the machine.

In N-BASIC, numerical constants are divided into integer, fixed-point, Floating-point (single and double precision), hexadecimal constant, octal constant, etc.

  1. Second, the representation of variables

variable There are numeric variables and character variables, the former stores numeric values and the latter stores strings. The value of the variable is constantly changing during the execution of the program. When a program executes somewhere, a variable is given a new value, and its original value is "washed out".

3. Operators

1.Arithmetic operators: The arithmetic operation in any mathematical expression is performed according to priority, and the same priority is performed in order from left to right.

2.Assignment operators: When the assignment is indicated by "=", it is called the assignment operator, which is used to assign numeric constants to numeric variables or character-type constants to character-type variables.

3.Relational operators (also known as a comparison operator): A relational operator is used to compare two expressions, each of which is an arithmetic expression. Relational operators can also be used to compare character variables, character constants, character functions, etc.

4. Boolean operators (or Logical operators: Boolean operators are logical operations on one or two expressions.

Fourth, standard functions

The BASIC language is equipped with some commonly used functions, users can call them freely, write a parenthesis after the function name when calling, and write the real argument in the position of X in the parentheses, and the real argument can use constants, variables, expressions or standard functions.

5. Operational rules

at Arithmetic expressions, The priority of the operations can be as follows:

1. Count the brackets first, and remove the brackets from the inside out.

2. Calculate the standard function value.

3. Multiplication.

4. Multiply or divide: from left to right.

5. Addition or subtraction: from left to right.

The precedence of other operations is arranged according to the previous arithmetic operators.

6. BASIC expressions

A complex operation object that connects numbers, variables, functions, and array elements with BASIC-compliant operation symbols is called a BASIC expression. Note that each symbol in the BASIC expression occupies a space, and all symbols must be written on a horizontal line one after the other, and cannot appear in the upper right or lower left corner.

EXAMPLE

PROGRAM product
LET M = 2                         
LET A = 4                        
LET FORCE = m*a 
IF FORCE > 0:
   PRINT force
ELSE
   PRINT A
END

Profile picture of MikeHe-creator

Written By

Who-am-I?

No bio found