Menu

Why does this "work"?

Anonymous
2016-12-28
2016-12-31
  • Anonymous

    Anonymous - 2016-12-28

    10 DIM A
    20 A=5 : A(3)=7
    30 PRINT A,A(3)

    The array A() is auto dimmed on line 20 , BUT it should have generated a Dup Def error.
    I realize that this is also the behaviour of the ORIGINAL GW-BASIC, but I'm wondering WHY it works

    since THIS does not

    10 DIM A
    11 DIM A(10)
    20 A=5 : A(3)=7
    30 PRINT A,A(3)

    The first example creates TWO "A" variables, yet the second example properly restricts you from creating it yourself.

    And since no DEF xxx statement was executed, BOTH are by default A! and A!()

     
  • Rob Hagemans

    Rob Hagemans - 2016-12-28

    Hi, I think the confusion here is an expectation that A and A() would be somehow related. They are not - in GW-BASIC (as well as in PC-BASIC) these are two entirely distinct variables, the first a scalar and the second an array. Moreover, and unlike in, say, Visual BASIC, DIM A without an index doesn't actually mean anything in GW-BASIC; it's ignored. GW-BASIC programs therefore usually do not contain it.

    So the first code snippet works correctly; it is not the case that it "should" generate an error. In both code snippets there are two distinct variables, the scalar A! and the array A!().

    The problem is in fact with the second snippet: line 10 should be ignored by PC-BASIC, but (in version 15.08.11) isn't, and instead triggers an auto-allocation of A(10). The second DIM statement then causes a Duplicate Definition. The problem has actually been solved in the development version (16.12.0rc0), where the second piece of code runs correctly, and identically to the first.

    Rob

     
  • Anonymous

    Anonymous - 2016-12-28

    Interesting, and thanks for the explanation :)
    So in reality, you can have TWO references to any variable[datatype] , a scalar, AND an array
    My emulator is going with the restrictions imposed by more modern languages :) "A[datatype]" refers to ONE entry in the symbol table. But then I think my overall goal is different than your. While I think yours is to create as true an implementation of GW-BASIC as possible, mine is multi-tiered....

    1) create a feature rich BASIC interpeter for iOS using GW-BASIC as a template
    2) next phase. enhance it to support BOOLEAN and CURRENCY datatypes, and features that an iOS device might have that a "terminal" did not
    3) after that : create a version that does away with line numbers, includes true Functions and Subroutines (ie. Named)
    4) then add support for forms (buttons, labels, etc)
    5) create a transpiler that will convert this BASIC into SWIFT to be compiled as a native iOS application

    FYI.... is you emulator implementing a machine code image from GW-BASIC, or is it closer to what I am doing, in that I parse the input, and do all the syntax checking etc...

     
    • Marcos Cruz

      Marcos Cruz - 2016-12-30

      1) create a feature rich BASIC interpeter for iOS using GW-BASIC as a template
      2) next phase. enhance it to support BOOLEAN and CURRENCY datatypes, and features that an iOS device might have that a "terminal" did not
      3) after that : create a version that does away with line numbers, includes true Functions and Subroutines (ie. Named)
      4) then add support for forms (buttons, labels, etc)
      5) create a transpiler that will convert this BASIC into SWIFT to be compiled as a native iOS application

      Have you considered Markus Hoffmann's X11-Basic as a template? It's nearer to your goal than GW-BASIC.

       
      • Anonymous

        Anonymous - 2016-12-30

        Tried looking at X11-Basic, but his website is messed up,, took multiple attempts to load a page. Anyways I am familiar with GFA (used it for years with an Atari ST back in the day). And yes that is close to my ultimate goal,,,,, But I laid out a road map, and am using THIS version to iron out all the internals (equation parser, symbol table etc, all things that ANY interpeter/compiler would require)

         
  • Rob Hagemans

    Rob Hagemans - 2016-12-29

    Hi, interesting ideas!

    To answer your question, PC-BASIC is an independently built interpreter and does not contain any code or ROM images from GW-BASIC.