Skip to content

Commit de8fe86

Browse files
added support for INSTR, as well as the most common alternatives, POS and INDEX. this supports both common formats, with the optional starting position in the first or last parameter
updating version to 1.8.7
1 parent d8150b4 commit de8fe86

File tree

8 files changed

+183
-89
lines changed

8 files changed

+183
-89
lines changed

bas/test.bas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@
131131
1910 PRINT "using SPACE$, should print three spaces and HELLO: ";SPACE$(3);"HELLO"
132132
1920 PRINT "using STRING$, should print HELLO three times: ";STRING$("HELLO",3)
133133
1930 PRINT "using STRING$ with ASCII value, should print three X's: ";STRING$(88,3)
134+
1940 PRINT "using INSTR to find ELL in HELLO, should print 2: ";INSTR("HELLO","ELL")
135+
1950 PRINT "using INSTR to find JEL in HELLO, should print 0: ";INSTR("HELLO","JEL")
136+
1960 PRINT "using INSTR to find ELL in HELLO starting at 2, should print 0: ";INSTR("HELLO","JEL",2)
137+
1970 PRINT "using POS to find ELL in HELLO, should print 2: ";POS("HELLO","ELL")
138+
1980 PRINT "using INDEX to find ELL in HELLO, should print 2: ";INDEX("HELLO","ELL")
139+
1985 PRINT "using POS with single parameter, should print cursor position: ";POS(0)
140+
1985 PRINT "using POS with no parameter, should print cursor position: ";POS(0)
134141
2000 REM
135142
2001 REM bin/oct/hex conversions
136143
2002 REM

doc/TODO

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ WB = Wang BASIC
99
PA = Palo Alto Tiny BASIC
1010
BP - DEC BASIC-PLUS
1111

12-
- add INSTR and variations thereof
12+
- trunc values for single and integer during calculations depending on the variable type
13+
14+
- add INKEY$
1315

1416
- need to allow multiple INPUTs on a single line, currently it requires a CR between values
1517

@@ -27,7 +29,7 @@ BP - DEC BASIC-PLUS
2729

2830
- support Dartmouth/ANSI style FOR loops which skip the body if the test fails on the first loop
2931

30-
- ELSE would be realtively easy to add, at least the single-line variety
32+
- ELSE would be relatively easy to add, at least the single-line variety
3133

3234
- flesh out GET and PUT, which are just placeholders for now
3335

doc/VERSIONS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ Version 1.8.5 - 16 November 2023
9898
Version 1.8.6 - 23 November 2023
9999

100100
- fix problem in array initialization that was causing amazing.bas to fail
101+
102+
Version 1.8.7 - 10 December 2023
103+
104+
- add INSTR string function, and the INDEX alias

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/* simple version info for --version command line option */
2828
static void print_version(void)
2929
{
30-
puts("RetroBASIC 1.8.6");
30+
puts("RetroBASIC 1.8.7");
3131
}
3232

3333
/* usage short form, just a list of the switches */

src/parse.h

Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -130,40 +130,41 @@
130130
CHR = 346,
131131
SEG = 347,
132132
SUBSTR = 348,
133-
AND = 349,
134-
OR = 350,
135-
NOT = 351,
136-
XOR = 352,
137-
CMP_LE = 353,
138-
CMP_GE = 354,
139-
CMP_NE = 355,
140-
CMP_HASH = 356,
141-
FRE = 357,
142-
SPC = 358,
143-
TAB = 359,
144-
POS = 360,
145-
USR = 361,
146-
LIN = 362,
147-
DEFSTR = 363,
148-
DEFINT = 364,
149-
DEFSNG = 365,
150-
DEFDBL = 366,
151-
CHANGE = 367,
152-
CONVERT = 368,
153-
UCASE = 369,
154-
LCASE = 370,
155-
STRNG = 371,
156-
TIME = 372,
157-
TIME_STR = 373,
158-
HEX = 374,
159-
OCT = 375,
160-
BIN = 376,
161-
HEXSTR = 377,
162-
OCTSTR = 378,
163-
BINSTR = 379,
164-
UBOUND = 380,
165-
LBOUND = 381,
166-
LABEL = 382
133+
INSTR = 349,
134+
AND = 350,
135+
OR = 351,
136+
NOT = 352,
137+
XOR = 353,
138+
CMP_LE = 354,
139+
CMP_GE = 355,
140+
CMP_NE = 356,
141+
CMP_HASH = 357,
142+
FRE = 358,
143+
SPC = 359,
144+
TAB = 360,
145+
POS = 361,
146+
USR = 362,
147+
LIN = 363,
148+
DEFSTR = 364,
149+
DEFINT = 365,
150+
DEFSNG = 366,
151+
DEFDBL = 367,
152+
CHANGE = 368,
153+
CONVERT = 369,
154+
UCASE = 370,
155+
LCASE = 371,
156+
STRNG = 372,
157+
TIME = 373,
158+
TIME_STR = 374,
159+
HEX = 375,
160+
OCT = 376,
161+
BIN = 377,
162+
HEXSTR = 378,
163+
OCTSTR = 379,
164+
BINSTR = 380,
165+
UBOUND = 381,
166+
LBOUND = 382,
167+
LABEL = 383
167168
};
168169
#endif
169170
/* Tokens. */
@@ -258,40 +259,41 @@
258259
#define CHR 346
259260
#define SEG 347
260261
#define SUBSTR 348
261-
#define AND 349
262-
#define OR 350
263-
#define NOT 351
264-
#define XOR 352
265-
#define CMP_LE 353
266-
#define CMP_GE 354
267-
#define CMP_NE 355
268-
#define CMP_HASH 356
269-
#define FRE 357
270-
#define SPC 358
271-
#define TAB 359
272-
#define POS 360
273-
#define USR 361
274-
#define LIN 362
275-
#define DEFSTR 363
276-
#define DEFINT 364
277-
#define DEFSNG 365
278-
#define DEFDBL 366
279-
#define CHANGE 367
280-
#define CONVERT 368
281-
#define UCASE 369
282-
#define LCASE 370
283-
#define STRNG 371
284-
#define TIME 372
285-
#define TIME_STR 373
286-
#define HEX 374
287-
#define OCT 375
288-
#define BIN 376
289-
#define HEXSTR 377
290-
#define OCTSTR 378
291-
#define BINSTR 379
292-
#define UBOUND 380
293-
#define LBOUND 381
294-
#define LABEL 382
262+
#define INSTR 349
263+
#define AND 350
264+
#define OR 351
265+
#define NOT 352
266+
#define XOR 353
267+
#define CMP_LE 354
268+
#define CMP_GE 355
269+
#define CMP_NE 356
270+
#define CMP_HASH 357
271+
#define FRE 358
272+
#define SPC 359
273+
#define TAB 360
274+
#define POS 361
275+
#define USR 362
276+
#define LIN 363
277+
#define DEFSTR 364
278+
#define DEFINT 365
279+
#define DEFSNG 366
280+
#define DEFDBL 367
281+
#define CHANGE 368
282+
#define CONVERT 369
283+
#define UCASE 370
284+
#define LCASE 371
285+
#define STRNG 372
286+
#define TIME 373
287+
#define TIME_STR 374
288+
#define HEX 375
289+
#define OCT 376
290+
#define BIN 377
291+
#define HEXSTR 378
292+
#define OCTSTR 379
293+
#define BINSTR 380
294+
#define UBOUND 381
295+
#define LBOUND 382
296+
#define LABEL 383
295297

296298

297299

@@ -309,7 +311,7 @@ typedef union YYSTYPE
309311
variable_reference_t *variable;
310312
}
311313
/* Line 1529 of yacc.c. */
312-
#line 313 "/Volumes/Bigger/Users/maury/Desktop/RetroBASIC/obj/Intermediates.noindex/RetroBASIC.build/Debug/retrobasic.build/DerivedSources/y.tab.h"
314+
#line 315 "/Volumes/Bigger/Users/maury/Desktop/RetroBASIC/obj/Intermediates.noindex/RetroBASIC.build/Debug/retrobasic.build/DerivedSources/y.tab.h"
313315
YYSTYPE;
314316
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
315317
# define YYSTYPE_IS_DECLARED 1

src/parse.y

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ static expression_t *make_operator(int arity, int o)
162162
%token LEFT MID RIGHT
163163
%token LEN STR VAL CHR
164164
%token SEG SUBSTR
165+
%token INSTR
165166

166167
/* boolean operations and comparisons */
167168
%token AND OR NOT XOR
@@ -176,22 +177,18 @@ static expression_t *make_operator(int arity, int o)
176177
%token LIN // from HP, a vertical version of TAB
177178

178179
/* type definitions added circa 1979 */
179-
%token DEFSTR
180-
%token DEFINT
181-
%token DEFSNG
182-
%token DEFDBL
180+
%token DEFSTR DEFINT DEFSNG DEFDBL
183181

184182
/* Dartmouth-style string manipulation */
185183
%token CHANGE
186184
/* otherwise identical command from HP */
187185
%token CONVERT
188186
/* and some later string-related additions */
189-
%token UCASE
190-
%token LCASE
187+
%token UCASE LCASE
191188
/* string builders */
192189
%token STRNG
193190

194-
/* time and date patterened on MS style */
191+
/* time and date patterned on MS style */
195192
%token TIME
196193
%token TIME_STR
197194

@@ -200,10 +197,9 @@ static expression_t *make_operator(int arity, int o)
200197
%token HEXSTR OCTSTR BINSTR
201198

202199
/* array utilities */
203-
%token UBOUND
204-
%token LBOUND
200+
%token UBOUND LBOUND
205201

206-
/* line lables, procedures, etc. */
202+
/* line labels, procedures, etc. */
207203
%token LABEL
208204

209205
%%
@@ -1069,6 +1065,8 @@ fn_2:
10691065

10701066
/* arity-1, 2 or 3 functions */
10711067
fn_x:
1068+
INSTR { $$ = INSTR; } |
1069+
POS { $$ = POS; } |
10721070
MID { $$ = MID; } |
10731071
SEG { $$ = SEG; } |
10741072
SUBSTR { $$ = SUBSTR; } |

0 commit comments

Comments
 (0)