B-- is a toy programming language based on BASIC programming language. It is made using lex and bison.
- Variable Names: Single Upper-Case Letter (A – Z) followed by an optional single digit (0 – 9). Example: A, F, H, A0, Z9
- Data Types: Numeric – Integer (%), Single Precision (!), Double Precision (#) & Strings ($).
- Type declaration uses special characters along with variable names as given above. Example: P1# (double precision), N$ (string), A9 (integer), M! (single precision)
Operator | Operation | Example |
---|---|---|
() | Parenthesis | (X + Y) |
^ | Exponentiation | X ^ Y |
- | Negation | -X |
*, / | Multiplication / Division | X * Y, X / Y |
+, - | Addition / Subtraction | X + Y, X - Y |
Operator | Operation | Example |
---|---|---|
= | Equality | X = Y |
<> | Inequality | X <> Y |
< | Less Than | X < Y |
> | Greater Than | X > Y |
<= | Less than or equal to | X <= Y |
>= | Greater than or equal to | X >= Y |
NOT, AND, OR, XOR
NOTE: In case of equal precedence evaluation for operators is done from left-to-right.
-
The DATA statement is used to contain values that will be later used by the READ statement. Example:
DATA 3.14159, “PI”
-
The DEF statement is used to define a user-defined function of one numeric variable or a pseudo-constant. Example:
DEF FNF(X) = X^4 – 1
DEF FNP = 3.14159
-
The DIM statement is used to specify non-default sizes of numeric arrays. Example:
DIM A(6), B(10,20)
-
The END statement is used to specify the end of the source program.
END
-
The FOR statement is used for coding pre-test loops that use an index numeric variable. Example:
10 FOR X=1 TO 9 STEP 4 20 PRINT X 30 NEXT X 40 PRINT "AFTER LOOP X IS"; X 50 END
-
The GOSUB statement is used to call a subroutine.
-
The IF statement is used to branch conditionally to a new statement. Example:
IF F<>1 THEN 260
IF A$="Y" THEN 170
-
The LET statement is used to assign a value to a variable. Examples:
LET A(X,3) = X*Y – 1
LET A$ = “ABC”
-
The INPUT statement is used to read data into one or more variables from the keyboard. Example:
INPUT X
-
The PRINT statement is used to send output to the terminal. Example:
PRINT “X = ”, 10
-
The REM statement is used to add a comment to the source code of the program.
-
The RETURN statement is used to exit a subroutine that was entered with GOSUB and continue execution on the line immediately following the GOSUB that invoked the subroutine.
-
The STOP statement will halt execution of the program immediately.
-
Clone the repository and extract the zipped files.
-
Open terminal and navigate to the extracted folder using
cd
command. -
Install Lex and Yacc on your device.
-
To compile the lex and yacc file run the following command:
$lex BMM_Scanner.l $yacc -d BMM_Parser.y
This will create a new file
lex.yy.c
, then run the following command to compile it:$gcc lex.yy.c y.tab.c -o b--
-
To run this file run the following command:
$./b--
-
You will get the desired output in the
output.txt
file.
Ajaybeer Singh (2021CSB1063)
Akanksh Caimi (2021CSB1064)