Skip to content

Commit 374ae4d

Browse files
committed
Modifies the parser to parse one statement on each parser call.
This makes the IF/THEN accept only one statement at the end, but allows the parser to generate bigger code for the long lines.
1 parent fae34ea commit 374ae4d

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

src/basic.syn

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ PRINT_NEXT:
354354
355355
# Parse multi-line IF
356356
THEN_OR_MULTILINE:
357-
"Then" PARSE_START E_POP_IF
357+
"Then" PARSE_STATEMENT E_POP_IF
358358
pass
359359
360360
VAR_CREATE_TYPE:
@@ -517,7 +517,6 @@ DATA_VAR:
517517
# Parse a line
518518
PARSE_LINE_COMMAND:
519519
"." E_REM
520-
"'" E_REM
521520
"?" IO_CHAN_OPT PRINT_EXPR
522521
"PRint" IO_CHAN_OPT PRINT_EXPR
523522
"INput" INPUT_STR INPUT_VAR_LIST emit TOK_IOCHN0
@@ -577,17 +576,18 @@ PARSE_LINE_ASSIGN: &LOW_ERROR
577576
VAR_FP_LVALUE EQUAL FP_EXPR emit TOK_FP_STORE
578577
#@endif FASTBASIC_FP
579578

580-
PARSE_LINE: statement or variable assignment
579+
SKIP_COMMENT:
580+
"'" E_REM
581+
E_EOL
582+
pass
583+
584+
PARSE_STATEMENT: statement or variable assignment
581585
PARSE_LINE_COMMAND E_EOL
582586
PARSE_LINE_ASSIGN
583-
584-
PARSE_MORE: comment, end of line or new line
585-
":" PARSE_LINE PARSE_MORE
586-
"'" E_REM
587-
E_EOL
587+
pass
588588

589589
PARSE_START:
590-
PARSE_LINE PARSE_MORE
591-
PARSE_MORE
590+
":" PARSE_START
591+
PARSE_STATEMENT SKIP_COMMENT
592592

593593
# vi:syntax=perl

src/compiler/main.cc

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,26 @@ int main(int argc, char **argv)
175175
if( do_debug )
176176
std::cerr << iname << ": parsing line " << ln << "\n";
177177
s.new_line(line, ln);
178-
if( !SMB_PARSE_START(s) || s.pos != line.length() )
178+
while( s.pos != line.length() )
179179
{
180-
std::cerr << iname << ":" << ln << ":" << s.max_pos << ": parse error";
181-
if( !s.saved_error.empty() )
182-
std::cerr << ", expected " << s.saved_error;
183-
std::cerr << "\n";
184-
size_t min = 0, max = s.str.length();
185-
if( s.max_pos > 40 ) min = s.max_pos - 40;
186-
if( s.max_pos + 40 < max ) max = s.max_pos + 40;
187-
for(auto i = min; i<s.max_pos; i++)
188-
std::cerr << s.str[i];
189-
std::cerr << "<--- HERE -->";
190-
for(auto i = s.max_pos; i<max; i++)
191-
std::cerr << s.str[i];
192-
std::cerr << "\n";
193-
return 1;
180+
if( !SMB_PARSE_START(s) || ( s.pos != line.length() && !s.peek(':') ) )
181+
{
182+
std::cerr << iname << ":" << ln << ":" << s.max_pos << ": parse error";
183+
std::cerr << "pos=" << s.pos << ", len=" << line.length() << "\n";
184+
if( !s.saved_error.empty() )
185+
std::cerr << ", expected " << s.saved_error;
186+
std::cerr << "\n";
187+
size_t min = 0, max = s.str.length();
188+
if( s.max_pos > 40 ) min = s.max_pos - 40;
189+
if( s.max_pos + 40 < max ) max = s.max_pos + 40;
190+
for(auto i = min; i<s.max_pos; i++)
191+
std::cerr << s.str[i];
192+
std::cerr << "<--- HERE -->";
193+
for(auto i = s.max_pos; i<max; i++)
194+
std::cerr << s.str[i];
195+
std::cerr << "\n";
196+
return 1;
197+
}
194198
}
195199
}
196200
if( do_debug )

src/parse.asm

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,6 @@ pcall:
306306
pha
307307
bcs parser_sub
308308

309-
call_ax1:
310-
pha
311-
txa
312-
pha
313-
rts
314-
315309
pemit_ret:
316310
jsr emit_sub
317311

@@ -330,6 +324,8 @@ pexit_ok:
330324
; Check if we are at end of line
331325
ldy bpos
332326
lda (bptr), y
327+
cmp #':' ; Colon: continue parsing line
328+
beq parse_start
333329
cmp #$9B
334330
bne set_parse_error
335331
line_ok:
@@ -354,6 +350,12 @@ skip_chars:
354350
tax
355351
bcc ploop_nofetch
356352

353+
call_ax1:
354+
pha
355+
txa
356+
pha
357+
rts
358+
357359
pexit_err:
358360
pla
359361
sta opos

0 commit comments

Comments
 (0)