Statement Structure: Semicolons, Comments and Functions
Rule
; separates two complete statements on one line and never starts a
comment. A comment on the same line as a statement is its own REM statement
after a semicolon: PRINT x; REM show x. A comment on a line of its own is
plain REM text with no semicolon, and a label takes REM with
no semicolon: show: REM text. A function such as MSGBOX() is
not a statement: assign its result, x = MSGBOX(...). An ERR=
or END= option names a label that must exist in the program.
Why
BBj reads a line as statements joined by ;, so whatever follows a
; must itself be a complete statement. Bare text there is not a statement,
and the line fails to compile; REM is the verb that turns text into a
comment. A function returns a value, so it has to appear inside an expression, never on
its own as a statement. The label named by ERR= or END= is
resolved when the program is compiled, so an undefined one is a compile error.
Edge
These forms do not compile: PRINT x ; text and
x = 1 ; this is a note (bare text after ;);
PRINT x REM show x (a REM after a statement with no
;, however wide the padding); MSGBOX("hi") as a statement;
OPEN (1,ERR=NOLABEL)"file" when no NOLABEL label exists (the
compiler reports the label as used but not defined). Keep a comment off the
THEN or ELSE line of a multi-line IF (see
Control Flow in BBj).
PRINT items are separated with ,, not ;:
PRINT a; b fails, because b is not a statement. In a compound
statement REM may only be the last verb.
A function used with the wrong result type is a related trap: FID()
returns a string, so IF FID(1)<=0 THEN does not compile, while
IF FID(1)="LP" THEN does.
METHOD ... METHODEND belongs inside CLASS ...
CLASSEND (BBj Custom Objects); METHOD PUBLIC VOID FOO() at the
top level of a program does not compile.
Evidence
REM Verb -- comments; "In compound statements, REM may only be the last verb."
Commands and Statements -- the statements of a compound statement must be separated by semicolons.
MSGBOX() Function, FID() Function -- both are functions that return a value (a button number; a string).
Error Trapping Rules
-- the ERR=, END= and DOM= clauses that branch to
a label or line.
METHOD Verb, CLASS Verb -- a method is defined inside a Custom Object class.
Compiler result (BBj 26.03): bbjcpl -N rejects
PRINT x ; text, x = 1 ; this is a note,
PRINT x REM show x, MSGBOX("hi") as a statement, an
OPEN whose ERR= label is undefined, PRINT a; b,
IF FID(1)<=0 THEN and a METHOD outside a class, and accepts
PRINT x; REM show x, label: REM text,
x = MSGBOX("hi"), IF FID(1)="LP" THEN and an OPEN
whose ERR= label is defined.
Example
A same-line comment after a semicolon, a label with REM, a function
result assigned, and an ERR= label that exists:
rem 'a same-line comment is its own REM statement after a semicolon
x = 1
print x; rem show x
show: rem a label takes rem with no semicolon
print x
answer = msgbox("Continue?")
open (1,err=nofile)"data.txt"
print "opened"
stop
nofile: print "no such file"
A method inside its class:
class public Greeter
method public void greet()
print "hello"
methodend
classend