Re: Unexpected behaviour "END PROC"

Discussions related to the BB4W & BBCSDL interpreters and run-time engines
User avatar
STOS
Posts: 12
Joined: Sun 15 Oct 2023, 10:49

Unexpected behaviour "END PROC"

Post by STOS »

Hi,

Can anyone shed some light on this behaviour as I've tried searching the forum but the search phrase is too common, yet too common it can't help?

Program A - Passes interpretation without any syntax error thrown for "END PROC" instead of "ENDPROC", but seems to NOT run?

Code: Select all

PROCa
PROCb
END

DEF PROCa
...
END PROC

DEF PROCb
...
END PROC

DEF PROCc
...
END PROC

DEF PROCd
...
END PROC
Program A - Passes interpretation without any syntax error thrown again, but runs even though only the first ENDPROC is valid syntax?

Code: Select all

PROCa
PROCb
END 

DEF PROCa
...
ENDPROC

DEF PROCb
...
END PROC

DEF PROCc
...
END PROC

DEF PROCd
...
END PROC
Bug?, feature?, or quirk?

If "END PROC" doesn't mean anything else other than "ENDPROC", then it would be nice if they were interchangeable much like "DEF PROC" and "DEFPROC".

Again, am I missing a side note within the manual somewhere?

BBC BASIC syntax error checking in versions for BBC Micro, Acorn v5, Matrix Brandy all work as expected. BBC4W and BBCSDL do not.
Last edited by STOS on Wed 27 Mar 2024, 13:42, edited 1 time in total.
User avatar
STOS
Posts: 12
Joined: Sun 15 Oct 2023, 10:49

Re: Unexpected behaviour "END PROC"

Post by STOS »

I've had a reply from rob over at groups.io

To start off with groups.io trashes source code so please take a look on the forum for clarity.

I totally understand the reason for the behaviour, the problem (to put it bluntly) is that this dialect of BBC BASIC doesn't follow the syntax of "real" BBC BASIC.
So unless it is fixed, then should it be called BBC BASIC for Windows or SDL?

A mis-placed space in someones source code can cause a headache catching a stupid error which SHOULD be picked up by the parser/lexer and throw a syntax error like original BBC Micro, Acorn v5, Matrix Brandy etc.

The only versions I haven't tried it on are Richards Z80, 86 Plus or the console version.

It just does nothing, which is even worse.

Surely the syntax of a language should be paramount if it is replicating an existing specification.

I'm sure this is just a bug and Richard may fix it if he deems it important.
DDRM

Re: Unexpected behaviour "END PROC"

Post by DDRM »

Hi STOS,

I don't think your analysis is correct! These BBC BASIC variants DO implement the spec correctly - it is what YOU are doing that doesn't make sense!

If you use DEFPROC and ENDPROC correctly, all will be well!

If you use END PROC, the interpreter will (correctly) interpret and tokenise the first word as END, and end the program. That's perfectly valid syntax, and the interpreter should handle it accordingly.

DEF is a keyword in its own right, so DEF PROC works, and DEFPROC (and DEFFN) work because it completes one token and then another one.

So in my view it isn't a bug, it was a misunderstanding by you of how the interpreter will handle END PROC. If you look at the manual, it is quite clearly laid out.

Best wishes,

D
myst
Posts: 1
Joined: Thu 28 Mar 2024, 12:14

Re: Unexpected behaviour "END PROC"

Post by myst »

the first quits after going to proca and second on probc as expected on hitting a 'end '

though i would say a adjustment to lexer-parser(or the editor) to detect the procedure is't being closed would be useful, i seem to remember !zap or one of its addons did this in the 90s
DDRM

Re: Unexpected behaviour "END PROC"

Post by DDRM »

Richard saw this when it got cross-posted to the group.io discussion group, and emailed me the following, which he is happy for me to post here. I hope it will clarify the situation for everyone. You might want to take note of the comments later on that a syntax checker has to handle VALID code correctly, but that behaviour with invalid code is not (always) determined, and that interpreted languages do not usually do syntax checking for coding errors.

I've posted it verbatim: regular users of the forum will be aware that Richard has strong views and can express them more forcefully than I would encourage others to do, but since this is essentially a support forum for his product, I think it appropriate to allow him some extra latitude.

Best wishes,

D

STOS> I totally understand the reason for the behaviour, the problem (to
put it bluntly) is that this dialect of
STOS> BBC BASIC doesn't follow the syntax of "real" BBC BASIC.

Needless to say I resent any suggestion that my implementations of BBC
BASIC are any less "real" than Sophie's. They are contemporary with
hers (I was already working on BBC BASIC Z80 in mid 1981) and in my rôle
at the BBC I had more responsibility for the language specification than
anybody at Acorn!

It is of course true that the BBC's specification of the language left
plenty of details open to interpretation, and inevitably the 'Wilson'
and 'Russell' strands diverged slightly as a result (sometimes through a
deliberate decision to do things differently, sometimes by accident) but
they are both BBC BASIC.

It's worth noting that Sophie made some changes in ARM BASIC V which
introduced incompatibilities with the earlier 6502 BASICs, that I
consider to have been unwise and which I never adopted in mine. To that
extent my BASICs are more similar to the original BBC Micro BASIC than
Sophie's, should ARM BASIC V therefore not be called 'BBC BASIC'? ;-)

STOS> A mis-placed space in someones source code can cause a headache
catching a stupid error which SHOULD
STOS> be picked up by the parser/lexer and throw a syntax error like
original BBC Micro, Acorn v5, Matrix Brandy etc.

I disagree. As a general rule interpreted languages don't do any syntax
checking purely for the purpose of detecting coding errors, since this
adds an overhead at runtime which hits performance. The only errors
they detect and report are ones which result in the interpreter not
being able to make sense of the code, and so prevent execution continuing.

END PROC is not in that category, END is a perfectly valid statement and
(unlike QUIT) takes no parameters, so it is valid for the interpreter to
conclude that the intention is for the program to terminate, so it does
(without any error being detected).

> Surely the syntax of a language should be paramount if it is
replicating an existing specification.

The syntax of a programming language tells you only about *valid* code,
that is it tells you what code which adheres to that syntax should do.
But it says nothing at all about what should happen in the case of code
which does *not* adhere to that syntax. There is no implication that an
error should be reported, that would require a full syntax checker,
something which no interpreted language has.

So code which does not adhere to the language syntax can legitimately do
*anything at all*. You can't complain if code containing a particular
mistake behaves different in one BBC BASIC dialect compared with
another, that is entirely to be expected (indeed is virtually inevitable
unless the interpreters themselves are identical).

STOS> I'm sure this is just a bug and Richard may fix it if he deems it
important.

It's not a bug and nothing is going to be changed.