neilsf / xc-basic3

A BASIC cross compiler for MOS 6502-based machines
MIT License
42 stars 5 forks source link

avoid DECLARE SUB / FUNCTION #241

Closed nippur72 closed 9 months ago

nippur72 commented 11 months ago

Why there's need to DECLARE SUB or FUNCTION...? can just the compiler figure it out by himself by doing another extra pass?

JJFlash-IT commented 11 months ago

In its defense I'll say that it's not an XC=BASIC "exclusive", there are quite a few modern BASIC dialects (and also other programming languages, like C if I'm not mistaken?) where you are required to declare SUBs, FUNCTIONs and the like if you define them after using them for the first time.

I don't find it particurarly struggling to just define everything before they're first called. Also, as I said, it's pretty standard stuff.

neilsf commented 11 months ago

xcbasic3 is a multipass compiler so theoretically it could read function headers in an early pass. I'll see how difficult it is to implement but for now I don't think that forward declaration is a big pain, especially that QBasic (our quasi-reference language) also requires it.