Boriels ZX Compiler
I'm trying to compile a very simple program and I keep getting the error: unexpected end of file.
Here's my code:
Any ideas?
Here's my code:
10 cls 20: let n=0 22 do 25 PAUSE 1 30 PRINT AT 20,n;" x" 35 if inkey$=" " then goto 90 36 let n=n+1 40 while n<30 50 let n=30 52 do 55 PAUSE 1 60 PRINT AT 20,n;"x " 65 if inkey$=" " then goto 90 66 let n=n-1 70 while n>0 80 GO TO 20 90 stop
Any ideas?
Post edited by Rebelstar without a cause on
Comments
You forgot you need an END IF to complete your IF statement, though. This is the one big change from sinclair basic.
10 cls
20: let n=0
22 do
25 PAUSE 1
30 PRINT AT 20,n;" x"
35 if inkey$=" " then goto 90
END IF
36 let n=n+1
40 while n<30
50 let n=30
52 do
55 PAUSE 1
60 PRINT AT 20,n;"x "
65 if inkey$=" " then goto 90
END IF
66 let n=n-1
70 while n>0
80 GO TO 20
Fixes that. You don't have an end to the while lines, either, though. What are you trying to loop with the while statements? (A bit like "FOR" without a "NEXT") - WHILE needs an "END WHILE" (or a "WEND").
Also similarly, you have "DO" without an end point. This is also a loop statement. "DO" needs a "LOOP" statement to mark the end point.
This is why it's hitting the end of your code and thinking it's premature - you haven't wound up the openings you started.
1. Your 'if' statements need an 'end if' to terminate them.
2. It's 'do... loop until', not 'do... while' for ZXBasic.
The following version compiles with those changes made. Whether it does what you expected it to is another thing altogether - I suspect your loop until conditions aren't quite right to get the effect it looks like you were intending. :)
I originally had a for next loop but that wouldn't compile either, I'm not sure if it was because I was jumping out of The loop.
Your code without line numbers and some indentation becomes way more readable. Once you start using nested structures you'll realize the convenience of doing it this way. Besides, you'll also realize that most of the time, labels and GOTOs are not needed at all (mut may come handy sometimes). I seem to recall that there isn't a single GOTO in our latest Maritrini Prequel game.
cls Do n = 0 Do Pause 1 Print At 20, n; " x" If Inkey$ = " " Then Goto finishThis: End If n = n + 1 Loop Until n < 30 n = 30 Do Pause 1 Print At 20, n; "x " If Inkey$ = " " Then Goto finishThis: End If n = n - 1 Loop Until n > 0 Loop finishThis: StopYou don't really have to read into the code to know where loops start and end, for example.
And hopefully at some point... BASIC in all its forms. :)
Sorry, that's not true, BASIC is an awful language. :/ Not that I want to start a flame war.
Why do you have a ":" after gosub keypress ? and endif should be written as end if !!!
Btw: Then is not needed anymore:
if inkey$="q" and y>1:let y=y-1:end if
Then say "I don't like BASIC" rather than "BASIC is an awful language".
BASIC itself has the same capabilities such as, for example, Pascal. Albeit with a different syntax. That's all.
Name just one thing that makes BASIC awful as a language, just 'cause I'm curious why you think that. But it has to be something that's not tied to a concrete implementation. "BASIC is slow", for example, is not a valid reason.
Did you read http://goo.gl/4jPd5 ?
Pfft. Line numbers concentrate the mind and produce much more compact code. When the restriction on line numbers is lifted, there's nothing to remind you of how much code you've written and you end up using a lot more.
D.
PASCAL is an awful language too! Thankfully it's been dead for years.
I agree, saying it is slow is not a valid reason on its own, although for many applications it is a perfectly valid one.
Here are a few:
Alas all of the rest of my criticisms are implementation specific. And I'm not going to pick on the Speccy, or other computers of its age. The BBC Micro had the best BASIC of that era.
I'm not saying that BASIC doesn't have some value, it does let people who are for whatever reason unable to learn a better language, program. Quite whether that is always a good thing (see VisualBasic shareware of the 90s) is another matter.
But I doubt you'll find anyone who moved up to C/C++/Java/Javascript (and I'm not talking about hacking, actually writing something substantial) would disagree that BASIC isn't an awful language.
I'll leave you with a quote from Edsger Wybe Dijkstra, award winning Dutch computer scientist...
It's a bit over the top as quotes go, but I think his general point is very little you learn from BASIC you'll take with you to other, better languages. I certainly wouldn't suggest anyone new to coding started with it.
It's possible to write beautiful code in any language, and it's possible to write crap code in any language, and anyone who maintains "language X is sh*t", or "language A is better than language B" just comes across as lacking in experience and being a little bit tragic to me.
Are you suggesting that javascript is a good language? :-o
Well said, php is sh*t, though :)
And I insist that ruby is better than malbolge.
Patrik
Pascal's syntax is pretty much identical to C, And Delphi is comparable to C++ for object-orientation. The only real difference is that Pascal doesn't require header files which I would be very surprised to hear an argument for.
Pascal is not dead; far from it. Embarcadero's Delphi RAD Studio is phenomenally popular amongst windows developers and since the meteric rise of the ARM CPU, FPC has seen a massive surge in popularity. You being a closed-minded individual wouldn't see that - you have your own preconceived notions of what makes a language and cannot see around your self-imposed blinkers.
Christ, you really are a nasty piece of work, aren't you? BASIC can be as readable as C, in fact it it is often more readable; C written well tends to be a nightmare to read. BASIC was designed from the ground up to be accessible to beginners and so is readable by default.
Your argument against "all shareware VB apps of the 90s" holds no water at all. Everyone has to start somewhere, and had the majority of coders in the 80s had access to the internet back then, you'd have found a huge amount of crap available then too, regardless of the language they used. Not everyone has talent (only a few really do) but that's no reason to take your bigoted attitude and look down your obviously enormous nose that them.
For shame, young man.
I love how you include Javascript in there; it's this decade's VB. FWIW, I moved up from BASIC to assembly, C, C++, Pascal and others - I've gone back to BASIC. Are you really saying that I can't code because I like BASIC better?
Way to take that out of context, muppet. Meanwhile, those of us who actually understand how beginners learn and how they mature as coders will continue to encourage the adoption of the BASIC dialects available. You can carry on with your blinkered view of humanity and take your elitist attitude elsewhere sir.
This.
D.
That is a rather simplistic view, I think, a computer language is way more than just a set of rules.
If you care at all about what the computer does, then you should care about the language you tell it in.
I'm not saying that BASIC is uniquely awful, I never quite understood why FORTH was going to take over the world either, despite magazines in the 80s going on about it. And PHP is a Dr Frankenstein of bad languages.
I'm also not saying other languages are perfect, and do not have their flaws, though I would say C++ is probably the closest we've come so far.
Then I must be really tragic, and the last twenty years I spent coding for a living wasted. :)
I'd love to see "beautiful code" written in BASIC, please show!
Apologies to them, no offence meant! I've used his apps. (It still sucks tho :))
No, it's just not a bad language. But it at least shares a lot of syntax with C, always a good thing. I'd recommend it for people starting out.
And actually, if you've ever used it with Node.js you'll find it's extremely well suited to event driven programming. It's not perfect, it lacks proper classes and inheritance, and strong typing, but it's very well suited to the task.
I try to code beautifully. Well indented, structured, and built code is beautiful no matter the language.
I can't understand why you see the difference between this:
int foo (unsigned char a) { int i = 0; while (a--) { i ++; } return i; }and this
Function foo (a As uByte) as Integer Dim i as Integer While a i = i + 1 a = a - 1 Wend Return i End FunctionThe code is equally well structured and readable. If you don't like the syntax, that's just a matter of preference. The code above is quite standard BASIC, which would work unmodified or with slight modifications in most Microsoft BASICs, freeBASIC, QB64, PowerBASIC or our very own Boriel's ZX Basic ;)
I code in Java, Javascript, php, Perl, Python and Ruby for a living, and I do C and BASIC to have fun. And my code is alsways beautiful :D
Well, that's true. I was pragmatically thinking about writing something which works before my life runs out... :)
Patrik
That's nonsense. If you only care what the computer does, it doesn't make any difference what language you write the code in.
If you care how the computer does it then shirley you should be coding everything in asm, or at least writing your own compiler.
I don't think much to your choice of function and variable names though :p
;)
When you use PHP for what it was intended it's fine.
That was just laziness XD
And for what it's not. I do all my console application coding for Linux in PHP. Ditched shell script or perl long time ago.