Language Design: Basis

Programming, for all ages and all languages.
Schol-R-LEA

Re:Language Design: Basis

Post by Schol-R-LEA »

OK, while it is probably a bit early for this, perhaps a bit of the grammar definition should be set, so I'll start by proposing a few things. Mind you, these suggestions are more influenced by VB than QBasic, so it is likely that others will want a different approach for some things. I've also added and changed a few things; these can be considered proposals rather than hard decisions.

Code: Select all

<line comment> ::= ["REM"|"'"] {<printable character>}+ <newline>

<declaration> ::= "DIM" <variable> {"," <variable>}* "AS" <type>{"(" [<constant>|<variable>] ")"}

<simple conditional> ::= "IF" <boolean clause> "THEN" <block> {"ELSEIF" <boolean clause> "THEN" <block>}* {"ELSE" <block>} "ENDIF"
 
<compound conditional> ::= "WHERE" [<guarded conditional>|<multiple conditional>] "ENDWHERE"

<guarded conditional> ::= "VALUE" "OF" <variable> <is sequence>

<is sequence> ::= {<is statement>}+ "IS" "DEFAULT" ":" <block> "ENDIS"

<is statement> ::= "IS" <value> {"," <value>}+ ":" <block> ["ENDIS"| "FALLTHRU"]

<multiple conditional> ::= {<result statement>}+ "RESULT"  "DEFAULT" ":" <block> "ENDRESULT"
 
<result clause> ::= "RESULT" "OF" <boolean clause> "IS" <block> "ENDRESULT"

<unconditional loop> ::= "DO" <block> "ENDDO"

<opening-conditional loop> ::= ["WHILE"|"UNTIL"] <boolean clause> <unconditional loop>

<closing-conditional loop> ::=  <unconditional loop> ["WHILE"|"UNTIL"] <boolean clause>

<for loop> ::= "FOR" <variable> "FROM" [<constant>|<variable>] ["TO"|"DOWNTO"] [<constant>|<variable>] "STEP" [<constant>|<variable>] <unconditional loop>

<for-each loop> ::= "FOR EACH" <variable> "IN" [<array variable>|<collection variable>] {"USING" <iterator function>} <unconditional loop> 
I left [tt]<printable character>[/tt] undefined since I'm sure that the issue of ASCII vs LATIN-1 vs Unicode will come up. I realize that the [tt]ENDIF[/tt], etc. is somewhat controversial, but I thought it justifiable.

I have also combined all the loop constructs so that the all use a single looping primitive, [tt]DO[/tt]. The different types of conditional loops are all basically variants in this.

I've also come up with a new construct, [tt]WHERE[/tt], which combine both the [tt]SELECT CASE[/tt] form from VB (which is now [tt]VALUE OF... IS[/tt], a more easiyl readable form IMAO) with a new [tt]RESULT OF..IS[/tt], which is somewhat like a [tt](cond)[/tt] statement in Lisp. While it is somewhat redundant (the [tt]IF..THEN..ELSEIF..ELSE[/tt] handles it more or less), it does make it clearer that there are several options in a row coming. Note that the default clause is not optional, though it can be empty.
kyle

Re:Language Design: Basis

Post by kyle »

ah thanks for clarifying that for me. :)

On the character set subject, I'm for Unicode, my argument is if a person wants to use basic then they are not looking for speed.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Language Design: Basis

Post by Candy »

Schol-R-LEA wrote: OK, while it is probably a bit early for this, perhaps a bit of the grammar definition should be set, so I'll start by proposing a few things. Mind you, these suggestions are more influenced by VB than QBasic, so it is likely that others will want a different approach for some things.
I must say, some of these are completely unknown for me when thinking back to basic.

WHILE ... WEND
DO ... LOOP

and the DO WHILE / DO UNTIL / LOOP WHILE / LOOP UNTIL were only useful in qb, in vb they constantly caused my programs to tightloop :(

IF was ended by an END IF, separated with a space.

And in some far way I recall something similar to switch or select to be in there too, just don't recall the name... It didn't have a default case though, and it didn't fallthrough (which still confuses lots of people)..

For the pointer issue, I finally agree with you that adding the pointers is too hard for basi[cs] users. Though, that would make the MM package impossible. As for the basis for BASIS (pun intended :P) I would be at the right place with AtlantisOS right now. It follows orders such as mapping memory or allocating memory just like the BASIS basis would need to do, and it can just comply with everything basis would want to do.

One small but big detail, how do you rip out the file opening/closing functionality in basic without damaging the language too much? Obviously, it has to be custom made by the author, or based on OS calls (which can be done with ASM). Still, it's hard..

Also, what do we do with the differing function or subroutine calls? It seems to me that having both is ridiculous, but ripping out one or the other doesn't seem right. And, aside from that part, there's still things like PSET and LINE which have really awkward calling conventions (LINE (x,y)-(x-y),c,t and PSET (x,y),c,t) which cannot be really represented in any form of header, but are clear... how do you treat them?

C&CW, Candy
Schol-R-LEA

Re:Language Design: Basis

Post by Schol-R-LEA »

Oops. I made some changes since then; you might want to look at what I have now.

I realize that this is quite different from the existing Basics. Part of the reason I did that was to make a point: just because you want Basis to be like QBasic, there is no reason to slavish in copying QB exactly. If there is a construct that you think could be done in a better way than it is now, feel free to mention it, so that we can all consider it. Despite it's origins, Basis may well end up a very different language fro QBasic, if that's the direction it goes in.

I must also admit that I don't recall QB specifically very well.
kyle

Re:Language Design: Basis

Post by kyle »

Candy wrote: And in some far way I recall something similar to switch or select to be in there too, just don't recall the name... It didn't have a default case though, and it didn't fallthrough (which still confuses lots of people)..
are you talking about SELECT CASE / END SELECT ?
Schol-R-LEA

Re:Language Design: Basis

Post by Schol-R-LEA »

It sounds like it. In the proposal above, the equivalent of the VB

Code: Select all

SELECT n
   CASE 1, 2: 
         ...
   CASE 3: 
         ...
   CASE 4: 
         ...
   ELSE 
         ...
END SELECT
is

Code: Select all

WHERE VALUE OF n 
   IS 1, 2: 
          ...
   ENDIS
   IS 3: 
          ...
   ENDIS
   IS 4: 
          ...
   ENDIS
   IS DEFAULT: 
          ...
   ENDIS
ENDWHERE
While it breaks precedent, I think it should be easier to read, hence the proposal.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Language Design: Basis

Post by Candy »

Schol-R-LEA wrote: I realize that this is quite different from the existing Basics. Part of the reason I did that was to make a point: just because you want Basis to be like QBasic, there is no reason to slavish in copying QB exactly. If there is a construct that you think could be done in a better way than it is now, feel free to mention it, so that we can all consider it. Despite it's origins, Basis may well end up a very different language fro QBasic, if that's the direction it goes in.
As for me, I'd start out with QBASIC (as I suggested in the first reply, only a few hours ago... damn this thread is fast) and modify it to only change on the points that don't fit or could be done better. Changing the end of an IF sequence from "END IF" to "ENDIF" isn't a real improvement in any way, and only confuses a lot of people. Also, it adds another keyword, which isn't necessary. I cannot see why you did that?

What is your intent with :
WHERE
RESULT OF
IS
DEFAULT
and things like that? I don't recall seeing them ever?

FOR was formulated as something like

Code: Select all

FOR x = 1 to 211 step 5
in my memory, so that would not amount to a FROM or DOWNTO. What do you want with them?

The FOR EACH seems like a good addition to me, don't see how you want to use a default container with it though. Also, what's the USING doing there?

And for the last thing I don't like, *gets down on his knees* please please please do not add a fallthrough.... *begs*
I must also admit that I don't recall QB specifically very well.
Who in the field of OS programming does have recent basic experience? My most recent adventure was a library that was waaay out of league for basic. It was also my biggest project and ran into a number of limits in QBASIC (or actually QUICKBASIC) that I didn't forsee. It was limited by the maximum filesize (100k), the speed and the outside interfacing. It ran in 1024*768*32bit colors with a translucent mouse cursor that only made 0.5FPS on my 233mhz computer... I submitted it to some QBASIC sites back then and since I explicitly put it in public domain, some people (*ahum*) took the code and made their own SVGA libs with mouse support... As for my code, it was never published, not even verbatim. I was pissed off (as any 14-year old would be) so I quit QB programming.

*RACE CONDITION!*
are you talking about SELECT CASE / END SELECT ?
yep. exactly.

For the IS, WHERE and stuff, why would you want that? It adds a lot of keywords, and contains a lot of keywords with no real meaning attached to them. The point of KEY words is that they in themselves indicate something, so just having that key word would be enough. My main point is, this language is not going to be for only US people, or only english speaking people, so these keywords are going to be learned by most people anyway. I mispronounced most keywords until I was 12 :)

Adding a lot of new and different keywords obscures BASIS from the existing set of basics with no real purpose than making it clearer to most new users. However, if you explain it really simple, as a selection between cases (which is what the QBASIC designers must've thought), so it's like a list of IF's, it's a lot clearer, without adding a shitload of keywords. Seems a better solution to me...

C&CW, Candy
Schol-R-LEA

Re:Language Design: Basis

Post by Schol-R-LEA »

Candy wrote:
As for me, I'd start out with QBASIC (as I suggested in the first reply, only a few hours ago... damn this thread is fast) and modify it to only change on the points that don't fit or could be done better. Changing the end of an IF sequence from "END IF" to "ENDIF" isn't a real improvement in any way, and only confuses a lot of people. Also, it adds another keyword, which isn't necessary. I cannot see why you did that?
Mostly it seemed that it would be easier to parse than two separate words; but I don't see it as a big deal either way. If you'd rather use [tt]END IF[/tt], that's fine. Also, looking back at it, the single word form is harder to read, so you have a point on that.
What is your intent with :
WHERE
RESULT OF
IS
DEFAULT
and things like that? I don't recall seeing them ever?
It's a completely new proposal; I thought I'd add it, though there wasn't anything quite like it before, to see what people thought of it. Part of it I explained, as an alternate form for the [tt]SELECT CASE[/tt] statement; part of it something new, a multiway conditional like the (cond) statement in Lisp:

Code: Select all

WHERE 
      RESULT OF x >= y IS 
          ...
      END RESULT
      RESULT OF y > z IS 
          ...
      END RESULT
      RESULT DEFAULT IS
          ...
      END RESULT
END WHERE



However, it is somewhat redundant, and not really necessary.
FOR was formulated as something like

Code: Select all

FOR x = 1 to 211 step 5
in my memory, so that would not amount to a FROM or DOWNTO. What do you want with them?
[me=Schol-R-LEA]kicks self[/me]
Damn it, I got confused; that's the Pascal [tt]FOR[/tt] syntax. My mistake. It should be:

Code: Select all

<for loop> ::= "FOR" <variable> "=" [<constant>|<variable>] "TO"  [<constant>|<variable>] {"STEP" [<constant>|<variable>]} <unconditional loop>
The FOR EACH seems like a good addition to me, don't see how you want to use a default container with it though.
The basic FOR EACH is used in VB a lot; I think it first appeared in Icon. Python, Perl and most Lisps have some variant of it, and there is a for_each() method in the C++ STL IIRC.
Also, what's the USING doing there?
It another proposed construct of mine; it allows you to have your own iterator, instead of just a default one. So if you define your own collection type or class (if we allow that, which isn't necessarily the case given the design goals) you can have a function to step through the collection in the order you'd want it to. So, for example, if you have a tree collection, you could have a function IterTopDown which would be called by the [tt]USING[/tt] statement

Code: Select all

FOR EACH n in MyStack USING IterTopDown DO
    ...
END DO
and it would get the last n as an argument, and iterate through each level of the tree sequentially. Again, this is an added proposal to the existing [tt]FOR EACH[/tt] syntax, meant to make it more flexible. Without the [tt]USING[/tt] clause, it would just use some default order.
And for the last thing I don't like, *gets down on his knees* please please please do not add a fallthrough.... *begs*
OK. That was a part I wasn't sure about; there seem to be divided opinions on it. I mostly added it because I felt that it was better to have an explicit fallthrough statement rather than have it be the default, as in C.
I must also admit that I don't recall QB specifically very well.
Who in the field of OS programming does have recent basic experience?
Good point.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Language Design: Basis

Post by Candy »

If I may give one idea about another language that might put Basic back in the league for application programming along with C++, Java and Delphi, it would be some form of OOP-Basic but then with real oop. Preferably designed with C++ compatibility in mind, so the objects could be sent back & forward like it's nothing between the two, and so I can make a simple c++ stdlib usable by both :D

It seems something I would, even after this time since basic, still like to see.

For the original thread, array bounds checking needs to know the bounds of the array. How do you do that transparently (* in an OS)? Or do we make it a compiler flag?

Also, I was thinking, I currently use some nice hacks for some bits of memory to appear instantly if I try to refer to them, because I'm too lame to register them explicitly myself. Seems impossible with BASIS?

gtg, Candy
srg

Re:Language Design: Basis

Post by srg »

What you want is already there for application development, it's Visual Basic.NET, it really is real OOP VB (so much so that VB6 programmers have called it Visual Fred), and mainly the brainchild of the guy that headed Delphi. Saying that VB.NET is managed code YUCK! >:(

As for the BASIS, hmm... I've always profered Pascal to basic IMHO it's a vastly better language.
Candy wrote: If I may give one idea about another language that might put Basic back in the league for application programming along with C++, Java and Delphi, it would be some form of OOP-Basic but then with real oop. Preferably designed with C++ compatibility in mind, so the objects could be sent back & forward like it's nothing between the two, and so I can make a simple c++ stdlib usable by both :D

It seems something I would, even after this time since basic, still like to see.

For the original thread, array bounds checking needs to know the bounds of the array. How do you do that transparently (* in an OS)? Or do we make it a compiler flag?

Also, I was thinking, I currently use some nice hacks for some bits of memory to appear instantly if I try to refer to them, because I'm too lame to register them explicitly myself. Seems impossible with BASIS?

gtg, Candy
Schol-R-LEA

Re:Language Design: Basis

Post by Schol-R-LEA »

Here are some suggestions regarding expression syntax:

Code: Select all

<statement> ::=  <declaration> <newline>
               | <assignment> <newline>
               | <subroutine call> <newline>
               | <conditional> <newline>
               | <loop> <newline>

<declaration> ::= "DIM" <variable or array> {"," <variable or array>}+   "AS" {<type modifier>} <type>

<type> ::= "INTEGER"
          | "REAL"
          | "DATA"
          | "CHAR"
          | "STRING"
          | <user defined type or class>

<type modifier> ::= <reference modifer>
                   | <char modifier>
                   | <size modifier>
                   | <raw data modifier>

<reference modifier> ::= "REF"

<char modfier> ::= "UNICODE" | "ASCII"
<size modifier> ::= "SHORT" | "LONG" | "EXTENDED"
<raw data modifier> ::= "BYTE" | "WORD" | "DOUBLE" | "QUAD"

<variable or array> ::= <identifier> {"(" <numeric constant> ")"}

<assignment> ::= {["LET" | "SET"]} <variable>  "=" [<value> | <expression>]

<value> ::=   <variable> 
            | <literal constant>

<expression> ::=   <term> 
                | <term> <binary operator> <expression>
                | <unary operator> <expression>
                | "(" <expression> ")"

<term> ::=  <value> | <function call>

<unary operator> ::= <negation operator>
                    | <arithmetic sign>

<binary operator> ::= <arithmetic operator>
                      | <string concatenate operator>
                      | <comparison operator>

<arithmetic operator> ::= ["+" | "-" | "*" | "/" | "^"]

<boolean clause> ::=   <boolean constant>
                    | <value>
                    | <negation operator> <term>
                    | <term> <comparison operator>  <expression>

<boolean constant> ::= ["TRUE" | "FALSE"]
<negation operator> ::= "NOT"

Should [tt]LET[/tt] be an optional part of the assignment staement, a required part, or an indicator for a non-standard assignment (along the lines of [tt]SET[/tt])? What should the function and subroutine syntaces be, and should they use the same syntax or different ones?

The types and type modifiers are examples; what actual types will be supported will have to be worked out later. The [tt]REF[/tt] modifier is one of the possible solutions to the pointer issue, though much still needs to be decided about that. The [tt]DATA[/tt] type is for handling raw data, without interpreting it as a type; this is useful in some cases in low-level programming (one of the problems in C that to access a single byte you usually have to use a char, which can cause type confusion issues).

I added the boolean constants [tt]TRUE[/tt] and [tt]FALSE[/tt], even though they are not in most BASICs, on the premise that most newer languages in general do have some form of boolean type. This is a proposed addition and can be eliminated if need be.

Any additions or corrections to be made to this?
Schol-R-LEA

Re:Language Design: Basis

Post by Schol-R-LEA »

If I recall, the procedure syntax for QBasic was something like:

Code: Select all

<procedure> ::= <subroutine> | <function>

<subroutine> ::= "SUB" <sub name> {<parameter list>} <newline> <block> "END SUB" 

<function> ::= "FUNCTION" <function name> {<parameter list>} "AS" <type> <newline> <block> "END FUNCTION" 

<sub call> ::= <sub name> {<argument list>}

<function call> ::= <function name> "(" <argument list> ")"

<argument list> ::= <value> {"," <value>}+
This is just as rough version, drawn from memory mostly. As suggested before, the separate syntax for subroutine calls and function calls is redundant, and the parenthesized form could be used for both (as in VB.Nyet). Anyone have any reasons why the separate syntax should be retained? For that matter, does anyone have a suitable alternative syntax, from some other Basic perhaps?

Also, it has been suggested that Basis should be an OO language, or at least support OOP. Does anyone have an class or object/prototype syntax to propose?

Finally, I've been wondering if anyone has had any problems with or questions about the BNF dialect I'm using here. It occurs to me that I haven't been 100% consistent with it, and I want to avoid confusion. Would anyone prefer I use a different variant, e.g., ABNF?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Language Design: Basis

Post by Candy »

You've made some errors in your bnf (was in the mood for reading bnf):

Code: Select all

<procedure> ::= <subroutine> | <function>

<subroutine> ::= "SUB" <sub name> {<parameter list>} <newline> <block> "END SUB" 

<function> ::= "FUNCTION" <function name> {<parameter list>} "AS" <type> <newline> <block> "END FUNCTION"  <||> again, only one list

<sub call> ::= <sub name> {<argument list>} <||> only one list of arguments.

<function call> ::= <function name> "(" <argument list> ")"

<argument list> ::= <value> {"," <value>}+
This is just as rough version, drawn from memory mostly. As suggested before, the separate syntax for subroutine calls and function calls is redundant, and the parenthesized form could be used for both (as in VB.Nyet). Anyone have any reasons why the separate syntax should be retained? For that matter, does anyone have a suitable alternative syntax, from some other Basic perhaps?

Also, it has been suggested that Basis should be an OO language, or at least support OOP. Does anyone have an class or object/prototype syntax to propose?
The parentheses syntax is OK with me, seems consistent.

Not basis, imo. System programming might be OO, but I don't think basis has a place as OO language.
Finally, I've been wondering if anyone has had any problems with or questions about the BNF dialect I'm using here. It occurs to me that I haven't been 100% consistent with it, and I want to avoid confusion. Would anyone prefer I use a different variant, e.g., ABNF?
It's readable and kind of conforms to the default expectations, isn't it EBNF of something? At least, you're kind of consistent in syntax.
Schol-R-LEA

Re:Language Design: Basis

Post by Schol-R-LEA »

OK, are there any other additions or changes to the syntax that ought to be made? So far, it's a pretty bare-bones language...
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Language Design: Basis

Post by Pype.Clicker »

hm. I've not delve in all the details of your discussion, but one thing that sounds primordial to me when implementing an OS is the ability to build complex structures like lists, trees and the like... have you something like this in your design ?
Post Reply