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:
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
«134

Comments

  • edited October 2012
    You're probably better off posting on the forum at boriel.com about his compiler!
    I'm trying to compile a very simple program and I keep getting the error: unexpected end of file.

    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?

    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.
  • edited October 2012
    Two things preventing compilation:

    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. :)
    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 loop until 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 loop until n>0
    80 GO TO 20
    90 stop
    
  • Thanks guys! Think I'm going to need a bit of practice before I program my masterpiece (yeah right!). I haven't used Do/Loop since college so I'm a bit rusty.
    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.
  • edited October 2012
    I'd suggest you to drop line numbers. They make your code unreadable and difficult to re-organize.

    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:
    
    Stop
    

    You don't really have to read into the code to know where loops start and end, for example.
  • Thanks. Breaking away from using line numbers will be tough!
  • edited October 2012
    It was for me back in the day when I started coding for PCs in QuickBasic, but trust me... In a breeze you'll despise line numbers with a passion :D
  • edited October 2012
    na_th_an wrote: »
    It was for me back in the day when I started coding for PCs in QuickBasic, but trust me... In a breeze you'll despise line numbers with a passion :D

    And hopefully at some point... BASIC in all its forms. :)
  • edited October 2012
    That's not true. There's no bad BASIC. There's bad compilers or interpreters.
  • I've got another unexpected end of file error:
    setup:
    let y=0
    mainloop:
    gosub keypress:
    goto mainloop
    keypress:
    if inkey$="q" and y>1 then let y=y-1:endif
    return
    
  • edited October 2012
    na_th_an wrote: »
    That's not true. There's no bad BASIC. There's bad compilers or interpreters.

    Sorry, that's not true, BASIC is an awful language. :/ Not that I want to start a flame war.
  • LCDLCD
    edited October 2012
    I've got another unexpected end of file error:
    setup:
    let y=0
    mainloop:
    gosub keypress:
    goto mainloop
    keypress:
    if inkey$="q" and y>1 then let y=y-1:endif
    return
    

    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
  • Many thanks LCD. It was your latest effort that inspired me to get to grips with this compiler. I'm also rather intimidated by what you've achieved!
  • edited October 2012
    RobeeeJay wrote: »
    Sorry, that's not true, BASIC is an awful language. :/ Not that I want to start a flame war.

    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.
  • edited October 2012
    I think some older versions don't support "endif" and you need to have "end if"

    Did you read http://goo.gl/4jPd5 ?
  • edited October 2012
    na_th_an wrote: »
    It was for me back in the day when I started coding for PCs in QuickBasic, but trust me... In a breeze you'll despise line numbers with a passion :D

    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.
  • edited October 2012
    na_th_an wrote: »
    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.

    PASCAL is an awful language too! Thankfully it's been dead for years.

    na_th_an wrote: »
    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.

    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:
    • There is no standard, every implementation has it's own (often unique) version, so you cannot easily translate what you have learned from one version to another
    • The syntax is excessive and doesn't make for easily readable code
    • It doesn't encourage well structured programs
    • Every single VisualBasic shareware app of the 90s

    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 is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration"

    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.
  • edited October 2012
    A programming language is just a set of rules you have to follow in order to make a computer do what you want. They all have plus points. They all suck in their own unique ways. It's just a set of rules.

    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.
  • edited October 2012
    RobeeeJay wrote: »
    PASCAL is an awful language too! Thankfully it's been dead for years.
    I think there's at least one person on these forums who would disagree with that, since all his apps are written in pascal :p
    RobeeeJay wrote: »
    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)
    Are you suggesting that javascript is a good language? :-o
  • edited October 2012
    ccowley wrote: »
    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.

    Well said, php is sh*t, though :)

    And I insist that ruby is better than malbolge.

    Patrik
  • edited October 2012
    RobeeeJay wrote: »
    PASCAL is an awful language too! Thankfully it's been dead for years.

    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.
    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:
    • There is no standard, every implementation has it's own (often unique) version, so you cannot easily translate what you have learned from one version to another
    • The syntax is excessive and doesn't make for easily readable code
    • It doesn't encourage well structured programs
    • Every single VisualBasic shareware app of the 90s

    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.

    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.
    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 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?
    I'll leave you with a quote from Edsger Wybe Dijkstra, award winning Dutch computer scientist...

    [snip]

    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.

    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.
    ccowley wrote: »
    A programming language is just a set of rules you have to follow in order to make a computer do what you want. They all have plus points. They all suck in their own unique ways. It's just a set of rules.

    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.

    This.

    D.
  • edited October 2012
    ccowley wrote: »
    A programming language is just a set of rules you have to follow in order to make a computer do what you want. They all have plus points. They all suck in their own unique ways. It's just a set of rules.

    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.

    ccowley wrote: »
    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.

    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!

    guesser wrote: »
    I think there's at least one person on these forums who would disagree with that, since all his apps are written in pascal :p

    Apologies to them, no offence meant! I've used his apps. (It still sucks tho :))

    guesser wrote: »
    Are you suggesting that javascript is a good language? :-o

    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.
  • edited October 2012
    Patrik Rak wrote: »
    And I insist that ruby is better than malbolge.
    Depends what you're trying to achieve. If the aim is to show off, malbolge is better :D
  • edited October 2012
    RobeeeJay wrote: »
    Then I must be really tragic, and the last twenty years I spent coding for a living wasted. :)
    Yep, I suspected you were a beginner. Come back and try to impress us all again when you've got a few more miles under your belt, eh?
  • edited October 2012
    RobeeeJay wrote: »
    I'd love to see "beautiful code" written in BASIC, please show!

    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 Function
    

    The 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
  • edited October 2012
    ccowley wrote: »
    Depends what you're trying to achieve. If the aim is to show off, malbolge is better :D

    Well, that's true. I was pragmatically thinking about writing something which works before my life runs out... :)

    Patrik
  • edited October 2012
    RobeeeJay wrote: »
    a computer language is way more than just a set of rules.
    Erm... not it's not.
    I wanna tell you a story 'bout a woman I know...
  • edited October 2012
    RobeeeJay wrote: »
    If you care at all about what the computer does, then you should care about the language you tell it in.

    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.
  • edited October 2012
    na_th_an wrote: »
    I try to code beautifully. Well indented, structured, and built code is beautiful no matter the language.

    I don't think much to your choice of function and variable names though :p

    ;)
  • edited October 2012
    RobeeeJay wrote: »
    And PHP is a Dr Frankenstein of bad languages.

    When you use PHP for what it was intended it's fine.
  • edited October 2012
    guesser wrote: »
    I don't think much to your choice of function and variable names though :p

    ;)

    That was just laziness XD
    guesser wrote: »
    When you use PHP for what it was intended it's fine.

    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.
Sign In or Register to comment.