Author Topic: Error Parsing "If"  (Read 11941 times)

0 Members and 5 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Error Parsing "If"
« 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


.
« Last Edit: May 27, 2014, 11:23:08 PM by Mike Lobanovsky »

Peter

  • Guest
Re: Error Parsing "If"
« Reply #1 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

Charles Pegge

  • Guest
Re: Error Parsing "If"
« Reply #2 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.

Aurel

  • Guest
Re: Error Parsing "If"
« Reply #3 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

Mike Lobanovsky

  • Guest
Re: Error Parsing "If"
« Reply #4 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. :)

Charles Pegge

  • Guest
Re: Error Parsing "If"
« Reply #5 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}

« Last Edit: May 28, 2014, 07:50:09 AM by Charles Pegge »

Peter

  • Guest
Re: Error Parsing "If"
« Reply #6 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

Mike Lobanovsky

  • Guest
Re: Error Parsing "If"
« Reply #7 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!
if a>b : b=a
if a>b : {b=a}


8)

Aurel

  • Guest
Re: Error Parsing "If"
« Reply #8 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

Mike Lobanovsky

  • Guest
Re: Error Parsing "If"
« Reply #9 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.

Ed Davis

  • Guest
Re: Error Parsing "If"
« Reply #10 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!

Charles Pegge

  • Guest
Re: Error Parsing "If"
« Reply #11 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

*/

Mike Lobanovsky

  • Guest
Re: Error Parsing "If"
« Reply #12 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!

.
« Last Edit: May 28, 2014, 01:21:59 PM by Mike Lobanovsky »

Mike Lobanovsky

  • Guest
Re: Error Parsing "If"
« Reply #13 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. :(


Aurel

  • Guest
Re: Error Parsing "If"
« Reply #14 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   :-\