Skip to content

Commit 1d27aff

Browse files
added integer division operator, X DIV Y
1 parent faf2ff9 commit 1d27aff

5 files changed

Lines changed: 125 additions & 113 deletions

File tree

doc/TODO

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ BP - DEC BASIC-PLUS
6969

7070
Debatable:
7171

72+
- it would not be difficult to allow any variable to hold a string, but in most dialects that is an error
73+
74+
- SUB$ from Apple Business BASIC substitutes one string into another. EG, SUB$("Hello!", "**", 2) produces H**lo!
75+
7276
- add TEN function, alias for HEX found in Apple Business BASIC?
7377

7478
- UK BASICs generally use LN for LOG and LOG for CLOG. Add a switch for this?
@@ -85,6 +89,8 @@ Debatable:
8589

8690
Will not be done:
8791

92+
- IP and FP, aliases for FIX and FRAC, too easily overlap with variable names.
93+
8894
- EXAM and FETCH aliases to PEEK from North Star and Opus and similar. No point, this returns 0 anyway.
8995

9096
- WB allows RESTORE to use an ordinal position in the list, as opposed to a line number. There appears to be no easy way to distinguish this.

src/parse.h

Lines changed: 114 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -119,61 +119,62 @@
119119
CSNG = 335,
120120
CDBL = 336,
121121
MOD = 337,
122-
COS = 338,
123-
SIN = 339,
124-
ATN = 340,
125-
ACS = 341,
126-
ASN = 342,
127-
TAN = 343,
128-
COSH = 344,
129-
SINH = 345,
130-
TANH = 346,
131-
ASC = 347,
132-
LEFT = 348,
133-
MID = 349,
134-
RIGHT = 350,
135-
LEN = 351,
136-
STR = 352,
137-
VAL = 353,
138-
CHR = 354,
139-
SEG = 355,
140-
SUBSTR = 356,
141-
INSTR = 357,
142-
INKEY = 358,
143-
AND = 359,
144-
OR = 360,
145-
NOT = 361,
146-
XOR = 362,
147-
CMP_LE = 363,
148-
CMP_GE = 364,
149-
CMP_NE = 365,
150-
CMP_HASH = 366,
151-
FRE = 367,
152-
SPC = 368,
153-
TAB = 369,
154-
POS = 370,
155-
USR = 371,
156-
LIN = 372,
157-
DEFSTR = 373,
158-
DEFINT = 374,
159-
DEFSNG = 375,
160-
DEFDBL = 376,
161-
CHANGE = 377,
162-
CONVERT = 378,
163-
UCASE = 379,
164-
LCASE = 380,
165-
STRNG = 381,
166-
TIME = 382,
167-
TIME_STR = 383,
168-
HEX = 384,
169-
OCT = 385,
170-
BIN = 386,
171-
HEXSTR = 387,
172-
OCTSTR = 388,
173-
BINSTR = 389,
174-
UBOUND = 390,
175-
LBOUND = 391,
176-
LABEL = 392
122+
DIV = 338,
123+
COS = 339,
124+
SIN = 340,
125+
ATN = 341,
126+
ACS = 342,
127+
ASN = 343,
128+
TAN = 344,
129+
COSH = 345,
130+
SINH = 346,
131+
TANH = 347,
132+
ASC = 348,
133+
LEFT = 349,
134+
MID = 350,
135+
RIGHT = 351,
136+
LEN = 352,
137+
STR = 353,
138+
VAL = 354,
139+
CHR = 355,
140+
SEG = 356,
141+
SUBSTR = 357,
142+
INSTR = 358,
143+
INKEY = 359,
144+
AND = 360,
145+
OR = 361,
146+
NOT = 362,
147+
XOR = 363,
148+
CMP_LE = 364,
149+
CMP_GE = 365,
150+
CMP_NE = 366,
151+
CMP_HASH = 367,
152+
FRE = 368,
153+
SPC = 369,
154+
TAB = 370,
155+
POS = 371,
156+
USR = 372,
157+
LIN = 373,
158+
DEFSTR = 374,
159+
DEFINT = 375,
160+
DEFSNG = 376,
161+
DEFDBL = 377,
162+
CHANGE = 378,
163+
CONVERT = 379,
164+
UCASE = 380,
165+
LCASE = 381,
166+
STRNG = 382,
167+
TIME = 383,
168+
TIME_STR = 384,
169+
HEX = 385,
170+
OCT = 386,
171+
BIN = 387,
172+
HEXSTR = 388,
173+
OCTSTR = 389,
174+
BINSTR = 390,
175+
UBOUND = 391,
176+
LBOUND = 392,
177+
LABEL = 393
177178
};
178179
#endif
179180
/* Tokens. */
@@ -257,61 +258,62 @@
257258
#define CSNG 335
258259
#define CDBL 336
259260
#define MOD 337
260-
#define COS 338
261-
#define SIN 339
262-
#define ATN 340
263-
#define ACS 341
264-
#define ASN 342
265-
#define TAN 343
266-
#define COSH 344
267-
#define SINH 345
268-
#define TANH 346
269-
#define ASC 347
270-
#define LEFT 348
271-
#define MID 349
272-
#define RIGHT 350
273-
#define LEN 351
274-
#define STR 352
275-
#define VAL 353
276-
#define CHR 354
277-
#define SEG 355
278-
#define SUBSTR 356
279-
#define INSTR 357
280-
#define INKEY 358
281-
#define AND 359
282-
#define OR 360
283-
#define NOT 361
284-
#define XOR 362
285-
#define CMP_LE 363
286-
#define CMP_GE 364
287-
#define CMP_NE 365
288-
#define CMP_HASH 366
289-
#define FRE 367
290-
#define SPC 368
291-
#define TAB 369
292-
#define POS 370
293-
#define USR 371
294-
#define LIN 372
295-
#define DEFSTR 373
296-
#define DEFINT 374
297-
#define DEFSNG 375
298-
#define DEFDBL 376
299-
#define CHANGE 377
300-
#define CONVERT 378
301-
#define UCASE 379
302-
#define LCASE 380
303-
#define STRNG 381
304-
#define TIME 382
305-
#define TIME_STR 383
306-
#define HEX 384
307-
#define OCT 385
308-
#define BIN 386
309-
#define HEXSTR 387
310-
#define OCTSTR 388
311-
#define BINSTR 389
312-
#define UBOUND 390
313-
#define LBOUND 391
314-
#define LABEL 392
261+
#define DIV 338
262+
#define COS 339
263+
#define SIN 340
264+
#define ATN 341
265+
#define ACS 342
266+
#define ASN 343
267+
#define TAN 344
268+
#define COSH 345
269+
#define SINH 346
270+
#define TANH 347
271+
#define ASC 348
272+
#define LEFT 349
273+
#define MID 350
274+
#define RIGHT 351
275+
#define LEN 352
276+
#define STR 353
277+
#define VAL 354
278+
#define CHR 355
279+
#define SEG 356
280+
#define SUBSTR 357
281+
#define INSTR 358
282+
#define INKEY 359
283+
#define AND 360
284+
#define OR 361
285+
#define NOT 362
286+
#define XOR 363
287+
#define CMP_LE 364
288+
#define CMP_GE 365
289+
#define CMP_NE 366
290+
#define CMP_HASH 367
291+
#define FRE 368
292+
#define SPC 369
293+
#define TAB 370
294+
#define POS 371
295+
#define USR 372
296+
#define LIN 373
297+
#define DEFSTR 374
298+
#define DEFINT 375
299+
#define DEFSNG 376
300+
#define DEFDBL 377
301+
#define CHANGE 378
302+
#define CONVERT 379
303+
#define UCASE 380
304+
#define LCASE 381
305+
#define STRNG 382
306+
#define TIME 383
307+
#define TIME_STR 384
308+
#define HEX 385
309+
#define OCT 386
310+
#define BIN 387
311+
#define HEXSTR 388
312+
#define OCTSTR 389
313+
#define BINSTR 390
314+
#define UBOUND 391
315+
#define LBOUND 392
316+
#define LABEL 393
315317

316318

317319

@@ -329,8 +331,8 @@ typedef union YYSTYPE
329331
variable_reference_t *variable;
330332
}
331333
/* Line 1529 of yacc.c. */
332-
#line 333 "/Volumes/Bigger/Users/maury/Desktop/RetroBASIC/obj/Intermediates.noindex/RetroBASIC.build/Debug/retrobasic.build/DerivedSources/y.tab.h"
333-
YYSTYPE;
334+
#line 335 "/Volumes/Bigger/Users/maury/Desktop/RetroBASIC/obj/Intermediates.noindex/RetroBASIC.build/Debug/retrobasic.build/DerivedSources/y.tab.h"
335+
YYSTYPE;
334336
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
335337
# define YYSTYPE_IS_DECLARED 1
336338
# define YYSTYPE_IS_TRIVIAL 1

src/parse.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static expression_t *make_operator(int arity, int o)
160160
%token INT FIX FRAC // fix=SGN(x)*INT(ABS(x)), frac=A-INT(A)
161161
%token ROUND // two versions, round-to-int and round-to-place
162162
%token CINT CSNG CDBL
163-
%token MOD
163+
%token MOD DIV
164164

165165
/* trig set */
166166
%token COS SIN ATN

src/retrobasic.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,9 @@ static value_t evaluate_expression(expression_t *expression)
11211121
case MOD:
11221122
result = double_to_value((int)floor(a) % (int)floor(b));
11231123
break;
1124+
case DIV:
1125+
result = double_to_value((int)floor(a) / (int)floor(b));
1126+
break;
11241127
case '=':
11251128
if (parameters[0].type >= NUMBER)
11261129
result = double_to_value(-(a == b));

src/scan.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ LIN { return LIN; }
158158
/* various operators and punctuation */
159159
[:,;()\[\]\^=+\-*/\<\>\&] { return yytext[0]; }
160160
MOD { return MOD; }
161+
DIV { return DIV; }
161162

162163
/* alternate form for power */
163164
"**" { return '^'; } // FIXME: we should have a separate token for this?

0 commit comments

Comments
 (0)