Oxygen Basic

Programming => Bugs & Feature Requests => Topic started by: Mike Lobanovsky on May 27, 2014, 11:15:15 PM

Title: Error Parsing "If"
Post by: Mike Lobanovsky on May 27, 2014, 11:15:15 PM
Hi Charles,

The following is a 100% bug:

dim as string cur_line = "<eof>"

if cur_line = "<eof>" then: print "got eof"
    cur_line = ""
end if

.
Title: Re: Error Parsing "If"
Post by: Peter on May 28, 2014, 02:13:02 AM
No Error.
Code: [Select]
dim as string cur_line = "<eof>"

if cur_line = "<eof>" then
    print "got eof"
    cur_line = ""
end if
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 03:15:20 AM

Mike,

If there is any code after "then" on the same line, it will assume it is a single liner, including any colons.

Internally, single liner ifs are automatically appended with endif.
Title: Re: Error Parsing "If"
Post by: Aurel on May 28, 2014, 03:48:35 AM
Or without stupid then

Code: [Select]
dim as string cur_line = "<eof>"

if cur_line = "<eof>"
    print "got eof"
    cur_line = ""
end if
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 04:45:18 AM
Gentlemen,

There is nothing on the same line with if/then because ":" is a line break. I could agree with you if ":" weren't supported at all but since it is, this is a bug.

I know pretty well that if/then and print will work if separated by a hard line break but ":" is also a line break, albeit soft, in BASIC terms except when used in conjunction with a label.

In my opinion, this is a 100% bug pardonnable for the time being only if Charles promises us to fix it up at the earliest time possible. :)
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 06:03:50 AM
Mike, I will contemplate your argument :)

if then has always been a bit odd in various basics, in that colons in such expressions, are not equivalent to line breaks.

Oxygen currently supports the following single liner syntax. (an else clause can also be appeneded appended):

if a>b then b=a

if a>b : b=a

if a>b {b=a}

if a>b then {b=a}

if a>b : {b=a}

Title: Re: Error Parsing "If"
Post by: Peter on May 28, 2014, 07:36:27 AM
Quote
Oxygen currently supports the following single liner syntax. (an else clause can also be appeneded):

Appended: better for learner like me.
No wonder that my English is so bad.  ;D
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 11:06:05 AM
My view on one-liners:

1. BASIC (colon-delimited something/anything/whatever may contain colons of their own)
if a>b then something [else whatever]
if a>b then : something [: elseif a<b then : anything] [: else : whatever] : end if

2. Quazi-BASIC (curly braces denote a scope that can contain colons)
if a>b then {something} [else {whatever}]
if a>b then : {something} [: elseif a<b then : {anything}] [: else : {whatever}] : end if
if a>b {something} [else {whatever}]
if a>b : {something} [: elseif a<b : {anything}] [: else : {whatever}] : end if

3. Not a BASIC! (http://www.fbsl.net/phpbb2/images/smilies/icon_m_tomato.gif)
if a>b : b=a
if a>b : {b=a}

8)
Title: Re: Error Parsing "If"
Post by: Aurel on May 28, 2014, 11:14:27 AM
well
i don't have to much problems with oxygen if/{else}/end if
because i tend to avoid then in
if / end if   block
of course ....i use then in one line
if a>b then a=a+1
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 11:40:41 AM
Aurel,

I'm perfectly aware that Oxygen is a quazi BASIC and I'm not insisting on it being pure but I'd like to see it being able to cope with pure BASIC syntax too, at least fundamentally. It's not a question of what you are or are not having problems with. For all we care you can get accustomed to using scopes (curly braces) in each and every multiline block of code if you like. But more BASIC-oriented users should have their chance as well. Isn't it called OxygenBasic after all?

I have nothing personal against building a superset upon BASIC, e.g. as we did in FBSL (I should say, very moderately, hehe...), but let's not break up BASIC's fundamental constructs in the process.

The cases printed in red are weird and they break up usual BASIC syntax. I say I ported and debugged the Toy interpreter in FBSL within an hour even using pure BASIC syntax. And I did it while in fact I could've written it all in a twice shorter and more efficient notation omitting almost all its global and local variables altogether in the process. But I'm beating about the bush with Oxygen for maybe five days in a row already.
Title: Re: Error Parsing "If"
Post by: Ed Davis on May 28, 2014, 12:22:56 PM
I say I ported and debugged the Toy interpreter in FBSL within an hour even using pure BASIC syntax. And I did it while in fact I could've written it all in a twice shorter and more efficient notation omitting almost all its global and local variables altogether in the process.

It would be great if you could create the "twice shorter and more efficient notation omitting almost all its global and local variables altogether in the process" version.  I always welcome shorter/faster/etc. ways of doing things..

Thanks!
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 01:03:33 PM
1  if a=1 : b=1  'endif implied

2  if a=1 : b=1 : end if   'endif explicit

I'm thinking seriously about option 2, Mike. It's a finely balanced decision.


This is Oxygen's current preferred scheme for single liners.

Code: [Select]
/*

SINGLE LINERS
=============

LOOPS AND LOOPING CONDITIONALS

do : exit do : end do         'explicit end
while a<=10  : a-=1 : wend    'explicit end
for a = 1 to 10 : b+=a : next 'explicit end


NON LOOPING CONDITIONALS

if a=1 : b=1  'endif implied
case a : b=1  'endcase implied


FUNCTIONS

function f(a) as sys = a*a 'end function implied
sys f(a)=a*a               'end function implied


TYPES

type vector float x,y,z    'end type implied

DIMS

dim vector a,b,c           'end dim implied

ENUMS

enum Colors red,green,blue 'end enum implied

*/
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 01:12:29 PM
I always welcome shorter/faster/etc. ways of doing things..

I will do it with pleasure as soon as we are through with O2 port of Toy interpreter here.

In the meantime, please have a look at the FBSL script that's a full-fledged BMP-to-RES file compiler. It doesn't use a single variable declaration or assignment statement that'd add runtime overhead. The second snapshot is a test .BMP precompiled into a .RES file using this pico-compiler and linked into an executable, as seen on loading the said resource .BMP with a call to LoadResource() WinAPI.

Thanks for your interest in FBSL!

.
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 01:49:08 PM
Charles,

This table looks very elegant and consistent indeed. It is however not compliant with BASIC tradition whenever even a single soft line break (:) appears within the code line. Moreover, it breaks up traditional BASIC block constructs if the soft line break appears on the first code line because you're refusing to accept : as a legit line break.

You're sacrificing tradition mercilessly to the harmony of your table and you're scaring me off as a BASIC user. :(

Title: Re: Error Parsing "If"
Post by: Aurel on May 28, 2014, 01:56:45 PM
Quote
-But more BASIC-oriented users should have their chance as well.
: Mike
 But i am one of them....

Quote
But I'm beating about the bush with Oxygen for maybe five days in a row already.
Heh ...I am beating all the time and because of that i often forget what is what
but this is standard tactic anyway...

Well Mike
I know that you can make better version but this one by Ed is somehow
good as example ...
I don't know is there a way to replace UDT variables with ordinary typed...maybe   :-\
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 02:08:41 PM
Option 2 would be consistent with a colon always being interpreted as a soft line break.

2  if a=1 : b=1 : end if   'endif explicit

That leaves case as the slightly odd one out.

case a : b=1
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 02:14:20 PM
No oddity seen here, Charles. The case that follows marks unambiguously the end of case immediately preceding it while end select will mark the end of entire block.
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 02:40:20 PM
I don't know is there a way to replace UDT variables with ordinary typed...maybe   :-\

Absolutely no problem here, Aurel. Just split each UDT into two simple variables and create two arrays for them. The array sizes will be the same and the indices within them will point to the same elements that they pointed to when each two-member UDT was still a single entity. This would be the easiest problem throughout the entire port. :)

Quote
but this is standard tactic anyway...

But it shouldn't be, at least as far as standard language constructs are concerned. This is why I'm so agitated: Charles is shaking the foundations and I'm already seeing the first bricks fall off the roof and bump on my head. :)
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 02:56:36 PM
I think option 2 tips the balance in your favour, Mike: :)

We can now do expressions like this (if we really want to):

sys a=2, b=0

if a=1 : b=1 : elseif a=2 : b=2 else b=3 : end if

or

if a=1 then : b=1 : elseif a=2 then : b=2 : else : b=3 : end if

print b
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 03:02:04 PM
Are you sure there are no typos here?
sys a=2, b=0
if a=1 : b=1 : elseif a=2 : b=2 else b=3 : end if
print b

And I suppose there may be anything instead of a sys here? (Just asking to be on the safe side, hehe...)

A voice in the wilderness again... yet maybe this is somehow better than nothing at all. :)
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 03:08:46 PM
Yes, Any primitive type: int, float or string.

I'm testing as we 'speak'. It works any which way. keywords then / else / elseif : are all expression terminators.
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 03:13:54 PM
It works any which way. keywords then / else / elseif : are all expression terminators.

Does that mean :'s after then and before else and elseif (and I suppose, before end too) are optional???
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 03:21:29 PM
The colon after then is essential to distinguish it from lines like

if a>1 then b=1


Similarly, a colon must come after an elseif condition.

end if / endif must be preceded by a colon under current parsing rules.

then is optional in these cases
Title: Re: Error Parsing "If"
Post by: JRS on May 28, 2014, 03:24:56 PM
This is why I'm glad Peter Verhas made the wise decision to only allow one statement per line.

This is a legal variable name in SB.

Hi = Hello:World

Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 03:25:58 PM
Charles,

Is your

b=2 else b=3

correct?


Hi John,

Quote
one statement per line

No "soft" line breaks (like : here) at all?
Title: Re: Error Parsing "If"
Post by: JRS on May 28, 2014, 03:33:39 PM
Code: [Select]
PRINT test( _
arg1, _
arg2, _
"""
               Multi
               Line
               String
""")

This is one statement.
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 03:38:37 PM
This is one statement.

Got it. The only legit line break is a *nix LF (0xA).

BTW FBSL's multiline string would be

"
Multi
Line
String
"


to be printed as

Multi
Line
String


Yours would be printed to the console as

"
Multi
Line
String
"




Charles,

What about my last question, please?
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 03:43:43 PM
Yes Mike, the else syntax works the same as before. I am almost ready to post an update. Just working through the permutations.

if a=1 then b=1 else b=5
Title: Re: Error Parsing "If"
Post by: JRS on May 28, 2014, 03:47:52 PM
a = _
"""
"Multi",
"Line',
'String'
"""
 :)
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 03:48:42 PM
Charles,

Please "yes" or "no":

if a=1 : b=1 : elseif a=2 : b=2 else b=3 : end if

does not require a colon before else, does it?
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 03:49:51 PM
John,

What will your print a look like?
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 03:51:37 PM
Yes, yes! else terminates an expression in all cases.

Oxygen also supports multiline strings btw.
Can be confusing when one quote mark is missing :)
Title: Re: Error Parsing "If"
Post by: JRS on May 28, 2014, 03:53:50 PM

Code: [Select]
a = _
"""
"Multi",
"Line',
'String'
"""

PRINT a,"\n"


jrs@laptop:~/sb/sb22/test$ scriba mls.sb

"Multi",
"Line',
'String'

jrs@laptop:~/sb/sb22/test$
Title: Re: Error Parsing "If"
Post by: JRS on May 28, 2014, 03:57:02 PM
Quote
Can be confusing when one quote mark is missing :)

Major contributor to hair loss.
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 04:01:53 PM
Oh,

Charles, my English must be failing me tonight. :)

Yes, yes!

Does it mean

"Yes, it does. It does need a colon within this context!"

or

"No, it doesn't. It does not need a colon within this context!"

The reason why I'm asking is because the Russian sentences like "No, it does" and "Yes, it doesn't" are perfectly legal and only correct from the Russian grammar perspective.

Sorry for being especially dumb tonight.


P.S.
Quote
Can be confusing when one quote mark is missing :)

Should have proper syntax highlighting in your editor to avoid confusion. :P
Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 04:02:58 PM
Major contributor to hair loss.

Anything to lose yet? ;)

Quote
"Multi",
"Line',
'String'

Understood. """ is simply a marker of a multiline string.
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 04:14:13 PM
Mike,

Yes, else it does not need a colon, and No, a colon is unnecessary :)

However in the older single liner syntax colons must not be used


if a=1 then b=1 : : : : else : : : : b=5
if a=1 then b=1  else b=5

New:
if a=1 then : b=1  else b=5 : end if
if a=1 then : b=1 :  else : b=5 : end if
if a=1 : b=1 :  else : b=5 : end if




Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 28, 2014, 04:24:07 PM
Yes, else does not need a colon

1. I thought Pegge looked more an Italian, not Russian, last name to me. :D

1. OMFG! From bad to worse... Charles, you owe me two bottles of beer this evening. First, for all the hopes I lost in this discussion. And second, for the new brand name I invented for Oxygen: Crypt-o-BASIC!

I should sleep it off on a pill. See you tomorrow, gentlemen!

:D
Title: Re: Error Parsing "If"
Post by: Charles Pegge on May 28, 2014, 04:34:54 PM
Goodnight both,

Unfortunately, I have no beer in stock, though I have port and some brandy. But what you really need is some of my cocoa and ginger porridge. :)


Update:
http://www.oxygenbasic.org/o2zips/Oxygen.zip

PS:
To check which version of Oxygen you have:
print version
"A40 08:44 29/05/2014"
Further update.

This single liner format is now supported (no colons required)
if a=1 then b=2 else b=99 end if
as well as:
if a=1 then b=2 else b=99

Mike's original quest is also satisfied:
if a=1 then : b=1
c=2
end if


Also set a better trap for unclosed quotes

Title: Re: Error Parsing "If"
Post by: Mike Lobanovsky on May 29, 2014, 02:16:18 AM
To check which version of Oxygen you have:...
This single liner format is now supported (no colons required)...
as well as:...
Mike's original quest is also satisfied:...
Also set a better trap for unclosed quotes

Hi Charles,

This looks much much better than a plate of ginger porridge or even two bottles of beer.

Thanks a lot! :D