Stage 66

Follow the development of the SharpBASIC compiler and share your thoughts and ideas.
Locked
User avatar
frank
Site Admin
Posts: 40
Joined: Sun Nov 21, 2021 12:04 pm
Location: Netherlands
Contact:

Stage 66

Post by frank »

There were some issues with initializing module/global string variables and local variables. This is because these two types of variables are stored differently. This has now been resolved and the following two code snippets give the correct output.

module level string variables declared and initialized

Code: Select all

' SharpBASIC string-05
' --------------------
incl "lib/sys.sbi";

dim Title: str = "This is SharpBASIC.";
dim title: str * 26 = "a new programming language";

main do
  print(Title);
  print(title);
  print();
end;
local string variables declared and initialized

Code: Select all

incl "lib/sys.sbi";

decl sub Hello();

main do
  Hello();
end;

sub Hello()
  dim var: str = "This is SharpBASIC.";
  dim fix: str * 26 = "a new programming language";
do
  print(var);
  print(fix);
  print();
end;
The strings are correctly allocated upon subroutine entry and automatically deallocated upon exit.

Note that the string datatype is called str rather than string. This is for the same reason that we use int rather than integer which makes the language more consistent and less verbose.

Also note that the print-statement no longer requires an argument. print();simply prints a linefeed and performs better than print(sbLF);
Last edited by frank on Thu Dec 30, 2021 3:45 pm, edited 1 time in total.
Keep it simple!
aurel
Posts: 11
Joined: Tue Nov 23, 2021 12:18 pm

Re: Stage 66

Post by aurel »

hello
and right in the EndofLine...
why must be EOL as semi-colon " ; " ??
looks like C

also why old stayle string size with string * 26 or i see
something in a wrong way ??

all best :)
User avatar
frank
Site Admin
Posts: 40
Joined: Sun Nov 21, 2021 12:04 pm
Location: Netherlands
Contact:

Re: Stage 66

Post by frank »

The semicolon as a statement terminator serves two purposes. First: it makes it very clear where the statement ends, both for the programmer and the compiler. Second: it eliminates the use of a statement continuation character like the underscore in traditional BASIC which can make things really messy. It is more convenient for the programmer to divide lengthy statements over multiple lines without having to mark each line for continuation. All it requires is a semicolon at the end.

Personally I've become so accustomed to the semicolon that I tend to use it in other languages that do not support it. ;)

The string size for a fixed-length string should be different from any array index declaration. dim s:str*10 is short and clear. But perhaps you have a good suggestion? I would really like to hear it! Any suggestion is most welcome.
Keep it simple!
aurel
Posts: 11
Joined: Tue Nov 23, 2021 12:18 pm

Re: Stage 66

Post by aurel »

well on windoze i use EOL token which is CRLF
then my interpreter recognize it as EndOfLine
first it is not easier for user always type ";" on end of line
when i use some C compilers to play with them i forget that one .
so my opinion is NOT easier ,but your product your way...right ? ; :)

for a string size
in array is normal arr[100] ..100 elements
standard string size is 256, when i use it in Oxygen Basic i don't have limitations
but Oxygen basic is a beast for himself , if you wish have string buffer or so called wide string this could be char[]
array of chars which then can hold size ,but i don+t know nothing about internal structure of your Sharp basic
so i cannot tell you what is what , also you are on linux so again i don't know .
User avatar
frank
Site Admin
Posts: 40
Joined: Sun Nov 21, 2021 12:04 pm
Location: Netherlands
Contact:

Re: Stage 66

Post by frank »

aurel wrote: Tue Nov 23, 2021 3:57 pm well on windoze i use EOL token which is CRLF
then my interpreter recognize it as EndOfLine
first it is not easier for user always type ";" on end of line
when i use some C compilers to play with them i forget that one .
so my opinion is NOT easier ,but your product your way...right ? ; :)

for a string size
in array is normal arr[100] ..100 elements
standard string size is 256, when i use it in Oxygen Basic i don't have limitations
but Oxygen basic is a beast for himself , if you wish have string buffer or so called wide string this could be char[]
array of chars which then can hold size ,but i don+t know nothing about internal structure of your Sharp basic
so i cannot tell you what is what , also you are on linux so again i don't know .
Over 30 years ago I started programming with QuickBASIC and I used it A LOT. Later on I used VB. So I'm very familiar with programming languages that don't use the semicolon as statement terminator. But once you get used to it, at one point it becomes second nature.

The idea behind the notation str * n is that str is a basic string of bytes. So the multiplication token makes sense.
Last edited by frank on Sun Jul 23, 2023 9:34 am, edited 1 time in total.
Keep it simple!
Locked