News:

Welcome to RetroCoders Community

Main Menu

Syntax diagramming valid "lines" of BASIC

Started by CharlieJV, Jun 29, 2023, 10:26 PM

Previous topic - Next topic

CharlieJV

OP initially titled: Description of "Single-Line BASIC Statement"

Instead of potentially getting into various threads related to "what's a valid line of code in BAM/BASIC", I figure best to just have it all in one thread.


Although I'm modeling BAM syntax, any of this is likely going to be mostly similar across BASIC implementations.



I'm right smack in the middle of a "how would I describe that" moment of paralysis by analysis.  The topic of syntax diagrams has grabbed me right by the jugular.

How would we syntactically describe a single-line BASIC statement for any/all BASIC implementations in general?

In my mind, a single-line BASIC statement is an instruction which tells a computer to do something, and a statement generally has (or may have) these parts:

  • (optionally) a line identifier
  • a keyword that represents the instruction to be performed
  • (optionally) one or more "components" (off the top of my head: zero or more parameters, zero or more keywords, like "STEP" for example; I can't think of any other types of components)
  • (optionally) end-of-line comment

Thinking of the gamut of statements available in any BASIC you can imagine, is there anything I'm not thinking of in regards to a single-line statement?

You cannot view this attachment.

ZXDunny

If it helps, SpecBAS enforces:

<line number> <statement[: statement...]>

where a statement is

<keyword> <arguments[;arguments...]>

arguments are whatever the keyword demands, so will vary.

<> are required, [] are optional, ... is an optional repeat. So rather than try to represent what a code line can be in one line, I break it up as above. Your end of line comment is interesting; I wrap that up as a statement in itself due to needing the REM keyword for it.

CharlieJV

Quote from: ZXDunny on Jun 30, 2023, 08:45 AM..snip..
Your end of line comment is interesting; ...snip...

I couldn't figure out what to call that thing, so I decided to just stick with Wikipedia's name for it: "line comment."

A "line comment" is a single quote followed by the text for the comment.  It doesn't need a colon before it.

I'm grouping REM with statements.

But then, I'll have general documentation about commenting and the choices available: single-quote, REM statement, and (I wouldn't use them or recommend them, but they are available) html block-commenting

HTML comment block:
<!-- Multiple lines of comments
 starting with "<!--" and ending with"-->",
 the whole block-quote gets stripped out by the pre-processor
 at runtime and on export. -->

Now, all of that aside ...

Really, a single-line BASIC statement (maybe I should say "single-line single-statement", vs "multi-line single-statement", vs "single-line multi-statement", vs "multi-line multi-statement", vs "statement blocks" ... still not sure what to call all of these) is just:

You cannot view this attachment.



CharlieJV

Defining a "Multi-Statement Line":

You cannot view this attachment.


ZXDunny

Looks good, easy enough to understand an interpret at a glance.

CharlieJV

Just kind of dawned on me, that last "Multi-Statement line" diagram kind of leads to believe that a REM statement can be stuck in there willy-nilly like any other statement.

So if I really want to get that right:

You cannot view this attachment.

Now the neat thing about syntax diagramming, it really has me thinking about everything in BAM.  Kind of exhausting, but still a pretty neat "journey."

CharlieJV

OMG, total "intertwingulitis" over here.  (i.e. paralysis by analysis caused by overwhelming intertwingled thinking...)

I definitely need a second cup of coffee ...

A multi-statement line:

You cannot view this attachment.

ZXDunny

But the syntax of REM overrides the diagram (everything from that point on is ignored), so there's no need for the "not REM" qualifier :)

CharlieJV

Now I can take a needed coffee break, as these seem to work for me:


A simple line:

You cannot view this attachment.

A multi-statement line:

You cannot view this attachment.

CharlieJV

Quote from: ZXDunny on Jul 01, 2023, 04:04 PMBut the syntax of REM overrides the diagram (everything from that point on is ignored), so there's no need for the "not REM" qualifier :)

Yeah, but for the total newb: REM is indeed a statement.  And if it hasn't totally cemented in the newb's head that REM is going to make every other statement after it be treated like part of the remark, then better to explicitly have a "hey, if you are going to use REM in a multi-statement line, do be putting that at the end.