Re:Language Design: Basis
Posted: Sun Feb 22, 2004 3:09 pm
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.
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.
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 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.